I've just updated my project's core-ktx (androidx.core:core-ktx) version to 1.7.0, and now I can't compile my project. In fact, at my PC everything works OK, but in Github Actions the build is broken.
At first I was getting this error:
* What went wrong:
Execution failed for task ':core:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.tasks.VerifyLibraryResourcesTask$Action
> Android resource linking failed
ERROR:/home/runner/.gradle/caches/transforms-3/cf34be3e77386540a828d329143911c7/transformed/core-1.7.0/res/values/values.xml:105:5-114:25: AAPT: error: resource android:attr/lStar not found.
But updating to SDK 31 fixed this issue. Now I'm getting the following one:
> Task :core:hiltAggregateDepsDebugUnitTest
WARNING: [Processor] Library '/home/runner/.gradle/caches/transforms-3/fd6df19df5b3c35086ae117610be6db2/transformed/browser-1.0.0-api.jar' contains references to both AndroidX and old support library. This seems like the library is partially migrated. Jetifier will try to rewrite the library anyway.
Example of androidX reference: 'androidx/browser/R$styleable'
Example of support library reference: 'android/support/customtabs/ICustomTabsCallback$Stub$Proxy'
WARNING: [Processor] Library '/home/runner/.gradle/caches/transforms-3/fc7ccfb37357e9edd2e98ab346848a40/transformed/core-1.7.0-api.jar' contains references to both AndroidX and old support library. This seems like the library is partially migrated. Jetifier will try to rewrite the library anyway.
Example of androidX reference: 'androidx/core/R$styleable'
Example of support library reference: 'android/support/v4/app/INotificationSideChannel$Default'
> Task :core:javaPreCompileReleaseUnitTest
> Task :core:compileReleaseUnitTestJavaWithJavac NO-SOURCE
> Task :core:createFullJarRelease
/home/runner/work/Android/Android/core/build/generated/hilt/component_sources/debugUnitTest/com/***/.../core/shared/Hilt_App.java:20: error: cannot find symbol
return DaggerApp_HiltComponents_SingletonC.builder()
> Task :core:hiltJavaCompileDebugUnitTest FAILED
^
symbol: variable DaggerApp_HiltComponents_SingletonC
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':core:hiltJavaCompileDebugUnitTest'.
> Compilation failed; see the compiler error output for details.
This is my build.gradle:
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-parcelize'
id 'org.jetbrains.dokka'
id 'org.jetbrains.kotlin.kapt'
id 'dagger.hilt.android.plugin'
}
android {
compileSdk 31
buildToolsVersion "31.0.0"
defaultConfig {
minSdk 24
targetSdk 31
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
}
tasks.named("dokkaHtmlPartial") {
dokkaSourceSets {
configureEach {
noAndroidSdkLink.set(false)
}
}
}
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.preference:preference-ktx:1.1.1'
// Testing
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:4.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// KotlinX Coroutines
api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
api 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.5.2'
// Android Jetpack
def jetpack_work_version = '2.7.0'
api "androidx.work:work-runtime-ktx:$jetpack_work_version"
api "androidx.work:work-gcm:$jetpack_work_version"
androidTestApi "androidx.work:work-testing:$jetpack_work_version"
api "androidx.startup:startup-runtime:1.1.0"
// Jetpack compose
api "androidx.compose.ui:ui:$compose_version"
api "androidx.compose.ui:ui-tooling:$compose_version"
api "androidx.compose.foundation:foundation:$compose_version"
api "androidx.compose.material:material:$compose_version"
api "androidx.compose.material:material-icons-core:$compose_version"
api "androidx.compose.material:material-icons-extended:$compose_version"
api "androidx.compose.runtime:runtime-livedata:$compose_version"
api "androidx.compose.runtime:runtime-rxjava2:$compose_version"
api 'androidx.activity:activity-compose:1.4.0'
api 'androidx.lifecycle:lifecycle-viewmodel-compose:2.4.0'
api 'androidx.navigation:navigation-compose:2.4.0-beta02'
api 'com.google.accompanist:accompanist-appcompat-theme:0.20.1'
androidTestApi "androidx.compose.ui:ui-test-junit4:$compose_version"
// Coil image loading
api 'io.coil-kt:coil:1.4.0'
api 'io.coil-kt:coil-compose:1.4.0'
// Live Data
api 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
// Google Play Core
api 'com.google.android.play:core:1.10.2'
api 'com.google.android.play:core-ktx:1.8.1'
// App Search
def appsearch_version = "1.0.0-alpha04"
api "androidx.appsearch:appsearch:$appsearch_version"
// Use kapt instead of annotationProcessor if writing Kotlin classes
kapt "androidx.appsearch:appsearch-compiler:$appsearch_version"
api "androidx.appsearch:appsearch-local-storage:$appsearch_version"
// Google Firebase
api platform('com.google.firebase:firebase-bom:29.0.0')
api 'com.google.firebase:firebase-analytics-ktx'
api 'com.google.firebase:firebase-firestore-ktx'
api 'com.google.firebase:firebase-storage-ktx'
api 'com.google.firebase:firebase-crashlytics-ktx'
api 'com.google.firebase:firebase-config-ktx'
api 'com.google.firebase:firebase-perf-ktx'
api 'com.google.firebase:firebase-dynamic-links-ktx'
api 'com.google.firebase:firebase-functions-ktx'
api 'com.google.firebase:firebase-auth-ktx'
api 'com.google.firebase:firebase-messaging-ktx'
api 'com.google.firebase:firebase-messaging-directboot:23.0.0'
// Google Firebase Auth Google Sign-In
api 'com.google.android.gms:play-services-auth:19.2.0'
// Hilt dependency injection
api "com.google.dagger:hilt-android:2.40"
kapt "com.google.dagger:hilt-compiler:2.40"
// Gson for JSON parsing
implementation 'com.google.code.gson:gson:2.8.9'
// Maps SDK
api 'com.google.android.gms:play-services-maps:18.0.0'
// Timber
api 'com.jakewharton.timber:timber:5.0.1'
// Custom Views
api 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
If any extra info is required please ask, my build workflow has been broken for a week :(
Thanks in advance
Implement a new version of androidx.core-ktx in your project .
implementation 'androidx.core:core-ktx:1.8.0-alpha03'
then force the project to use the new version of it.
configurations.all {
resolutionStrategy { force 'androidx.core:core-ktx:1.8.0-alpha03' }
}
just only remove line
implementation 'androidx.core:core-ktx:1.7.0'
that should fix the warning
Related
We are migrating to using the Microsoft Graph API from using older auth methods.
Previously in this project the dependency management has been very manual, this included downloading .jars and manually importing them into intelliJ for local development.
Since we need to pull in new dependencies for the Graph API SDK, I took it as a chance to pay off some tech-debt and start going toward more programmatic dependency management.
I was able to get the web-app to run properly, however bringing in the new dependencies
https://mvnrepository.com/artifact/com.microsoft.azure/msal4j
https://mvnrepository.com/artifact/com.microsoft.graph/microsoft-graph
https://mvnrepository.com/artifact/com.azure/azure-core
did not seem to work fully.
Our build.gradle looks like this
dependencies {
providedCompile 'com.microsoft.graph:microsoft-graph:5.40.0'
providedCompile 'com.azure:azure-identity:1.7.0'
// https://mvnrepository.com/artifact/com.azure/azure-core
implementation group: 'com.azure', name: 'azure-core', version: '1.34.0'
// https://mvnrepository.com/artifact/com.microsoft.azure/msal4j
implementation 'com.microsoft.azure:msal4j:1.13.3'
providedCompile fileTree(dir: "${webAppDirName}/WEB-INF/lib", excludes: [
'aspose.pdf.jar',
'aspose-pdf.jar',
'async-http-client-2.4.4.jar',
'commons-beanutils-core.jar',
'commons-collections.jar',
'commons-fileupload-1.1.jar',
'commons-fileupload-1.2.2.jar',
'commons-io-1.1.jar',
'commons-io-2.1.jar',
'commons-lang-2.3.jar',
'commons-logging.jar',
'commons-logging-1.0.jar',
'commons-logging-1.1.1.jar',
'commons-logging-1.1.3.jar',
'core-1.5.0.jar',
'empty.jar',
'firebase-admin-6.3.0.jar',
'groovy-all-1.7.5.jar',
'httpclient-4.1.2.jar',
'httpclient-4.5.jar',
'httpcore-4.1.2.jar',
'httpcore-4.4.1.jar',
'httpmime-4.1.2.jar',
'itext-2.0.4.jar',
'jackson-annotations-2.4.0.jar',
'jackson-annotations-2.8.0.jar',
'jackson-core-2.4.0.jar',
'jackson-databind-2.4.0-rc3.jar',
'jackson-jaxrs-1.9.2.jar',
'jackson-xc-1.9.2.jar',
'jasperreports-5.6.0.jar',
'jersey-json-1.17.1.jar',
'jsch-0.1.53.jar',
'json_simple-1.1.jar',
'mailapi.jar',
'netty-all-4.1.23.Final.jar',
'opentok-server-sdk-2.2.0.jar',
'opentok-server-sdk-4.2.0.jar',
'reactive-streams-1.0.2.jar',
'servlet.jar',
'soap.jar',
'twilio-7.1.0-jar-with-dependencies.jar',
'twilio-java-sdk-3.3.10-jar-with-dependencies.jar',
'webprovider-1.5.0.jar'
],include:'*.jar')
providedCompile 'org.apache.tomcat:tomcat-catalina:8.5.32'
}
The code in particular that I am running into an issue with is located here
public MicrosoftEmailClient() {
ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId(CLIENT_ID)
.clientSecret(CLIENT_SECRET)
.tenantId(TENANT_ID)
.build();
TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(SCOPE, clientSecretCredential);
graphClient =
GraphServiceClient
.builder()
.authenticationProvider(tokenCredentialAuthProvider)
.buildClient();
}
and the error itself is here
Exception in thread "Thread-8" java.lang.NoClassDefFoundError: com/azure/core/credential/TokenCredential
For context around this project we are deploying it through Tomcat 8.5+
I just released a new app on the Play Store. The app was working fine on my phone before submission but when I download the app from play store, it crashed on launch. I have tried deleting the app from the phone and re-installing and that continues to crash on launch.
When I have the phone connected to Android Studio, I see this logged when the crash occurs.
java.lang.RuntimeException: Unable to create application com.bundleid.EXAMPLE.MyApplication: java.lang.TypeNotPresentException: Type kotlin.Pair not present
Why would kotlin.Pair not be available on the play store version of the app?? I haven't submitted any apps to play store since around 2018 so I am a bit rusty but I kind of remember having a similar experience before and I think it had something to do with Proguard but I am not sure. How can I fix this and how can I test the app beforehand on how it's going to behave when it's downloaded from Playstore?
Full:
--------- beginning of crash
2021-08-09 00:09:03.067 13733-13733/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bundleid.EXAMPLE, PID: 13733
java.lang.RuntimeException: Unable to create application com.bundleid.EXAMPLE.MyApplication: java.lang.TypeNotPresentException: Type kotlin.Pair not present
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6759)
at android.app.ActivityThread.access$1400(ActivityThread.java:244)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1952)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7700)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)
Caused by: java.lang.TypeNotPresentException: Type kotlin.Pair not present
at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:69)
at libcore.reflect.ParameterizedTypeImpl.getOwnerType(ParameterizedTypeImpl.java:54)
at p4.a.a(Unknown Source:35)
at p4.a$a.<init>(Unknown Source:3)
at p4.a.a(Unknown Source:63)
at t4.a.<init>(:1)
at v4.t3.<init>(Unknown Source:0)
at com.bundleid.EXAMPLE.MyApplication.onCreate(:23)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6754)
at android.app.ActivityThread.access$1400(ActivityThread.java:244)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1952)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7700)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)
Caused by: java.lang.ClassNotFoundException: kotlin.Pair
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:67)
at libcore.reflect.ParameterizedTypeImpl.getOwnerType(ParameterizedTypeImpl.java:54)
at p4.a.a(Unknown Source:35)
at p4.a$a.<init>(Unknown Source:3)
at p4.a.a(Unknown Source:63)
at t4.a.<init>(:1)
at v4.t3.<init>(Unknown Source:0)
at com.bundleid.EXAMPLE.MyApplication.onCreate(:23)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6754)
at android.app.ActivityThread.access$1400(ActivityThread.java:244)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1952)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7700)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)
Caused by: java.lang.ClassNotFoundException: kotlin.Pair
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:67)
at libcore.reflect.ParameterizedTypeImpl.getOwnerType(ParameterizedTypeImpl.java:54)
at p4.a.a(Unknown Source:35)
at p4.a$a.<init>(Unknown Source:3)
at p4.a.a(Unknown Source:63)
at t4.a.<init>(:1)
at v4.t3.<init>(Unknown Source:0)
at com.bundleid.EXAMPLE.MyApplication.onCreate(:23)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6754)
at android.app.ActivityThread.access$1400(ActivityThread.java:244)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1952)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7700)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)
gradle.properties:
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
android.enableJetifier=true
kotlin.code.style=official
build.gradle (Project):
buildscript {
ext.kotlin_version = "1.5.20"
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.8'
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (Module):
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.bundleid.EXAMPLE"
minSdkVersion 21
targetSdkVersion 30
versionCode 5
versionName "5.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
ndk {
debugSymbolLevel 'FULL'
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'nl.dionsegijn:konfetti:1.3.2'
implementation 'com.android.billingclient:billing:4.0.0'
implementation 'org.apache.commons:commons-text:1.9'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'org.adblockplus:adblock-android-webview:4.4.0'
implementation 'org.jsoup:jsoup:1.13.1'
implementation("com.android.volley:volley:1.2.0")
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation 'com.github.blipinsk:ViewPropertyObjectAnimator:1.5.0'
implementation 'me.saket:better-link-movement-method:2.2.0'
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation 'androidx.asynclayoutinflater:asynclayoutinflater:1.0.0'
implementation 'com.google.firebase:firebase-messaging:22.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
}
My proguard-rules.pro file is empty.
EDIT:
I was able to at least reproduce the same issue using the release build of the app using:
brew install bundletool
cd /location/to/your/release/folder
bundletool build-apks --bundle=app-release.aab --output=./app.apks
ls
bundletool install-apks --apks=app.apks --adb=~/Library/Android/sdk/platform-tools/adb
Now I just need to figure out how to fix the crash.
EDIT 2:
If I set minifyEnabled to false in build.gradle, then it doesn't crash. So it definitely has to do with Proguard. How can I fix it?
EDIT 3:
I was able to resolve this by putting this in the proguard-rules.pro file:
-keep class androidx.** { *; }
-keep interface androidx.** { *; }
-keep class kotlin.** { *; }
-keep interface kotlin.** { *; }
-keep class com.bundleid.EXAMPLE.** { *; }
-keep interface com.bundleid.EXAMPLE.** { *; }
This works. But if someone thinks these rules might be incorrect or too broad, please let me know.
I just ran into this after increasing an existing app's targetSdkVersion from 29 to 30. Adding just this to proguard-rules.pro seems to fix it for me:
-keep class kotlin.Pair
I am using RetroFit to make a call to TheMovieDatabase API and am trying to get a list of the popular movies to populate into a RecylerView. However, when I make the call through RetroFit, I am getting an error related to OkHTTP. I am using OkHTTP in conjunction with RetroFit:
06-08 19:57:26.281 19232-19254/popularmovies.troychuinard.com.popularmovies E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: popularmovies.troychuinard.com.popularmovies, PID: 19232
java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/internal/Platform;
at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:112)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:160)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.internal.Platform" on path: DexPathList[[zip file "/data/app/popularmovies.troychuinard.com.popularmovies-2/base.apk", zip file "/data/app/popularmovies.troychuinard.com.popularmovies-2/split_lib_dependencies_apk.apk", zip file "/data/app/popularmovies.troychuinard.com.popularmovies-2/split_lib_slice_0_apk.apk", zip file "/data/app/popularmovies.troychuinard.com.popularmovies-2/split_lib_slice_1_apk.apk", zip file "/data/app/popularmovies.troychuinard.com.popularmovies-2/split_lib_slice_2_apk.apk", zip file "/data/app/popularmovies.troychuinard.com.popularmovies-2/split_lib_slice_3_apk.apk", zip file "/data/app/popularmovies.troychuinard.com.popularmovies-2/split_lib_slice_4_apk.apk", zip file "/data/app/popularmovies.troychuinard.com.popularmovies-2/split_lib_slice_5_apk.apk", zip file "/data/app/popularmovies.troychuinard.com.popularmovies-2/split_lib_slice_6_apk.apk", zip file "/data/app/popularmovies.troychuinard.com.popularmovies-2/split_lib_slice_7_apk.apk", zip file "/data/app/popularmovies.troychuinard.com.popularmovies-2/split_lib_slice_8_apk.apk", zip file "/data/app/popularmovies.troychuinard.com.popularmovies-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/popularmovies.troychuinard.com.popularmovies-2/lib/arm, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:112)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:160)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Below is my relevant code from RetroFit:
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(getApplicationContext(), String.valueOf(i), Toast.LENGTH_LONG).show();
String selection = String.valueOf(i);
switch (i){
case 0:
query = "popular";
mBaseURL = "https://api.themoviedb.org/3/movie/popular/";
break;
case 1:
query = "top_rated";
mBaseURL = "https://api.themoviedb.org/3/movie/top_rated/";
break;
default:
query = "popular";
mBaseURL = "https://api.themoviedb.org/3/movie/popular/";
break;
}
mMovieURLS.clear();
mMovieResultsAdapter.notifyDataSetChanged();
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(mBaseURL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
ApiInterface apiInterface = retrofit.create(ApiInterface.class);
Call<TheMovieDatabase> call = apiInterface.getImages();
call.enqueue(new Callback<TheMovieDatabase>() {
#Override
public void onResponse(Call<TheMovieDatabase> call, Response<TheMovieDatabase> response) {
String movieResponse = String.valueOf(response.isSuccessful());
Log.v("SUCESS", movieResponse);
}
#Override
public void onFailure(Call<TheMovieDatabase> call, Throwable t) {
}
});
}
API InterFace:
public interface ApiInterface{
#GET("?api_key=xxxxxxxxx&language=en-US")
Call<TheMovieDatabase> getImages();
}
Gradle Dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.3.0'
}
I know this question has been 2 years, but I solve mine. So here is an alternate answer you could try.
My error started after upgrading version of my dependencies(Android Studio suggested it after looking in project structure). Since the problem involve Retrofit and OkHttp, I revert back to the older version that I use, when my app was working. So, I suggest to revert back to older version of :
implementation 'com.squareup.retrofit2:retrofit:*older version here*'
implementation 'com.squareup.retrofit2:converter-gson:*older version here*'
implementation 'com.squareup.retrofit2:converter-moshi:*older version here*'
implementation 'oauth.signpost:oauth-signpost:*older version here*'
implementation 'se.akerfeldt:okhttp-signpost:*older version here*'
implementation 'com.squareup.okhttp3:okhttp:*older version here*'
implementation 'oauth.signpost:signpost-core:*older version here*'
That is the dependencies that I revert back to older version. I suggest you change any Retrofit or OkHttp related dependencies back to older version when your app was working.
If you have any problem figuring out what is the older version that is available, I suggest to look into dependencies version from Project Structure > Dependencies tab > app tab. from there you can find your dependencies that you are looking for, and change the version.
Good luck
I am developing a location aware application. I integrated Google Play Location Services and Google Maps into my application. My application runs without an issue in debug mode. When I generate a signed APK in release mode and run the application, it crashes on startup with following exception:
Process: com.example.akif, PID: 4233
java.lang.RuntimeException: Unable to resume activity {com.example.akif/com.example.akif.activities.MainActivity}: java.lang.SecurityException: Binder invocation to an incorrect interface
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3400)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3440)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2713)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.SecurityException: Binder invocation to an incorrect interface
at android.os.Parcel.nativeEnforceInterface(Native Method)
at android.os.Parcel.enforceInterface(Parcel.java:482)
at vz.onTransact(:com.google.android.gms.DynamiteModulesB:81)
at android.os.Binder.transact(Binder.java:499)
at com.google.android.gms.maps.a.bt.c(Unknown)
at com.google.android.gms.maps.i.b(Unknown)
at com.google.android.gms.b.d.b(Unknown)
at com.google.android.gms.b.j.a(Unknown)
at com.google.android.gms.maps.h.b(Unknown)
at com.google.android.gms.maps.h.a(Unknown)
at com.google.android.gms.b.a.c(Unknown)
at com.google.android.gms.b.a.e(Unknown)
at com.google.android.gms.maps.g.f(Unknown)
at android.support.v4.app.k.ay(Unknown)
at android.support.v4.app.x.l(Unknown)
at android.support.v4.app.ax.h(Unknown)
at android.support.v4.app.ax.i(Unknown)
at android.support.v4.app.ax.run(Unknown)
at android.support.v4.app.x.ae(Unknown)
at android.support.v4.app.i.aa(Unknown)
at android.support.v4.app.a.onPostResume(Unknown)
at android.support.v7.app.a.onPostResume(Unknown)
at android.app.Activity.performResume(Activity.java:6792)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3377)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3440)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2713)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
I noticed by following logs at each lifecycle method that this happens in my fragment's onResume method where I check for Google Play Services availability as following:
#Override public void onResume() {
Log.debug(getClass(), "onResume()");
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int googlePlayServicesAvailabilityResult = googleApiAvailability.isGooglePlayServicesAvailable(getContext());
if (googlePlayServicesAvailabilityResult != ConnectionResult.SUCCESS) {
if (!googleApiAvailability.isUserResolvableError(googlePlayServicesAvailabilityResult)) {
Toast.makeText(getContext(), "Your device doesn't support Google Play location services. This application cannot run without it!", Toast.LENGTH_LONG).show();
getActivity().finish();
return;
}
Dialog errorDialog = googleApiAvailability.getErrorDialog(getActivity(), googlePlayServicesAvailabilityResult, GOOGLE_PLAY_SERVICES_REQUEST_CODE);
if (errorDialog != null) {
errorDialog.setCancelable(false);
errorDialog.setCanceledOnTouchOutside(false);
errorDialog.setOnDismissListener((DialogInterface dialogInterface) -> {
Toast.makeText(getContext(), "You need Google Play location services to run this application!", Toast.LENGTH_LONG).show();
getActivity().finish();
});
errorDialog.show();
}
} else if (googleApiClient.isConnected() && !isUpdatingLocation) {
startLocationUpdates();
}
super.onResume();
}
My gradle file looks like following:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.example.akif"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "0.1"
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
debug {
applicationIdSuffix '.test'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:preference-v7:24.2.0'
compile 'com.google.android.gms:play-services-location:9.4.0'
compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.github.mehmetakiftutuncu:toolbelt:1.1.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'joda-time:joda-time:2.9.4'
}
I have two Google Maps API keys set up according to my package names com.example.akif.test and com.example.akif respectively for debug and release modes. So, I don't think it's related to package names but then again, it could very well be about that as I didn't understand anything from the error.
Any idea what is happening?
After doing a lot of research with almost no results, I was able to fix the issue with following Proguard rules:
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**
I still don't know the real reason why I had this issue but it seems fixed with this.
Hope this helps.
I am attempting to send an email from an android app using Mailgun and Jersey. The problem is when I post the request to get a response, the app crashes with error: A message body writer for Java type, class com.sun.jersey.multipart.FormDataMultiPart, and MIME media type, application/x-www-form-urlencoded, was not found. I am not sure why this is the case. Researching this it was suggested you add the multipart class when creating the client, but that did not work either. Note that in this email it is simply plain text, but I will need to send another email in the app that may contain attachments - 0 or more images.
java class:
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.impl.MultiPartWriter;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MultiPartWriter.class);
Client theClient = Client.create(cc);
theClient.addFilter(new HTTPBasicAuthFilter("api", "my_api_key"));
final WebResource theWebResource = theClient.resource("https://api.mailgun.net/v3/"
+ "mailgun_domain_key"
+ "/messages");
final FormDataMultiPart message = new FormDataMultiPart();
message.field("from", "My App <donotreply#dnr.com>");
message.field("to", "email_recs");
message.field("subject", "subj");
message.field("text", "body_text");
ClientResponse response = theWebResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, message);
//app crashes after the above line is executed
build.gradle (module):
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.x.x"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions{
pickFirst 'META-INF/jersey-module-version'
pickFirst 'META-INF/services/com.sun.jersey.spi.inject.InjectableProvider'
pickFirst 'META-INF/services/javax.ws.rs.ext.MessageBodyReader'
pickFirst 'META-INF/services/javax.ws.rs.ext.MessageBodyWriter'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile files('libs/jersey-client-1.19.jar')
compile files('libs/jersey-core-1.19.jar')
compile files('libs/jersey-multipart-1.19.jar')
compile files('libs/javax.ws.rs.jar')
compile files('libs/jai_imageio-1.1.jar')
}
Look at this
theWebResource.type(MediaType.APPLICATION_FORM_URLENCODED)
You're trying to post an object that is meant to be used as a multipart request, FormDataMultiPart, but you are setting the Content-Type to application/x-www-form-urlencoded.
You just need change the Content-Type to multipart/form-data[1] or MediaType.MULTIPART_FORM_DATA.
1. As mentioned in the API documentation