Reputation: 22556
I am all of a sudden getting the following issue when I try to build my application:
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_51\bin\java.exe'' finished with non-zero exit value 2'
From reading other threads it has something to do with having more than 65k methods. however My app is no where near that many, it is still a small app. Im not sure if that includes additional libraries included in the gradle file.
here is my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "com.domain.app"
minSdkVersion 14
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile files('libs/jasypt-1.9.2.jar')
apply plugin: 'com.google.gms.google-services'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.google.code.gson:gson:2.3'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'me.dm7.barcodescanner:zbar:1.6.3'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.mobsandgeeks:android-saripaar:2.0.3'
compile 'com.github.satyan:sugar:1.3.1'
compile 'uk.co.ribot:easyadapter:1.5.0@aar'
compile 'com.android.support:design:23.1.0'
}
How can I determine If I am reaching this limit, If so is there a way to see which included library is so large? Also what are the drawbacks to enabling multiDexEnabled true
?
If I must be honest I would rather not enable multiDex and this application should not be this large. I would rather fix the source of the problem.
Upvotes: 0
Views: 888
Reputation: 1992
add this to your build grandle
android {
.....
multiDexEnabled true
}
and add multidex to your dependencies and try to build again
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
EDIT : add in your manifest the mutltidex app :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
EDIT 2 : OR, if you have a class who extends Application, add MultiDex.install(this)
in the attachBaseContext()
of your class (override it if not exist)
Upvotes: 1
Reputation: 75788
Remove this at first
apply plugin: 'com.google.gms.google-services'
Actually you already call compile 'com.google.android.gms:play-services:8.1.0'
.So don't need to call again .
Then Clean and Rebuild
Finally
dependencies {
compile files('libs/jasypt-1.9.2.jar')
compile 'com.android.support:support-v4:23.1.0'
compile 'com.google.code.gson:gson:2.3'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'me.dm7.barcodescanner:zbar:1.6.3'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.mobsandgeeks:android-saripaar:2.0.3'
compile 'com.github.satyan:sugar:1.3.1'
compile 'uk.co.ribot:easyadapter:1.5.0@aar'
compile 'com.android.support:design:23.1.0'
}
Edit 1
call multiDexEnabled true
Looks
defaultConfig {
applicationId "com.domain.app"
minSdkVersion 14
targetSdkVersion 23
multiDexEnabled true
}
And add this
compile 'com.android.support:multidex:1.0.1'
Upvotes: 0
Reputation: 1521
This eror happens because you have more than 65k methods which exceeds the capacity of dex.
You can use this lib to check if you have more than 65k methods or not https://github.com/KeepSafe/dexcount-gradle-plugin
You should had to your gradle if you have more than 65k and you need them
defaultConfig {
applicationId "com.domain.app"
minSdkVersion 14
targetSdkVersion 23
multiDexEnabled true // Add this
}
Please check the documentation here http://developer.android.com/tools/building/multidex.html
Although if you do not need all methods of play-services use what you really need, you should check this documentation to use what you only need. https://developers.google.com/android/guides/setup
Additionally, as @IntelliJAmiya said remove this
apply plugin: 'com.google.gms.google-services'
because is duplicated, you are already using
'com.google.android.gms:play-services:8.1.0'
Upvotes: 1