Can't upload Android app to device (stale dexed jars)
AndroidAndroid StudioAndroid Problem Overview
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?
Android Solutions
Solution 1 - Android
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.
Solution 2 - Android
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.
Solution 3 - Android
Go to AVD Manager, then in the action section of your device select wipe data. This worked for me, hope it helps....
Solution 4 - Android
This helped me for the emulator: Close Emulator. Tools > AVD Manager > Select Emulator Settings > Wipe Data > Cold Boot.. Now Install App.
Solution 5 - Android
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
Solution 6 - Android
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.
Solution 7 - Android
This worked for me: > In Android Studio this can be done by clicking on Build > Clean > Project. SysadminTips
Solution 8 - Android
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.
Solution 9 - Android
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
Solution 10 - Android
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.
Solution 11 - Android
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 !
Solution 12 - Android
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
Solution 13 - Android
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
Solution 14 - Android
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'
}
}
Solution 15 - Android
In my case it was caused by a file named "dictionary.txt". I just deleted it and solved the problem.
Solution 16 - Android
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.