213

I am developing an Android application using Android 2.2, my application APK size is 22.5 MB, and I would like to create a new build for a Samsung tablet. I got the following error:

INSTALL_FAILED_DEXOPT

How do I solve this kind of error?

E.T.
  • 125
  • 1
  • 2
  • 11
john
  • 2,131
  • 2
  • 12
  • 4
  • were you able to successfully install this application on devices other than the Samsung tablet? – Will Tate Mar 01 '11 at 17:14
  • 1
    You need to paste in the logcat output generated when the installation fails. – fadden Mar 01 '11 at 20:31
  • Uninstalling and reinstalling the app always work. Wipe user data or recreating the AVD are all just doing the same in a more time consuming manner. Question is, Is there a better and quicker option? – bschandramohan Dec 29 '11 at 07:21
  • 8
    @ChandraMohan that is NOT true. Stop trying to make it true. I've formatted my device and tried to re-install the app. It still throws this error! – Artiom Chilaru Jan 15 '12 at 17:51
  • It depends i turn off the eclipse and started it work fine but You will need to Uninstall your old version and then you should have no more issues... Settings-->Applications-->Manage Applications-->[Find and Uninstall your App] INSTALL_FAILED_DEXOPT errors should not erupt. Like – Ashishsingh Apr 20 '12 at 06:02
  • Just change the workspace and should work fine. – Deepak Goel Mar 15 '12 at 09:28
  • I had the same problem on a device I was testing on(HTC Droid Eris). I had a previously installed version of my app on the phone, I just uninstalled and reinstalled and it was fine. – ninjasense Jun 13 '11 at 15:23
  • Uninstalling app worked for me – Daahrien Sep 27 '13 at 07:51
  • logcat is your friend here. See my answer below – Dori Oct 18 '13 at 11:31
  • This solved my issue !!! [enter link description here][1] [1]: http://stackoverflow.com/a/13556519/2519412 – shimi_tap Feb 11 '14 at 09:37
  • Clearing space on my Nexus One fixed this issue for me. – TheIT Apr 09 '14 at 21:47
  • One possible issue could be that your apk is no longer fit to install thus you get this error. Possible duplicate of this [question](https://stackoverflow.com/questions/11530097/installation-failed-due-to-invalid-apk-file-android/60188684#60188684). Solution is to check the apk using apkanalyzer or verify using the program you signed it with. All the best! – Phume Feb 12 '20 at 13:17

45 Answers45

116

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

You can find the option as highlighted in the below given image:

Wipe User Data option when starting android emulator

Vikas Patidar
  • 42,865
  • 22
  • 93
  • 106
114

This seemed to be related to disk space for me. A newly rolled 5.1 emulator boots with a "low on disk space" error - and looking at the emulator properties, the default space allocated for internal storage is 800MB which seems low.

Solution, therefore was to increase this (I went to 4GB). Oddly the emulator still boots with the same disk space warning but factory resetting it (Settings --> Backup and Restore inside the emulator) solved it entirely for me.

Just a bit odd that it doesn't work out of the box with default settings.

HughHughTeotl
  • 5,439
  • 3
  • 34
  • 49
  • 3
    Indeed this what the issue I had and resetting via the phone settings fixed it for me. thanks! – Justin Stanley May 28 '19 at 17:13
  • 1
    Tried almost everything but nothing worked except this one, thanks – shehzy Jul 24 '19 at 15:55
  • 1
    After 2 hrs i found this comment - thank you for saving my day, worked! – kilian eller Jul 31 '19 at 21:30
  • 2
    This caused the INSTALL_FAILED_DEXOPT on my emulator too. I had increased the size but I needed to go to settings and run a factory restore. It fixed the issue. – Dave Thomas Oct 03 '19 at 21:35
  • 1
    Christ... again this happened to me after updating my mac OS. Doubling down on my reimbursement of that solution goto -> settings and run factory restore. Had to look up this question just to remember how I fixed it... thank god for history on stack overflow, and I was able to find my comment – Dave Thomas Feb 11 '20 at 23:15
  • Settings --> Backup and Restore fix it!! Thanks – Gueorgui Obregon May 06 '20 at 17:28
  • Indeed the INSTALL_FAILED_DEXOPT error was removed after factory reset. Notice that APK installs only works from command line, drag & drop still fails for some reason. – andreszs Jun 29 '21 at 13:04
18

Your old version of the app that you are installing has dependent libraries / jars that have been changed. I ran into this issue when updating other jar files that my app was refrencing.

You will need to Uninstall your old version and then you should have no more issues...

Settings-->Applications-->Manage Applications-->[Find and Uninstall your App]

INSTALL_FAILED_DEXOPT errors should not erupt. Like

[2011-06-14 01:23:40 - ProtectYourself] Installing ProtectYourself.apk...
[2011-06-14 01:24:26 - ProtectYourself] Installation error: INSTALL_FAILED_DEXOPT
[2011-06-14 01:24:26 - ProtectYourself] Please check logcat output for more details.
[2011-06-14 01:24:26 - ProtectYourself] Launch canceled!

Whoo hoo.

Lenn Dolling
  • 1,300
  • 13
  • 23
  • I can concur the cause & effect. The same situation happened in my case after tinkering with jars. For me this was on Android 2.3 Gingerbread based devices only, ICS & Lollipop were fine. – AlexVPerl May 25 '15 at 00:53
  • Will this be an issue when uploading to the Play Store? or does the installer delete the app and reinstall? – Eduardo Naveda Jun 08 '15 at 19:22
17

Ran into this with Android Studio 3.4.1 but using an older (5.0) emulator. This procedure (on Mac) fixed the issue:

  1. stop emulator
  2. cd ~/.android/avd/[emulator name].avd
  3. rm *.lock
  4. wipe emulator
  5. start emulator
Ken
  • 1,691
  • 5
  • 22
  • 38
  • 5
    Doing what's mentioned above *after increasing the emulator's internal storage to 4gb* is the only thing that worked for me. – dell116 Jul 08 '19 at 13:52
  • @dell116 I'm not surprised that sometimes more than one thing will have to be done, just based on all the different answers to this question! – Ken Jul 08 '19 at 20:47
  • 3
    Agreed! And congrats on snagging the username "Ken". – dell116 Jul 09 '19 at 12:41
  • Unfortunately none of the combinations of wiping/increasing storage/wiping again helped me. I gave up. – Can Poyrazoğlu Jul 11 '19 at 19:44
  • 1
    @CanPoyrazoğlu — I almost gave up, too. I think the emulators must be extremely sensitive and many things can cause them to fail (as evidenced by all the different answers here to a question asked more than eight years ago). Removing the .lock files was key in my case, but I can certainly see where that might not solve all the issues. – Ken Jul 12 '19 at 12:14
  • Both `lock` file deletion and `emulator memory increase` were necessary for my case. I increased my Emulator's memory from **1 GB** to **2 GB** and it worked. Only deleting lock file didn't help me. – Abhishek May 30 '20 at 10:40
15

If you are using Android Studio, try clean your project:

Build > Clean Project

SandroMarques
  • 6,070
  • 1
  • 41
  • 46
11

It seems like this error message can have many different causes. The case I came across was on a real device (so the emulator bases solutions did not apply).

Basically, when this happens, set your Logcat filter to Verbose or Warn, which will help you get more information about the cause.

In my case, multiple or conflicting versions of JUnit were being included in the project I was working on (a large existing codebase). The Android app I was trying to deploy had several library projects as dependencies, and I had mistakenly set things up to include multiple JUnit jar files.

I discovered this based on a series of Logcat messages. Note that the WARN line gives the cause:

DEBUG/dalvikvm(4808): DexOpt: 'Ljunit/framework/TestSuite$1;' has an earlier definition; blocking out
11-06 14:30:10.973: WARN/dalvikvm(4808): Invalid file flags in class Ljunit/runner/Sorter$Swapper;: 0209
11-06 14:30:10.973: null/libc(4808): Fatal signal 11 (SIGSEGV) at 0x00000004 (code=1), thread 4808 (dexopt)
wsanville
  • 37,158
  • 8
  • 76
  • 101
  • 4
    This is a good suggestion. I agree that you should view LogCat output to see what the actual error message is. I was getting this error and it was because my device was low on storage and it was failing to unzip the APK. I believe there are multiple reasons that this error can be triggered and uninstalling or clearing user data may be unnecessary. I posted this same suggestion as an answer to a similar (duplicate) question. – Bryan Bedard Nov 30 '12 at 01:58
  • 2
    SORRY, THIS IS THE SAME POINT THAT Bryan Bedard WAS MAKING. I was out of space -- usually, I get an error like "insufficient space", but for some reason I got this DEXOPT error. Logcat showed an error Zip inflate: write failed: No space left on device. – mobibob Sep 05 '13 at 17:39
11

I' changed the RAM size and internel storage capacity of the emulator Now IT IS Working... in eclipse AVD manager

KATJ Srinath
  • 950
  • 1
  • 11
  • 18
10

try my answer https://stackoverflow.com/a/34918549/3737254

if you use android studio 2.0, DISABLE the instant run.

FYI, instant run is new feature from android studio 2.0 (i never used it >.<)

how to disable : preferences -> build, execution & deployment -> instant run -> disable, then works like magic

Enjoy!

Community
  • 1
  • 1
yfsx
  • 1,906
  • 14
  • 17
  • This was my issue when testing old APIs on an emulator. After changing this and a clean wipe of the emulator it worked! – Ben Jul 30 '19 at 20:44
10

The only solution that worked for me to fixed this was to increase the VM's RAM to 4GB.

Jim
  • 1,027
  • 1
  • 10
  • 19
8

I needed to disable Instant Run to fix the issue. To disable Instant Run on OS X, go to Android Studio > Preferences > Build, Execution, Deployment > Instant Run then remove the tick from Enable Instant Run to hot swap code/resource changes on deploy (default enabled).

iamkaan
  • 1,495
  • 2
  • 23
  • 43
  • This worked for my `dexopt error. Application failed to install`. I tried these before I found this: `adb kill-server` `adb start-server`, restarting Android Studio, and Factory resetting my device. – Sherlock Mar 06 '16 at 04:10
6

I had the same issue today with Android Studio on a new virtual device. It appeared I had downloaded the x86_64 image, recreating the VD with the equivalent x86 image fixed it.

I expected to get a INSTALL_FAILED_NO_MATCHING_ABIS in this case but somehow I was stuck with INSTALL_FAILED_DEXOPT

dvkch
  • 1,079
  • 1
  • 12
  • 20
  • 1
    For me it was the opposite. Attempting to install on `x86` failed. After downloading the image and changing the emulator to `x86_64` the error was gone. I used the API 21 system image. – friederbluemle Jun 27 '18 at 07:37
  • The opposite worked for me as well. Tried everything on this thread before trying to use the `x86_64` image instead of the `x86` one. I was also using an API 21 AVD (Nexus 5). – Renan Ferrari May 07 '20 at 14:20
5

I am working with Android Studio and had the same error.

Deleting the build folder of the main Modul helped. After deleting everything get back to normal.

Informatic0re
  • 6,300
  • 5
  • 41
  • 56
4

INSTALL_FAIL_DEXOPT usually has to do with the limit placed on classes.dex. On anything pre-ICS dexopt will fail on anything over 5 MB. Recent versions of Android use an 8 or 16 MB buffer.

Check the size of classes.dex in your APK. It would also be good to see what your method count is, as dex has a 65536 method/field limit.


References:

Error while installing application (INSTALL_FAILED_DEXOPT)

https://www.facebook.com/notes/facebook-engineering/under-the-hood-dalvik-patch-for-facebook-for-android/10151345597798920

How to shrink code - 65k method limit in dex

Community
  • 1
  • 1
Jared Rummler
  • 37,824
  • 19
  • 133
  • 148
4

verify the storage space on your device

Farido mastr
  • 464
  • 5
  • 12
3

I ran into this problem after enabling the jumboMode flag in the build (dex.force.jumbo=true). Everything worked fine on newer Android devices, but installation failed on Gingerbread.

So if your app requires jumbo mode due to the annoying 65k restriction, try cutting some unused code/strings and setting jumbo mode back to false.

friederbluemle
  • 33,549
  • 14
  • 108
  • 109
  • I also just enabled jumbo mode and started to see this when testing on old devices. Unfortunately reverting back to false didn't resolve the issue for me. Using proguard to shrink the APK did. – slott Oct 01 '14 at 08:40
  • We encountered the same issue, Jumbo Mode is not working with API 10 – Henrique de Sousa Aug 10 '15 at 13:32
3

classes.dex does not make it to the final .apk. Running gradlew --offline clean && gradlew --offline assembleDebug fixed things for me every time. From that point you can start launching the app from Android Studio again.

EDIT: Before what I said above go to Task Manager and kill all cmd.exe and conhost.exe processes (or just the one in which aapt got stuck). Otherwise aapt would crash from now on when launched from command line with the infamous error -1073741819.

Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124
  • Appreciated :D worth mentioning that the newest build tools (2.1.1) and gradle plugin (1.0.0-rc1) work like a charm – Eugen Pechanec Dec 09 '14 at 00:00
  • Well I don't know about that, I just installed android studio 1.0 and had to do this to get it to work. – axnsan Dec 09 '14 at 00:17
  • Try killing all java.exe too. How much RAM do you have? Make absolutely sure you have the latest version of the following: Android Studio 1.0.0-rc4, gradle android plugin 1.0.0-rc1, build tools 21.1.1. I haven't seen the error for some time now. – Eugen Pechanec Dec 09 '14 at 18:40
  • Build tools are 21.1.1, android studio is 1.0, and I don't know how to find the gradle plugin version. I just downloaded the 1.0 release that appeared yesterday on the android developers site... – axnsan Dec 09 '14 at 18:44
  • Look in your root project `build.gradle` file. Among buildscript dependencies there should be `classpath 'com.android.tools.build:gradle:1.0.0-rc4'`. – Eugen Pechanec Dec 10 '14 at 00:16
  • It's just 1.0.0. If I try to add -rc4, I get this error: `You must use a newer version of the Android Gradle plugin. The minimum supported version is 1.0.0 and the recommended version is 1.0.0. Not all versions of the Android Gradle plugin are compatible with all versions of the SDK. If you update your tools, or if you are trying to open a project that was built with an old version of the tools, you may need to update your plugin version number.` – axnsan Dec 10 '14 at 08:29
  • Rc means Release Candidate. Two days ago was released a full baked version. Just delete the -rc1. – Eugen Pechanec Dec 10 '14 at 13:01
  • Meh, I give up. I tried everything short of reinstalling Windows. Maybe I'll try again when Windows 10 launches. – axnsan Dec 10 '14 at 18:07
3

I got the same error and fixed it by increasing the size of internal storage.

The internal storage was initially set to 32MB(I know) and then I installed a couple of apks on it, which had left less space than what was needed for the one to be installed.

binRAIN
  • 45
  • 2
2

I had the app uninstalled and got the INSTALL_FAILED_DEXOPT error nevertheless. If you are working with Android Studio / gradle: gradle clean did the trick for me, Cheers.

JacksOnF1re
  • 3,336
  • 24
  • 55
  • I had to use gradlew, but hey it worked! thanks (also removed the package in data/data) – Maxim Nov 23 '14 at 20:38
2

in build.gradle change compiled and build to latest version. and it worked for me.

================

android {
    compileSdkVersion 22
    buildToolsVersion "22"
riseres
  • 3,004
  • 4
  • 28
  • 40
2

I found there's one reason for this problem: not enough space on mobile. So I delete several APP from mobile and it's fixed.

Jalon Ray
  • 21
  • 3
2

a lot of answers here, but maybe it can help someone I had this issue with real device and problem was with D8

try to add this to your gradle.properties and it works for me

android.enableD8=false
android.enableD8.desugaring= false
NataTse
  • 381
  • 2
  • 10
1

I was getting this issue when trying to install on 2.3 devices (fine on 4.0.3). It ended up being due to a lib project i was using had multiple jars which were for stuff already in android e.g. HttpClient and XML parsers etc. Looking at logcat led me to find this as it was telling me it was skipping classes due to them already being present. Nice unhelpful original error there!

Dori
  • 18,283
  • 17
  • 74
  • 116
  • 2
    I have the same problem can you explain how did you cleared that issue . I Have libs size more than 7 mb so its not allow me to install in the earlier device like 2.3. – Rakki s Aug 01 '14 at 09:36
  • In my case, I was using gradle build to create apk and the culprit was bouncy-castle provider jar. I had to exclude module 'bcprov-jdk' in root project's compile dependencies. – Pawan Dec 23 '14 at 11:20
1

I had this error testing on a real device. Clearing cache/uninstalling, restarting everything didn't work for me, deleting the contents of the build folder did :) (Android studio)

Gyroscope
  • 3,121
  • 4
  • 26
  • 33
1

There's no generic solution, you have to find the error reported on your Logcat to be able to figure it out. Sometimes it's a class that can't be 'dexed' due to an usage of a class not available on the specified Target API for instance. Or it could be a class that you're making reference in your code, but the library that it is in is not being packaged.

Alécio Carvalho
  • 13,481
  • 5
  • 68
  • 74
1

Consider using proguard to shrink your APK. I have the same issue if I try to install a large 25MB+ APK on an old Samsung Galaxy Ace 2.3.6 device without shrinking/optimizing code with proguard.

Jumbo mode and restarting the device is not working.

slott
  • 3,266
  • 1
  • 35
  • 30
1

In my case, this was a bug in kotlin plugin, version 1.1.51

https://youtrack.jetbrains.com/issue/KT-20034

This error appeared on old devices (API 16).

Fixed this by removing @Parcelize annotations and replacing them with this code generator: https://github.com/nekocode/android-parcelable-intellij-plugin-kotlin

stillwaiting
  • 415
  • 1
  • 5
  • 14
1

targetSdkVersion 22//17==========================> set this number less then or equal to the version of Android OS on devices might help

 defaultConfig {
        applicationId "software.nhut.personalutilitiesforlife"
        minSdkVersion 16
        targetSdkVersion 22//17==========================> set this number less then or equal to the version of Android OS on devices might help
        versionCode 5
        versionName "1.26"
        // Enabling multidex support.
        multiDexEnabled true
    }
Thunder knight
  • 284
  • 3
  • 5
1

In my case problem was happening on some devices running API 21 and 22. Setting android:vmSafeMode="true" in manifest under application tag resolved the issue. However, it is not recommended for release builds, so I created two xml files in values folder. The default one for older API's:

<resources>
    <bool name="vm_safe_mode">true</bool>
</resources>

And the same for API's >= 23 with false value. In that case devices with newer OS won't be affected and the old ones will at least work.

anro
  • 1,300
  • 16
  • 30
0

I had this problem when there were some Unicode characters in my method names (due to, of all things, copy/pasting from a powerpoint file) that Dalvik did not like. You can see this by looking at Logcat output while trying to install the APK.

This was on a real device.

thoutbeckers
  • 2,599
  • 22
  • 24
0

Solved by correcting date time on the phone (it was some default date 01.01.1980), and cleaning the project.

No Name
  • 719
  • 6
  • 14
0

I had changed my version of android version 4 support for sdk 21 and had this error. So I went back the version of support for the old version (before 21) and it worked. The error was occurring only in android 2.3

Cícero Moura
  • 2,027
  • 1
  • 24
  • 36
0

I've ran into this problem when I was trying to update new build tools 24.0.1. Internet connection was lost and tools was not downloaded successfully, after that I got this error and spent a lot of time trying to solve it. But when I succesfully updated build tools - problem solved. Good luck.

Alex Perevozchykov
  • 2,211
  • 22
  • 19
0

Make sure you have all the SDK's you need installed and Gradle is targeting the right version.

I was having the same issue, but it was caused by me updating my device to Android 5.0 and then forgetting to change all my builds to target it.

0

I have faced this issue because there was some mismatch with the libraries i was using

Resolved by updaing android sdk to latest. Check SDK manager if it shows update then fully update, clean your project and then run, it will work :)

Sonali8890
  • 2,005
  • 12
  • 16
0

Maybe this will help:

  1. Wipe the user data before launching the emulator
  2. clean the project
  3. remove dependencies which are not required....
Rajat Sawant
  • 133
  • 1
  • 9
0

The error get resolved by deleting the build folder of your main app.It will recreate again.

Prateek
  • 306
  • 4
  • 17
0

In android Studio click on File -> Invalidate caches/ restart . This did the trick for me when I was getting this error when I got this error on device not emulator.

Amr El Aswar
  • 3,395
  • 3
  • 23
  • 36
0

For me it was proguard that was causing INSTALL_FAILED_DEXOPT on some Samsung devices with Android 5.x.

Namely I had to add this to proguard - not sure why it helped.

-keepattributes LocalVariableTable
Martin Rajniak
  • 630
  • 8
  • 26
0

Restart your device.

In my case, the app run in most devices except for one: a cellphone that was too old and had been failing lately, the app thrown this error even without having installed the app once.

dianakarenms
  • 2,609
  • 1
  • 22
  • 22
0

Also if you are using ECLIPSE yet, try clean your project:

Project > Clean...

Adamz
  • 13
  • 4
0

One reason is that classes.dex is not found in the root of the .apk-package. Either

  • this file is missing in the apk-package or
  • it is located in a subfolder within the .apk file.

Both situations cause the termination because Android supposedly searches only in the root of the apk file. The confusion is because the build run of the .apk file was without an error message.

Core reasons for that error may be:

  • The dx tool need classes.dex in the current main working folder. But in reality classes.dex is located somewhere other.
  • aapt have a wrong information for the location for classes.dex. For example with aapt.exe add ... bin/classes.dex. Thats would be wrong because classes.dex is in a subfolder /bin of the created .apk file.
gotwo
  • 663
  • 8
  • 16
0

To anyone searching for this with keyword "Room". I met this problem while implementing Room to manage my database. The cause was that I copied all dependencies from Android documentation. Copy only the ones you need. If you are not using Kotlin nor Guava add only:

implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
testImplementation "androidx.room:room-testing:$room_version"
0

I added the follow lines to the gradle.properties file and the problem was solved:

android.enableD8=false 
android.enableD8.desugaring= false

I'm running the app in a real device.

CarlFerr
  • 51
  • 1
  • 4
-1

As this seems to be a problem I have myself encountered multiple times and this time none of the shared solutions helped me, I'll still post what helped me personally and what I believe may help someone else in future:

Go to your project's directory and find build/intermediates/dex-cache/cache file. Remove it - as name suggests, it's a cached dex file that may be outdated if you have made changes to your project's dependencies, build tools version etc.

Sosoel
  • 116
  • 1
  • 7
-2

If you have error INSTALL_FAIL_DEXOPT, see in manifest android:targetSdkVersion. Set version < 21 sample:

android:targetSdkVersion="19"

This worked for me.