34

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.....

Rockin
  • 723
  • 4
  • 25
  • 51
  • Does your all use and external, pre-built libraries (not game dependencies)? If so, are they in jar or aar form? – Larry Schiefer Oct 02 '15 at 14:48
  • Please post the logcat from when the install fails – iagreen Oct 03 '15 at 02:18
  • Can you post the `build.gradle` code? Especially `buildTypes` element with `debug` and `release` variants. – Abhishek V Oct 03 '15 at 03:35
  • @LarrySchiefer we use external jars and Module dependencies – Rockin Oct 07 '15 at 13:43
  • @AbhishekV please check the question .i have edited – Rockin Oct 07 '15 at 13:46
  • This is a long shot, but once I had similar problems when installing, because I had two accounts on my phone, and somehow the second account (which I never used) had the application installed aswell. So I had to switch accounts, delete it there and than it worked. – Marko Oct 07 '15 at 14:02
  • just wana ask, are you using google play services lib ? – penta Oct 07 '15 at 14:42
  • @penta ..I have google play service library in project....and multidex is enabled...it works for 5 and above devices ..but not certain 5.0 devices.if i change gradle version to 1.0.0..then in debug it works for the above device but release fails...if change 1.3.1 then it does nt for both build variants. – Rockin Oct 08 '15 at 13:23
  • Hey @Rockin, sorry that my answer was not able to help you, try adb uninstall command and tell us what do you get :-) – penta Oct 08 '15 at 13:59
  • after you try to install, can you take logcat and post the log – nandeesh Oct 09 '15 at 07:37
  • @Rockin - we got this error a long time ago in my previous job. The issue was caused by a bad ProGuard configuration (something releated to the Attributes). Please make absolutely sure you have no "minifyEnabled true" in your project. – oba Oct 14 '15 at 10:17
  • @oba I checked all modules and project minifyEnabled is false. – Rockin Oct 14 '15 at 12:00
  • Which is solved this issue for me: Downloaded the 23.0.2 SDK tools: https://dl.google.com/android/android-sdk_r23.0.2-windows.zip, then I copied only the tools folder to my SDK. Then do the same with the platform tools: http://dl-ssl.google.com/android/repository/platform-tools_r22-windows.zip. – Zsolt Mester Oct 17 '15 at 19:50
  • @Zsolt Mester I am using latest sdk tools 24.4 – Rockin Oct 19 '15 at 12:11
  • @ZsoltMester I also checked with 23.0.2.. – Rockin Oct 19 '15 at 15:10
  • Okay, can you attach a log from logcat? – Zsolt Mester Oct 19 '15 at 20:41
  • @ZsoltMester there is no logcat as application is not installed...you can see the log in console...that already pasted above.. – Rockin Oct 20 '15 at 18:53
  • What about the google play services version - is that updated to the latest and you've updated build.gradle with it? – Vrashabh Irde Oct 21 '15 at 09:41
  • google play services android:versionCode="5077000" – Rockin Nov 04 '15 at 16:15

9 Answers9

4

When the APK is installed onto Android, the OS executes dex2opt for optimizing. The INSTALL_FAILED_DEXOPT error message means that your device can't optimize the dex file.

This issue usually occurs because of the dex file size. Usually, you can find a LinearAlloc Limit warning or error message in the Android monitor when this happens. If it is a problem of dex size, add this to your build.gradle file:

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"
    }
}

Also, be sure to turn Instant Run off.

Oliver Spryn
  • 16,871
  • 33
  • 101
  • 195
hanbumpark
  • 233
  • 2
  • 14
0

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.

0

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

penta
  • 2,536
  • 4
  • 25
  • 50
  • You transformed my comment into answer :D well played – Marko Oct 07 '15 at 14:26
  • Sorry, i did not see your comment, your comment was hidden. I have faced same problem and answered these type of questions before – penta Oct 07 '15 at 14:28
  • @Marko see this link, i have answered these questions before http://stackoverflow.com/questions/32910041/android-when-i-try-to-install-my-signed-app-it-says-app-not-installed/32919015#32919015 – penta Oct 07 '15 at 14:29
  • 1
    No worries, I tought you missed it. Didn't want to post it as an answer, since it's a long shot. Let's hope it helps :) – Marko Oct 07 '15 at 14:29
  • 1
    @Marko Thanks for understanding :-) kindly see my comments. – penta Oct 07 '15 at 14:30
  • I already mentioned i tried to install the built in a new device bought freshly from market..Clean rebuild all mechanism i have tried...i told you i have googled a lot ..played around for 1 week...atlast only i posted in stack overflow – Rockin Oct 08 '15 at 13:17
0

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.

C.Allan
  • 141
  • 1
  • 5
0

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

ProjectJourneyman
  • 3,566
  • 1
  • 27
  • 37
0

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.

ripan
  • 78
  • 8
-1

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

Renjith
  • 546
  • 1
  • 8
  • 28
-1

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.

Srikanth104
  • 65
  • 2
  • 10
-2

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