Can't upload Android app to device (stale dexed jars)
Asked Answered
N

16

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?

Nazarius answered 25/8, 2014 at 19:49 Comment(7)
"unknown failure" does not look helpful. Do you have rooted device?Aubarta
Not, it is not rooted. I've reset it to factory settings, the problem persists.Nazarius
First, try some other phone to check If It's phone or software problem.Aubarta
I am trying to get another phone to test. Meanwhile, I tried the simulator and it does work with it.Nazarius
@Nazarius Did you get work around? Please share with me I am also facing the same problem. ThanksDarken
@Darken yes, I did. Check the answer belowNazarius
@Nazarius 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?Darken
N
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

Nazarius answered 2/9, 2014 at 12:52 Comment(5)
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?Recession
@Recession did u get alternate solution for this issue? Please tell me I m searching from yesterday.Darken
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.Recession
@Recession 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.Darken
@Guiherme I followed your answer. I found "Overall method count: 24474" in terminal. Now whats next step? Please help!Darken
T
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

Terr answered 11/2, 2016 at 11:23 Comment(6)
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.Conjurer
Correct, worked for me as I was trying to run the app for the 1st time on a TV AVDBaseburner
For me I had to increase the internal storage (studio managed) from 100MB to 500MB to solve this problem.Barrator
This Worked !! ThanksBrotherinlaw
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.Conjurer
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.Gena
T
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.

Teyde answered 10/12, 2015 at 2:59 Comment(7)
This worked for me too. I am using AS 2.0 Preview 3b.Vesicant
Same here , I went through all questions and solutions , a life saver !Blabber
This was it. But only on a certain device.Grenadines
That's a bummer. I wanted to use Instant run on the device. Oh well.Surra
For windows and linux users, there is no Preferences option. Preferences menu option is called Settings under File > SettingsHomemaking
same here with AS 2.0 Preview 5b, didn't happen with 4b.Gerontology
Thank you for that. It happened to me after upgrading from beta5 to beta6.Commutate
Q
24

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

Quoin answered 27/2, 2015 at 3:25 Comment(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). :-)Druce
E
14

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

Reference

Encomiastic answered 6/6, 2019 at 12:23 Comment(4)
Solved my problemWon
Damn, you right. I did everything besides the Cold Boot and it still didn't work. Needed to do that for it to fix the issue.Spinode
this fixed the issue!!! +1 Literally ran into this problem running in emulator in old android version for the first time.Tribade
This definitely solves the issue, should be marked as the correct answer.Disavow
N
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

Nazarius answered 2/9, 2014 at 12:52 Comment(5)
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?Recession
@Recession did u get alternate solution for this issue? Please tell me I m searching from yesterday.Darken
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.Recession
@Recession 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.Darken
@Guiherme I followed your answer. I found "Overall method count: 24474" in terminal. Now whats next step? Please help!Darken
R
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.

Recession answered 31/3, 2015 at 7:39 Comment(1)
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.Synthetic
B
3

This worked for me:

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

Barbados answered 6/3, 2015 at 13:1 Comment(0)
H
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.

Hassi answered 20/4, 2015 at 7:11 Comment(0)
I
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

Ineluctable answered 30/7, 2015 at 20:26 Comment(0)
V
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.

Validate answered 15/4, 2016 at 0:0 Comment(0)
H
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 !

Hertahertberg answered 22/12, 2014 at 15:35 Comment(1)
I Have the same problem and this solution doesn't work.Faceplate
B
2

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

All credit and thanks go for the life saver https://mcmap.net/q/269588/-can-39-t-upload-android-app-to-device-stale-dexed-jars

Blabber answered 17/12, 2015 at 9:23 Comment(0)
I
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

Inquisitorial answered 6/3, 2019 at 11:1 Comment(0)
P
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'
    }
}
Psalms answered 25/7, 2016 at 7:10 Comment(0)
B
0

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

Balsa answered 21/7, 2017 at 6:14 Comment(0)
F
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.

Frederickson answered 24/11, 2019 at 4:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.