74

I am using Android Studio to develop this app, and today when I tried to upload it to my device to test I got a popup window saying:

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?

It gave two options, OK or Cancel. Upon hitting OK, the following message showed up in the Run tab:

DEVICE SHELL COMMAND: pm uninstall my.bundle.id
Unknown failure

The app seems to be uninstalled, the is no trace of it under Manage Applications.
I am unable to upload the app. I tried cleaning the project and rebuilding, but it didn't work.

What can I do?

Guilherme
  • 7,839
  • 9
  • 56
  • 99
  • "unknown failure" does not look helpful. Do you have rooted device? – Yuraj Aug 25 '14 at 20:33
  • Not, it is not rooted. I've reset it to factory settings, the problem persists. – Guilherme Aug 29 '14 at 13:42
  • First, try some other phone to check If It's phone or software problem. – Yuraj Aug 29 '14 at 13:55
  • I am trying to get another phone to test. Meanwhile, I tried the simulator and it does work with it. – Guilherme Aug 29 '14 at 14:17
  • @Guilherme Did you get work around? Please share with me I am also facing the same problem. Thanks – Programmer Apr 09 '15 at 15:45
  • @Programmer yes, I did. Check the answer below – Guilherme Apr 09 '15 at 15:53
  • @Guilherme Thanks for answer. But I am very new to Gradle things. As you told to enable progaurd I did. But I am getting exception while generating signed apk. The error is "Execution failed for task ':app:proguardRelease'. > java.io.FileNotFoundException: /path-to-my-app/project-name/app/proguard-rules.pro (No such file or directory) ". Can you help me in this regard? – Programmer Apr 09 '15 at 17:12

16 Answers16

79

I have also encountered this problem in Android Studio, from version 2.0 Preview 6 all the way up to 2.0 Beta 3 and none of the solutions mentioned here worked for me.

Turned up it had nothing to do with Instant Run. All I had to do was to increase the AVD's Internal Storage until the following notification disappeared. I also had to perform a data wipe after changing the values.

enter image description here

Alexandru Pele
  • 1,123
  • 7
  • 12
  • 4
    Thanks. In my case Instant Run was already disabled. I increased AVD's Internal Storage from 800 to 1600 Mb, wiped data and installed apk. – CoolMind Jun 28 '18 at 13:04
  • Correct, worked for me as I was trying to run the app for the 1st time on a TV AVD – Golan Shay Sep 26 '18 at 11:19
  • For me I had to increase the internal storage (studio managed) from 100MB to 500MB to solve this problem. – Afilu Mar 11 '19 at 10:30
  • This Worked !! Thanks – Ramya BA May 20 '19 at 02:05
  • 1
    I again got this exception on Nexus 5 API 21 emulator. Increased AVD's Internal Storage from 800 to 1600 Mb, restarted the emulator and installed apk. – CoolMind Sep 10 '20 at 09:33
  • I needed to increase the internal storage to 4 GB (which is a lot!) on my API 21 emulator before storage was no longer running out.... Which is ridiculous for API 21: after a clean install and boot there's less than 700 MB used. Also, while the device was thinking that storage space was running out, I saw random crashes every minute or so of the Play Services. That has been solved too by increasing the internal storage size. – Erik Feb 26 '21 at 12:27
28

I disabled Instant run for this project, and problem solved.

Maybe it's a bug in the instant run feature of Android studio 2.0 preview.

Instant Run is a new feature introduced in Android Studio 2.0.

ps: in case you don't find Instant run, its in:

Android Studio --> Preferences --> Build, execution, deploy --> Instant run.

or you can search for it in the preferences tab.

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
dalizhang
  • 391
  • 3
  • 3
24

Go to AVD Manager, then in the action section of your device select wipe data. This worked for me, hope it helps....

Walter Torricos
  • 381
  • 3
  • 9
  • 1
    I disabled Instant Run as suggested and the situation remained the same. I wiped the data on my AVD and it worked, like a charm. I enabled Instant Run again, and is still working. Android Studio 2.1 (from April 22, 2016). :-) – monn3t May 11 '16 at 06:30
14

This helped me for the emulator: Close Emulator. Tools > AVD Manager > Select Emulator Settings > Wipe Data > Cold Boot.. Now Install App.

Reference

Murat
  • 3,084
  • 37
  • 55
8

I discovered that the dex file was getting larger than the buffer, even though it contained less than 64k methods. Then I enabled ProGuard and it helped a lot reducing the dex file size.

THe application dex-method-counts helps a lot to debug your dex file, by checking not only the number of methods, but to what package they belong

Guilherme
  • 7,839
  • 9
  • 56
  • 99
  • 2
    Hello, I have run into the exact same problem as in this question, however this answer which is accepted does not give me a solution that I can understand. Could it be possible for you to open this answer somehow, like it is possible to solve this problem somehow without using 3rd party apps, and the ProGuard tip seems to be viable in production versions, but what will help in allowing me to debug the my app? In short, how to solve this problem which is occuring in an application that I have just started to make and is nowhere near to production? – ghoulfolk Mar 25 '15 at 11:40
  • @ghoulfolk did u get alternate solution for this issue? Please tell me I m searching from yesterday. – Programmer Apr 10 '15 at 04:06
  • hi @Programmer, yes I discovered my problem was caused by an older SDK Build Tools version (I am using Android Studio as my IDE) please refer to my answer down below for possible help.. I learned that keeping the IDE and Build Tools up-to-date and then cleaning the project seems to have solved my issue. – ghoulfolk Apr 10 '15 at 07:55
  • @ghoulfolk thank you.I am using sdk build tool 21. But still m getting this error. And this problem is coming on device 2.3.x version. – Programmer Apr 10 '15 at 07:58
  • @Guiherme I followed your answer. I found "Overall method count: 24474" in terminal. Now whats next step? Please help! – Programmer Apr 11 '15 at 10:27
8

I found out my problem was caused by old SDK Build Tools version, which was causing the Clean to fail. I upgraded my SDK Build Tools to the newest version and after that cleaning worked, and I no longer received the stale dexed jars error. Hopefully this will help someone else struggling with this issue.

ghoulfolk
  • 326
  • 7
  • 17
  • 2
    This works for me. If you ever get this error, just run the SDK manager and install build tools. Upon relaunching android studio without reinstalling them, it actually prompted me to do so, so simply restarting AS and following the prompt could work. – Riot Goes Woof Jul 01 '15 at 15:19
3

This worked for me:

In Android Studio this can be done by clicking on Build > Clean Project. SysadminTips

Gary Kerr
  • 13,650
  • 4
  • 48
  • 51
Rene Juuse
  • 575
  • 8
  • 16
3

When your dex file gets larger then buffer size( i.e. contains more than 65k methods) then this error occurs. You can avoid this error in two ways: 1.) Remove unused code with ProGuard - Configure the ProGuard settings for your app to run ProGuard and ensure you have shrinking enabled for release builds. Enabling shrinking ensures you are not shipping unused code with your APKs.

2.) You can configure your app for multidex support. Refer this link to use it: https://developer.android.com/tools/building/multidex.html

For multidex support I override this method in my application class:

@Override
protected void attachBaseContext(Context base) {
  super.attachBaseContext(base);
  MultiDex.install(this);
}

and modify my build.gradle like this:

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 21

             // Enabling multidex support.
             multiDexEnabled true
         }
}

dependencies {
    compile 'com.android.support:multidex:1.0.0'
}

Hope it helps!

EDITS: Took out the text explanation from the code.

Moïze
  • 707
  • 8
  • 16
Anupriya
  • 1,663
  • 3
  • 17
  • 28
3

In my case was because my emulator was full of apps. I saw how much space the emulator had and was almost nothing so I deleted some apps and with this my problem was resolved

Jorge Casariego
  • 21,948
  • 6
  • 90
  • 97
3

In my project I got past this by being more specific about which portions of Google Play Services I was linking with. In particular, I changed

dependencies {
    ...
    compile 'com.google.android.gms:play-services:8.4.0'
}

to

dependencies {
    ...
    compile 'com.google.android.gms:play-services-maps:8.4.0'
}

in my app module's build.gradle, since all I was really using was the maps API.

user3582891
  • 31
  • 1
  • 2
2

What i did was modified build.gradle (Module:app) file.

Initially it was

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

I changed it to

    buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

Then Rebuild and deploy !

Guilherme
  • 7,839
  • 9
  • 56
  • 99
minatverma
  • 1,090
  • 13
  • 24
2

If you're using Android studio 2.0 preview , disable the instant run .

All credit and thanks go for the life saver https://stackoverflow.com/a/34192979/1413998

Community
  • 1
  • 1
yehyatt
  • 2,295
  • 3
  • 28
  • 31
1

I have Faced this problem today, Got the solution. Saw how much space the emulator and was almost nothing so I deleted some apps and my problem was resolved.Thanks

Praveen Kumar Verma
  • 2,988
  • 2
  • 18
  • 31
0

None of answer didn't solve my problem

you should also make progaurd for debug too. just add buildtypes to your main gradle file:

buildTypes {
    debug {  // change release to debug
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
Amir Hossein Ghasemi
  • 20,623
  • 10
  • 57
  • 53
0

In my case it was caused by a file named "dictionary.txt". I just deleted it and solved the problem.

Mr.He
  • 1
  • 2
0

I have tried followings

  • increasing the RAM
  • increasing the storage of emulator
  • removing and adding emulator
  • invalidate cache and restart

but nothing work.

However, deleting the actual emulator file did trick for me.

You can find the emulator files at this location.

C:\Users\<username>\.android\avd

Thanks.

emarshah
  • 328
  • 3
  • 14