Home » Android » gradle – INSTALL_FAILED_DEXOPT Error in Android 5.0 in Release mode

gradle – INSTALL_FAILED_DEXOPT Error in Android 5.0 in Release mode

Posted by: admin April 23, 2020 Leave a comment

Questions:

I have a strange issue with INSTALL_FAILED_DEXOPT .
This occurs in android 5.0 devices in emulator as well as in devices.
And strange thing is that it works well when build variant in Debug mode .

If I change to Release I get this exception only on 5.0 devices. I have thoroughly went through all the links that is available in google.

  1. Wipe the data

  2. Bought a new device where I can install for the first time but still I face the same issue.

  3. Project has multidex support:- true in gradle

  4. Also tried change SDK tool version and build tool version to latest which is 24.4.0.

I use this device
enter image description here

When i build in release mode i get this Error
enter image description here

in Console

enter image description here

These are the build type we use.

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        signingConfig signingConfigs.release
    }


    debug {
        applicationIdSuffix ".debug"
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        signingConfig signingConfigs.debug
    }


}

Image of SDK Tools used:

enter image description here
I can assure you that there has been never a build installed the device.I have cleared everything if it already installed.

Can somebody in this world could help me with this issue.Because it driving us crazy…..

How to&Answers:

when apk install to android, android execute dex2opt for optimizing. INSTALL_FAILED_DEXOPT error message mean your android device can’t optimizing dex. this can be occured by dex size. you can find “LinearAlloc Limit” warning or error message in android monitor.

if it is problem of dex size. add this to config.

afterEvaluate{
tasks.matching {
    it.name.startsWith('dex')
}.each { dx ->
    if(dx.additionalParameters == null){
        dx.additionalParameters = []
    }
    //To avoid linearAlloc limit problem on Gingerbread and below
     dx.additionalParameters += "--set-max-idx-number=50000"
     dx.additionalParameters += "--minimal-main-dex"
}

}

and Instant Run = On to off

Answer:

This issue might occur due to mismatching sdks between Android Studio and the Project. The project was using an old sdk and once I made them the same, I cleaned and rebuilt the project and everything was good to go.

Answer:

please see if your app has been by mistake installed in your guest account of your phone.

If yes, then un-install or remove it from there.

Do this for all user accounts in your phone.

Additional tips:-

Build -> Clean project Build -> Rebuild project

Answer:

This might due to different version of Gradle build tools in your Module and Project build file. Make sure they use the same version in both file, clean and build again, and it should be fine.

Answer:

It sounds like multidex might be your issue. Android handles this natively on Lollipop devices (which may account for some devices behaving correctly, but others having problems), but uses the multidex library on older devices which could explain why older devices behave uniformly (see http://developer.android.com/tools/building/multidex.html).

Are you close enough to the 65k limit that you could use ProGuard or temporarily remove one of your dependencies such that you wouldn’t need multidex? Despite there being a library to support it, it is generally a good idea to reduce your method count so that you don’t need it. I know some apps may really need it, but it’s worth checking this first.

Also, investigate using the granular Google Play Services modules. If you’re pulling in all of GMS, switching to granular includes can reduce your method count significantly: http://android-developers.blogspot.com/2014/12/google-play-services-and-dex-method.html

Answer:

Try to uninstall this app, and all others who have your signature on your device. Clean your project and restart install. Also, you should consider installing your app through another mean that ADB, for instance using dropbox.

Answer:

Restarting the emulator from the Android SDK and AVD Manager and selecting the option Wipe User Data has solved this problem for me.

Answer:

I got the same issue while testing code in my phone. I followed below steps

  1. Clean and Build the code
  2. Upgrade Android Studio to latest release

It solved my issue and please check in your case.

Answer:

This issues might ocuur when you install the debug/release apk while relese/debug apk is already installed in your device/emulator.means if you are installing debug apk while release apk is exist or if you are installing release apk while debug apk is exist.so uninatall the apk and install it again

Answer:

afterEvaluate{
    tasks.matching {
        it.name.startsWith('dex')
    }.each { dx ->
        if(dx.additionalParameters == null){
            dx.additionalParameters = []
        }
        //To avoid linearAlloc limit problem on Gingerbread and below
        dx.additionalParameters += "--set-max-idx-number=65535"
        dx.additionalParameters += "--minimal-main-dex"
   }
}