john
john

Reputation: 2121

How do I solve the INSTALL_FAILED_DEXOPT error?

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?

Upvotes: 212

Views: 181493

Answers (30)

CarlFerr
CarlFerr

Reputation: 81

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.

Upvotes: 0

Krzysztof Wiśniewski
Krzysztof Wiśniewski

Reputation: 31

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"

Upvotes: 0

anro
anro

Reputation: 1388

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.

Upvotes: 1

gotwo
gotwo

Reputation: 870

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.

Upvotes: 0

NataTse
NataTse

Reputation: 411

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

Upvotes: 2

Jim
Jim

Reputation: 1147

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

Upvotes: 10

Ken
Ken

Reputation: 1721

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

Upvotes: 17

Farido mastr
Farido mastr

Reputation: 504

verify the storage space on your device

Upvotes: 4

HughHughTeotl
HughHughTeotl

Reputation: 5789

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.

Upvotes: 117

Thunder knight
Thunder knight

Reputation: 284

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
    }

Upvotes: 1

Jalon Ray
Jalon Ray

Reputation: 21

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.

Upvotes: 2

dvkch
dvkch

Reputation: 1109

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

Upvotes: 6

Adamz
Adamz

Reputation: 13

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

Project > Clean...

Upvotes: 0

stillwaiting
stillwaiting

Reputation: 474

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

Upvotes: 1

dianakarenms
dianakarenms

Reputation: 2695

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.

Upvotes: 0

Martin Rajniak
Martin Rajniak

Reputation: 640

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

Upvotes: 0

Amr El Aswar
Amr El Aswar

Reputation: 3515

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.

Upvotes: 0

user3270024
user3270024

Reputation: 1

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

android:targetSdkVersion="19"

This worked for me.

Upvotes: -2

Sosoel
Sosoel

Reputation: 116

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.

Upvotes: -1

iamkaan
iamkaan

Reputation: 1515

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

Upvotes: 8

yfsx
yfsx

Reputation: 1986

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!

Upvotes: 10

Prateek
Prateek

Reputation: 316

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

Upvotes: 0

Rajat Sawant
Rajat Sawant

Reputation: 133

Maybe this will help:

  1. Wipe the user data before launching the emulator
  2. clean the project
  3. remove dependencies which are not required....

Upvotes: 0

Jared Rummler
Jared Rummler

Reputation: 38121

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

Upvotes: 4

Sonali8890
Sonali8890

Reputation: 2005

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 :)

Upvotes: 0

KATJ Srinath
KATJ Srinath

Reputation: 970

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

Upvotes: 10

riseres
riseres

Reputation: 3172

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

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

android {
    compileSdkVersion 22
    buildToolsVersion "22"

Upvotes: 2

user4474925
user4474925

Reputation: 1

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.

Upvotes: 0

Alex Perevozchykov
Alex Perevozchykov

Reputation: 2491

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.

Upvotes: 0

binRAIN
binRAIN

Reputation: 45

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.

Upvotes: 3

Related Questions