Build apk with gradle error

To build apk with gradle, error in console:

if make minifyEnabled = false, the error will disappear. It seems that there are duplicate 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 follows:

 ...... 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?

+5
source share
6 answers

Finally, I found the compilation com.squareup.retrofit2: converter-jackson: $ retrofit_version "" leads to a build error.

With "gradle app: dependencies" we see that the jackson converter is dependent on quickxml. So add the following to the proguard file, it works !!!

 -keep class com.fasterxml.** { *; } -dontwarn com.fasterxml.** 

How can I find the exact dependency package (I mean com.squareup.retrofit2: converter-jackson)? I just rule out the dependencies one by one. It took me a few hours: - (

If anyone has a better way to find the dependency package, tell me.

0
source

Try adding below gradle options to build.gradle. By adding the options below, you can enable MultiDex and 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" } 

The Application class extends in your application, 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); } 

You can also see below related question links on stackoverflow:

Error: execution completed for task ': app: transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: .. non-zero output value 3

Android java.exe finished with nonzero exit value 1

See Creating Applications with More Than 65K Methods

+3
source

How to check which package is duplicated?

Add the following to your proguard_legacy.cfg file.

  -dontobfuscate 

This will not confuse your code, and you will see the real name of the classes or objects with errors in your logs.

+2
source

I spent many hours and checked the dependency tree, removing duplicates. For example, I use the FastScrollRecylerView library, so I did not need to compile the reyclerview version for com.android.support.

 gradle app:dependencies 

I also carefully built my proguard rules based on each library, searched for common configs, etc. I worked though!

+1
source

You are using a custom ProGuard settings file for obfuscation / minimization called proguard_legacy.cfg

It is very likely that this file contains some rules that are no longer compatible with DEX processing. It is recommended that you use the default ProGuard configuration file from the SDK, which is provided by Google, and is guaranteed to work with DEX processing.

Either you can disable minimization all together, as you already know ( minifyEnabled false ), or you can try and use the default ProGuard configuration. For the latter, change this line in the gradle file:

 proguardFiles 'proguard_legacy.cfg' 

to

 proguardFiles getDefaultProguardFile('proguard-android.txt') 

There is another configuration file in the SDK called "proguard-android-optimize.txt", but it is a bit more aggressive in modifying your binary, so it may not work at all.

You can add more relaxed or stricter rules in addition to the standard rules by adding them to the new ProGuard configuration and listing them next to the standard rules in the gradle file, for example:

 proguardFiles getDefaultProguardFile('proguard-android.txt'),'my_proguard_rules.pro' 

Any rules from the second file will be added at the top of the rules from the first. (Often, overriding the behavior of certain rules.)

Pay attention . Using the default ProGuard rules can change your code in a way that can cause problems (for example, methods or classes are completely renamed or deleted). There may be certain rules in your custom configuration file as to what should be kept unchanged. Despite the file, it is difficult to determine how to configure the ProGuard.

It is also possible that some of the security-related properties of your application change as ProGuard rules change, so if your project has security concerns, then do an intrusion / security analysis of the application after the change.

+1
source

make minifyEnabled false for debugging in your build.gradle file.

-1
source

Source: https://habr.com/ru/post/1246997/


All Articles