Reputation: 559
To build apk with gradle, error in console as following:
if make minifyEnabled = false, error disappear. It looks like there are duplicated packages.
:app:collectDebugMultiDexComponents
:app:transformClassesWithMultidexlistForDebug
ProGuard, version 5.2.1
Reading program jar [<My_Android_Project>/app/build/intermediates/transforms/proguard/debug/jars/3/1f/main.jar]
Reading library jar [<My_Android_SDK>/build-tools/23.0.2/lib/shrinkedAndroid.jar]
Preparing output jar [<My_Android_Project>/app/build/intermediates/multi-dex/debug/componentClasses.jar]
Copying resources from program jar [<My_Android_Project>/app/build/intermediates/transforms/proguard/debug/jars/3/1f/main.jar]
:app:transformClassesWithDexForDebug
Error:Uncaught translation error: com.android.dex.util.ExceptionWithContext: name already added: string{"a"}
Error:Uncaught translation error: com.android.dex.util.ExceptionWithContext: name already added: string{"a"}
Error:Uncaught translation error: com.android.dex.util.ExceptionWithContext: name already added: string{"a"}
Error:Uncaught translation error: com.android.dex.util.ExceptionWithContext: name already added: string{"a"}
Error:Uncaught translation error: com.android.dex.util.ExceptionWithContext: name already added: string{"a"}
Error:Uncaught translation error: com.android.dex.util.ExceptionWithContext: name already added: string{"a"}
Error:Uncaught translation error: com.android.dex.util.ExceptionWithContext: name already added: string{"a"}
Error:Uncaught translation error: com.android.dex.util.ExceptionWithContext: name already added: string{"a"}
Error:Uncaught translation error: com.android.dex.util.ExceptionWithContext: name already added: string{"a"}
Error:Error converting bytecode to dex:
Cause: java.lang.RuntimeException: Translation has been interrupted
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.
ExecException: Process 'command <My_JDK_PATH>/bin/java'' finished with non-zero exit value 2
build.gradle as following:
......
buildTypes {
debug {
minifyEnabled true
zipAlignEnabled false
shrinkResources false
proguardFiles 'proguard_legacy.cfg'
signingConfig signingConfigs.debug
}
release {
minifyEnabled true
zipAlignEnabled true
shrinkResources true
proguardFiles 'proguard_legacy.cfg'
signingConfig signingConfigs.release
}
}
.....
......
def dagger_version = '2.0.2'
def okhttp_version = '3.2.0'
def butterknife_version = '7.0.0'
def retrofit_version = '2.0.1'
def rxandroid_version = '1.1.0'
def rxjava_version = '1.1.0'
dependencies {
compile project(':explorer_sdk')
//multidex
compile 'com.android.support:multidex:1.0.0'
//facebook
compile 'com.facebook.android:facebook-android-sdk:4.+'
//dependency independent: dagger2/butterknife
compile "com.google.dagger:dagger:$dagger_version"
apt "com.google.dagger:dagger-compiler:$dagger_version"
compile "com.jakewharton:butterknife:$butterknife_version"
//rxjava/rxandroid
compile "io.reactivex:rxandroid:$rxandroid_version"
compile "io.reactivex:rxjava:$rxjava_version"
//retrofit2
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version"
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
compile "com.squareup.retrofit2:converter-jackson:$retrofit_version"
compile ("com.squareup.retrofit2:converter-simplexml:$retrofit_version") {
exclude module: 'stax-api'
exclude module: 'stax:stax'
exclude module: 'xpp3:xpp3'
}
//picasso
compile 'com.squareup.picasso:picasso:2.5.2'
//support
compile 'com.android.support:cardview-v7:23.+'
compile 'com.android.support:recyclerview-v7:23.+'
//annotation
provided 'javax.annotation:jsr250-api:1.0'
compile files('libs/ant.jar')
compile files('libs/defake.jar')
compile files('libs/HwID_OpenSDK_V3.0.01.07-R9156.jar')
compile files('libs/libammsdk_2015.2.5.jar')
compile files('libs/mta-sdk-1.6.2.jar')
compile files('libs/mtll_sdk_v115_20160226133400.jar')
compile files('libs/open_sdk_v2.9.1.jar')
compile files('libs/passportSDK_V1.4.jar')
compile files('libs/weibosdk_V3.1.jar')
compile files('libs/weibosdkcore_V3.1.jar')
//line-sdk
compile files('libs/line-android-sdk-3.1.19.jar')
}
.....
By the way, how to check which package is duplicated?
Upvotes: 5
Views: 4670
Reputation: 25310
Try to add below gradle options in your build.gradle. By adding below options, you can enable MultiDex support and incremental dex support.
...
defaultConfig {
...
multiDexEnabled true // Enabling multidex support.
}
...
dexOptions {
//you can speed up your builds by turning on incremental dexing
incremental = true;
//you can specify the heap size for the dex process
javaMaxHeapSize "4g"
}
In your app extends the Application
class, you can override the attachBaseContext()
method and call MultiDex.install(this)
to enable multidex.
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Also you can see below related question links on stackoverflow:
Android java.exe finished with non-zero exit value 1
See Building Apps with Over 65K Methods
Upvotes: 3
Reputation: 559
Finally, I found "compile "com.squareup.retrofit2:converter-jackson:$retrofit_version"" lead to the build error.
With "gradle app:dependencies", we can see converter-jackson depends on fasterxml. So add following to proguard file, it works!!!
-keep class com.fasterxml.** { *; }
-dontwarn com.fasterxml.**
How can I locate the exact dependency package(I mean com.squareup.retrofit2:converter-jackson) ? I just exclude the dependencies one by one. It took me several hours :-(
If anyone has a better way of locating the dependency package, pls tell me.
Upvotes: 0
Reputation: 33438
How to check which package is duplicated?
Add the following to your proguard_legacy.cfg
file.
-dontobfuscate
This will not obfuscate your code and you will see the real name of the classes or objects with the errors in your logs.
Upvotes: 2
Reputation: 4144
You are using a custom ProGuard setting file for obfuscation/minification, called: proguard_legacy.cfg
It is quite likely that this file contains some rules which are no longer compatible with DEX processing. It is recommended to use the default ProGuard configuration file from the SDK which is provided by Google and guaranteed to be working with DEX processing.
Either you can turn off minification all-together as you have found out already (minifyEnabled false
) or you might give a try and use the provided default ProGuard configuration. For the latter change this line in your gradle file:
proguardFiles 'proguard_legacy.cfg'
to
proguardFiles getDefaultProguardFile('proguard-android.txt')
There is another config file in the SDK, called 'proguard-android-optimize.txt', but that is a bit more aggressive on how your binary is changed, so it might not work at all.
You can add more relaxed or stricter rules in addition to the standard rules by adding these into a new ProGuard configuration and list it next to the default rules in the gradle file, like:
proguardFiles getDefaultProguardFile('proguard-android.txt'),'my_proguard_rules.pro'
Any rules from the second file will be added on the top of the rules from the first one. (Often by overriding the behaviour of certain rules.)
Please be aware: using default ProGuard rules might change your code in a way which might introduce problems (e.g. methods or classes are renamed or removed completely). There can be specific rules in your custom config file regarding what must be kept unchanged. Without having a look at the file it is hard to tell how to adjust your ProGuard configuration.
It is also possible that some security-related properties of your app change with changing the ProGuard rules, so if your project has security-related considerations then do penetration/security review of the app after the change.
Upvotes: 1
Reputation: 25
I spent quite a few hours going through and checking the dependency tree, removing duplicates. For example, I use a FastScrollRecylerView libary therefore I didnt need to compile the com.android.support version of reyclerview.
gradle app:dependencies
I also carefully constructed my proguard rules on a per library basis, searching for common configs, etc. I got it working though!
Upvotes: 1
Reputation: 1291
make minifyEnabled false
for debug in your build.gradle
file.
Upvotes: -1