问题
Hi I am using MultiDex in my app with Proguard. When
-dontobfuscate
line is present in the proguard rules, I am able to generate minified apk without obfuscation. But when I remove this line, to generate an obfuscated apk, from proguard rules I am getting this error in gradle console.
Here's the link to my gradle error Gradle Error. Also I have mentioned it below
AGPBI: {"kind":"error","text":"Error converting bytecode to dex:\n
Cause: java.lang.RuntimeException: Exception parsing classes","sources":[{}],"original":"UNEXPECTED TOP-LEVEL EXCEPTION:\njava.lang.RuntimeException: Exception parsing classes\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:775)\n\tat com.android.dx.command.dexer.Main.processFileBytes(Main.java:741)\n\tat com.android.dx.command.dexer.Main.access$1200(Main.java:88)\n\tat com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1683)\n\tat com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)\n\tat com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)\n\tat com.android.dx.command.dexer.Main.processOne(Main.java:695)\n\tat com.android.dx.command.dexer.Main.processAllFiles(Main.java:592)\n\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:321)\n\tat com.android.dx.command.dexer.Main.run(Main.java:292)\n\tat com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:54)\n\tat com.android.builder.core.DexByteCodeConverter.lambda$dexInProcess$0(DexByteCodeConverter.java:173)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:266)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat java.lang.Thread.run(Thread.java:745)\nCaused by: com.android.dx.cf.iface.ParseException: name already added: string{\"a\"}\n\tat com.android.dx.cf.direct.AttributeListParser.parse(AttributeListParser.java:156)\n\tat com.android.dx.cf.direct.AttributeListParser.parseIfNecessary(AttributeListParser.java:115)\n\tat com.android.dx.cf.direct.AttributeListParser.getEndOffset(AttributeListParser.java:96)\n\tat com.android.dx.cf.direct.MemberListParser.parse(MemberListParser.java:213)\n\tat com.android.dx.cf.direct.MemberListParser.parseIfNecessary(MemberListParser.java:108)\n\tat com.android.dx.cf.direct.FieldListParser.getList(FieldListParser.java:54)\n\tat com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:536)\n\tat com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)\n\tat com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)\n\tat com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)\n\tat com.android.dx.command.dexer.Main.parseClass(Main.java:787)\n\tat com.android.dx.command.dexer.Main.access$1600(Main.java:88)\n\tat com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1722)\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:773)\n\t... 16 more\nCaused by: java.lang.IllegalArgumentException: name already added: string{\"a\"}\n\tat com.android.dx.rop.annotation.Annotation.add(Annotation.java:208)\n\tat com.android.dx.cf.direct.AnnotationParser.parseAnnotation(AnnotationParser.java:264)\n\tat com.android.dx.cf.direct.AnnotationParser.parseAnnotations(AnnotationParser.java:223)\n\tat com.android.dx.cf.direct.AnnotationParser.parseAnnotationAttribute(AnnotationParser.java:152)\n\tat com.android.dx.cf.direct.StdAttributeFactory.runtimeVisibleAnnotations(StdAttributeFactory.java:633)\n\tat com.android.dx.cf.direct.StdAttributeFactory.parse0(StdAttributeFactory.java:123)\n\tat com.android.dx.cf.direct.AttributeFactory.parse(AttributeFactory.java:96)\n\tat com.android.dx.cf.direct.AttributeListParser.parse(AttributeListParser.java:142)\n\t... 29 more\n","tool":"Dex"}
AGPBI: {"kind":"error","text":"1 error; aborting","sources":[{}]}
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForRelease'.
> java.lang.UnsupportedOperationException (no error message)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
This is the code in my gradle file
defaultConfig {
resConfigs "en"
applicationId "XXXX.XXXXX"
minSdkVersion 16
targetSdkVersion 25
versionCode 50
multiDexEnabled true
versionName "1.2"
}
buildTypes {
debug {
minifyEnabled false
debuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
dexOptions {
javaMaxHeapSize "4g"
}
回答1:
add javaMaxHeapSize "4g"
inside app level build.gradle inside android tag
android{
defaultConfig {
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
}
来源:https://stackoverflow.com/questions/42483279/getting-errorexecution-failed-for-task-apptransformclasseswithmultidexlistfo