Search code examples
androidrx-javarx-androiddexsqlbrite

Android app install with Failure [INSTALL_FAILED_DEXOPT] Android 2.3.x devices


I have an app composed of multiple modules which I have just updated from rxjava1 to rxjava2. Now there is no way to install it on android 10 devices or emulators. On compile time, no errors but installs fails either from android studio or command line. here are some of my settings:

compileSdkVersion = 25
buildToolsVersion = "25.0.1"
minSdkVersion = 10
targetSdkVersion = 21

running ./gradlew app:dependencies

compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:25.3.1
|    +--- com.android.support:support-annotations:25.3.1
|    +--- com.android.support:support-v4:25.3.1
|    |    +--- com.android.support:support-compat:25.3.1
|    |    |    \--- com.android.support:support-annotations:25.3.1
|    |    +--- com.android.support:support-media-compat:25.3.1
|    |    |    +--- com.android.support:support-annotations:25.3.1
|    |    |    \--- com.android.support:support-compat:25.3.1 (*)
|    |    +--- com.android.support:support-core-utils:25.3.1
|    |    |    +--- com.android.support:support-annotations:25.3.1
|    |    |    \--- com.android.support:support-compat:25.3.1 (*)
|    |    +--- com.android.support:support-core-ui:25.3.1
|    |    |    +--- com.android.support:support-annotations:25.3.1
|    |    |    \--- com.android.support:support-compat:25.3.1 (*)
|    |    \--- com.android.support:support-fragment:25.3.1
|    |         +--- com.android.support:support-compat:25.3.1 (*)
|    |         +--- com.android.support:support-media-compat:25.3.1 (*)
|    |         +--- com.android.support:support-core-ui:25.3.1 (*)
|    |         \--- com.android.support:support-core-utils:25.3.1 (*)
|    +--- com.android.support:support-vector-drawable:25.3.1
|    |    +--- com.android.support:support-annotations:25.3.1
|    |    \--- com.android.support:support-compat:25.3.1 (*)
|    \--- com.android.support:animated-vector-drawable:25.3.1
|         \--- com.android.support:support-vector-drawable:25.3.1 (*)
+--- com.android.support:recyclerview-v7:25.3.1
|    +--- com.android.support:support-annotations:25.3.1
|    +--- com.android.support:support-compat:25.3.1 (*)
|    \--- com.android.support:support-core-ui:25.3.1 (*)
+--- com.android.support:design:25.3.1
|    +--- com.android.support:support-v4:25.3.1 (*)
|    +--- com.android.support:appcompat-v7:25.3.1 (*)
|    +--- com.android.support:recyclerview-v7:25.3.1 (*)
|    \--- com.android.support:transition:25.3.1
|         +--- com.android.support:support-annotations:25.3.1
|         \--- com.android.support:support-v4:25.3.1 (*)
+--- com.google.android.gms:play-services-maps:7.5.0
|    \--- com.google.android.gms:play-services-base:7.5.0
|         \--- com.android.support:support-v4:22.0.0 -> 25.3.1 (*)
+--- com.google.android.gms:play-services-gcm:7.5.0
|    \--- com.google.android.gms:play-services-base:7.5.0 (*)
+--- org.ocpsoft.prettytime:prettytime:3.2.4.Final
+--- com.google.maps.android:android-maps-utils:0.4
+--- com.fasterxml.jackson.core:jackson-databind:2.4.4
|    +--- com.fasterxml.jackson.core:jackson-annotations:2.4.0
|    \--- com.fasterxml.jackson.core:jackson-core:2.4.4 -> 2.8.7
+--- com.google.code.gson:gson:2.7
+--- com.jakewharton.timber:timber:4.3.1
+--- com.google.dagger:dagger:2.8
|    \--- javax.inject:javax.inject:1
+--- com.jakewharton:butterknife:8.5.1
|    +--- com.jakewharton:butterknife-annotations:8.5.1
|    |    \--- com.android.support:support-annotations:25.1.0 -> 25.3.1
|    +--- com.android.support:support-annotations:25.1.0 -> 25.3.1
|    \--- com.android.support:support-compat:25.1.0 -> 25.3.1 (*)
+--- com.getsentry.raven:raven-android:8.0.2
|    \--- com.getsentry.raven:raven:8.0.2
|         +--- org.slf4j:slf4j-api:1.7.24
|         \--- com.fasterxml.jackson.core:jackson-core:2.8.7
+--- com.github.bumptech.glide:glide:3.8.0
+--- com.squareup.sqlbrite2:sqlbrite:2.0.0
|    +--- io.reactivex.rxjava2:rxjava:2.1.0
|    |    \--- org.reactivestreams:reactive-streams:1.0.0
|    \--- com.android.support:support-annotations:25.3.1
+--- io.reactivex.rxjava2:rxandroid:2.0.1
|    \--- io.reactivex.rxjava2:rxjava:2.0.1 -> 2.1.0 (*)
+--- io.reactivex.rxjava2:rxjava:2.1.0 (*)
+--- project :domain
|    +--- com.google.dagger:dagger:2.8 (*)
|    +--- io.reactivex.rxjava2:rxandroid:2.0.1 (*)
|    \--- io.reactivex.rxjava2:rxjava:2.1.0 (*)
+--- project :data
|    +--- project :domain (*)
|    +--- project :database
|    |    +--- com.jakewharton.timber:timber:4.3.1
|    |    +--- com.squareup.sqlbrite2:sqlbrite:2.0.0 (*)
|    |    +--- io.reactivex.rxjava2:rxandroid:2.0.1 (*)
|    |    \--- io.reactivex.rxjava2:rxjava:2.1.0 (*)
|    +--- com.google.dagger:dagger:2.8 (*)
|    +--- com.squareup.retrofit2:converter-gson:2.3.0
|    |    +--- com.squareup.retrofit2:retrofit:2.3.0
|    |    |    \--- com.squareup.okhttp3:okhttp:3.8.0
|    |    |         \--- com.squareup.okio:okio:1.13.0
|    |    \--- com.google.code.gson:gson:2.7
|    +--- com.squareup.okhttp3:logging-interceptor:3.6.0
|    |    \--- com.squareup.okhttp3:okhttp:3.6.0 -> 3.8.0 (*)
|    +--- com.squareup.retrofit2:adapter-rxjava2:2.3.0
|    |    +--- com.squareup.retrofit2:retrofit:2.3.0 (*)
|    |    \--- io.reactivex.rxjava2:rxjava:2.0.0 -> 2.1.0 (*)
|    +--- com.jakewharton.timber:timber:4.3.1
|    +--- com.squareup.sqlbrite2:sqlbrite:2.0.0 (*)
|    +--- io.reactivex.rxjava2:rxandroid:2.0.1 (*)
|    \--- io.reactivex.rxjava2:rxjava:2.1.0 (*)
\--- project :database (*)

I did everything any other similar thread said, clean project, delete build folders, I even started a fresh build on another computer so no way the app was previously installed built there.

If I remove the rxjava2 and rxandroid2 dependency and comment out all the code that uses them, then the app installs fine. As soon as I reenable them I get the error again. On studion the error is:

Installation failed since the device possibly has stale dexed jars 
that don't match the current version (dexopt error).
In order to proceed, you have to uninstall the existing application.

WARNING: Uninstalling will remove the application data!

Do you want to uninstall the existing application?

Of course I say yes even if I know the app is not installed and of course it fails.

I have tried the method count with this tool https://github.com/KeepSafe/dexcount-gradle-plugin Methods are still below 64000 but even I added multidex as explained here: https://developer.android.com/studio/build/multidex.html but still it does not work! I have tried playing with target SDK, increase to 25 and even buildtools to 26, using a more recent gradle wrapper then before (currently I am on 3.5) but nothing, still the same issue. I have no idea of what else to try than to revert back to rxjava1 but the reason I updated in the first place is because I have too many items and get OOME on android 10 so after reading this https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#which-type-to-use I decided to upgrade. It does not say anywhere that rxjava2 is not compatible with android 10. App installs fine on android 19++ (have not tried inbetween 10 and 19) I have tried the sample from https://github.com/square/sqlbrite and I changed it to work with api 10 and it installs fine on android 10. Any ideas of that else I can try?

update: these are the logs from the emulator:

56.584 1186-1207/system_process E/PackageManager: Package com.mypackage.myapp has mismatched uid: 10070 on disk, 10040 in settings
08-18 11:47:56.784 1853-1853/? E/dalvikvm: LinearAlloc exceeded capacity (5242880), last=220
08-18 11:47:56.784 1853-1853/? E/dalvikvm: VM aborting
08-18 11:47:56.804 1132-1132/? E/installd: dexopt failed on '/data/dalvik-cache/data@[email protected]@classes.dex' res = 11

Update 2: I have added proguard and still get the same error even when trying to install the release builds (with proguard)


Solution

  • Unfortunately I have not found any other solution than removing

    com.fasterxml.jackson.core:jackson-databind
    

    library. Since I also use Gson I just modified the code using that library to use Gson instead.

    When found yourself facing this error, do not lose time attempting adding multidex and configuring to separate into 2 dex files, this never works right.

    Examine all your libs for example with http://www.methodscount.com/ and find some big libraries you can remove or replace with smaller ones.

    Usefull plugin to track methods count in your app is https://github.com/KeepSafe/dexcount-gradle-plugin