Error Gradle when generate apk in Android Studio: Exception parsing classes - android

I have a problem when I generate signed Apk file in Android studio. I get a messages below:
Error:Error converting bytecode to dex:
Cause: java.lang.RuntimeException: Exception parsing classes
Error:1 error; aborting
:app:transformClassesWithDexForRelease FAILED
Error:Execution failed for task ':app:transformClassesWithDexForRelease'.
> 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 'C:\Program Files\Java\jdk1.7.0_67\bin\java.exe'' finished with non-zero exit value 1
I use proguard in build gradle:
classpath 'com.android.tools.build:gradle:2.1.0'
I was searching through many existing answers, but it's not worked.
I refer this topic, but i can not find anything like this.
When try to use gradlew assembleRelease, I find the message:
Cause: java.lang.RuntimeException: Exception parsing classes
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
at com.android.dx.command.dexer.Main.processClass(Main.java:761)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:727)
at com.android.dx.command.dexer.Main.access$1200(Main.java:87)
at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1655)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:681)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:578)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:315)
at com.android.dx.command.dexer.Main.run(Main.java:286)
at com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:52)
at com.android.builder.core.AndroidBuilder$2.call(AndroidBuilder.java:1511)
at com.android.builder.core.AndroidBuilder$2.call(AndroidBuilder.java:1507)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.dx.cf.iface.ParseException: name already added: string{"a"}
at com.android.dx.cf.direct.AttributeListParser.parse(AttributeListParser.java:156)
at com.android.dx.cf.direct.AttributeListParser.parseIfNecessary(AttributeListParser.java:115)
at com.android.dx.cf.direct.AttributeListParser.getEndOffset(AttributeListParser.java:96)
at com.android.dx.cf.direct.MemberListParser.parse(MemberListParser.java:213)
at com.android.dx.cf.direct.MemberListParser.parseIfNecessary(MemberListParser.java:108)
at com.android.dx.cf.direct.FieldListParser.getList(FieldListParser.java:54)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:536)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.parseClass(Main.java:773)
at com.android.dx.command.dexer.Main.access$1600(Main.java:87)
at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1694)
at com.android.dx.command.dexer.Main.processClass(Main.java:758)
... 17 more
Caused by: java.lang.IllegalArgumentException: name already added: string{"a"}
at com.android.dx.rop.annotation.Annotation.add(Annotation.java:208)
at com.android.dx.cf.direct.AnnotationParser.parseAnnotation(AnnotationParser.java:264)
at com.android.dx.cf.direct.AnnotationParser.parseAnnotations(AnnotationParser.java:223)
at com.android.dx.cf.direct.AnnotationParser.parseAnnotationAttribute(AnnotationParser.java:152)
at com.android.dx.cf.direct.StdAttributeFactory.runtimeVisibleAnnotations(StdAttributeFactory.java:632)
at com.android.dx.cf.direct.AnnotationParser.parseAnnotations(AnnotationPa
at com.android.dx.cf.direct.AnnotationParser.parseAnnotationAttribute(Anno
at com.android.dx.cf.direct.StdAttributeFactory.runtimeVisibleAnnotations(
at com.android.dx.cf.direct.StdAttributeFactory.parse0(StdAttributeFactory
at com.android.dx.cf.direct.AttributeFactory.parse(AttributeFactory.java:9
at com.android.dx.cf.direct.AttributeListParser.parse(AttributeListParser.
... 30 more
1 error; aborting
:app:transformClassesWithDexForRelease FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.proce
s.ProcessException: Return code 1 for dex process
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug op
BUILD FAILED
I tried create new project and copy all gradle, proguard-pro and it build ok.
I don't know why?
What can be other possible solution please ?

Related

Phonegap Build Error: Execution failed for task ':transformClassesWithDexForRelease'

I'm having BUILD FAILED everytime I try to build using phonegap build android --release. Here's what I get by adding --verbose,
BUILD FAILED
Total time: 5.791 secs
Command finished with error code 1: cmd /s /c ""D:\Phonegap Projects\Project - GAMEHOBEY\GameHobe-final\platforms\android\gradlew.bat" cdvBuildRelease -b "D:\Phonegap Projects\Project - GAMEHOBEY\GameHobe-final\platforms\android\build.gradle" -Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx2048m -Pandroid.useDeprecatedNdk=true"
(node:3344) UnhandledPromiseRejectionWarning: Error: cmd: Command failed with exit code 1 Error output:
Dex: Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
at com.android.dx.command.dexer.Main.processClass(Main.java:775)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:741)
at com.android.dx.command.dexer.Main.access$1200(Main.java:88)
at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1683)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:695)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:592)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:321)
at com.android.dx.command.dexer.Main.run(Main.java:292)
at com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:54)
at com.android.builder.core.DexByteCodeConverter.lambda$dexInProcess$0(DexByteCodeConverter.java:173)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:476)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.parseClass(Main.java:787)
at com.android.dx.command.dexer.Main.access$1600(Main.java:88)
at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1722)
at com.android.dx.command.dexer.Main.processClass(Main.java:773)
... 16 more
1 error; aborting
I'm not sure how can I fix this.

Build Failing with Program type already present: android.net.http.SslCertificate

My build is failing with the following stack trace. I have been searching for this for over two hours but to no avail. Can anyone suggest what this error is or why it's happening?
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list.
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
...
Caused by: com.android.build.api.transform.TransformException: Error while generating the main dex list.
at com.android.build.gradle.internal.transforms.D8MainDexListTransform.transform(D8MainDexListTransform.kt:127)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:221)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:217)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
... 41 more
Caused by: com.android.builder.multidex.D8MainDexList$MainDexListException: com.android.tools.r8.errors.CompilationError: Program type already present: android.net.http.SslCertificate
at com.android.builder.multidex.D8MainDexList.generate(D8MainDexList.java:87)
at com.android.build.gradle.internal.transforms.D8MainDexListTransform.transform(D8MainDexListTransform.kt:114)
... 44 more
Caused by: com.android.tools.r8.errors.CompilationError: Program type already present: android.net.http.SslCertificate
at com.android.tools.r8.utils.ProgramClassCollection.resolveClassConflictImpl(ProgramClassCollection.java:64)
at com.android.tools.r8.utils.ProgramClassCollection.lambda$create$0(ProgramClassCollection.java:25)
at com.android.tools.r8.utils.ProgramClassCollection.create(ProgramClassCollection.java:24)
at com.android.tools.r8.graph.LazyLoadedDexApplication$Builder.build(LazyLoadedDexApplication.java:121)
at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:122)
at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:86)
at com.android.tools.r8.GenerateMainDexList.run(GenerateMainDexList.java:36)
at com.android.tools.r8.GenerateMainDexList.run(GenerateMainDexList.java:95)
at com.android.builder.multidex.D8MainDexList.generate(D8MainDexList.java:83)
... 45 more

D8 DexMergerTransform: flaky android builds on gitlab-ci

Since several days, I see flaky builds on my GitLab CI system.
Sometimes the build fails with this error:
Caused by: com.android.build.api.transform.TransformException: java.lang.IllegalArgumentException
at com.android.build.gradle.internal.transforms.DexMergerTransform.transform(DexMergerTransform.java:230)
When I then retry the build once or twice it works.
I know, this may be difficult to answer, so please add some comments, what I could try or which additional info you would need (unfortunately the project is not open-source): all comments/ideas are welcome.
Here are some thoughts that I have in mind:
maybe this is caused by insufficient memory (it's a quite large multi-module build)
maybe a timing issue of the build
maybe an error in the D8 Dexer
some more info:
the build is not doing any fancy stuff (android UI tests, etc.).
It just executes ./gradlew assembleDebug
com.android.tools.build:gradle 3.0.1
CompileSdkVersion: 26
Here are some relevant parts of the build-log:
> com.android.build.api.transform.TransformException: java.lang.IllegalArgumentException
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':m10_android_apk:transformDexArchiveWithDexMergerForRelease'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
Caused by: java.lang.RuntimeException: com.android.build.api.transform.TransformException: java.lang.IllegalArgumentException
at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:55)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104)
at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:213)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
Caused by: com.android.build.api.transform.TransformException: java.lang.IllegalArgumentException
at com.android.build.gradle.internal.transforms.DexMergerTransform.transform(DexMergerTransform.java:230)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:222)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:218)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
... 116 more
Caused by: java.lang.IllegalArgumentException
at com.android.tools.r8.utils.ThreadUtils.getExecutorService(ThreadUtils.java:40)
at com.android.tools.r8.D8.runForTesting(D8.java:150)
at com.android.tools.r8.D8.run(D8.java:71)
at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:73)
at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:97)
at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:35)

Auth0 gradle dependency error

I am trying to work with Auth0 in my project and when I try to include it in the build.gradle file I get an error. I've tried adding the following:
compile 'com.auth0.android:auth0:1.10.0'
and
compile 'com.auth0.android:auth0:1.+'
I get the following error:
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed with multiple errors, see logs
I ran gradlew build --stacktrace and got this:
14:31:51.285 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
14:31:51.285 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':app:processDebugManifest'.
14:31:51.285 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Manifest merger failed with multiple errors, see logs
14:31:51.285 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
14:31:51.285 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try:
14:31:51.285 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --stacktrace option to get the stack trace.
14:31:51.285 [LIFECYCLE] [org.gradle.internal.buildevents.BuildResultLogger]
14:31:51.286 [LIFECYCLE] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED
14:31:51.286 [LIFECYCLE] [org.gradle.internal.buildevents.BuildResultLogger]
14:31:51.286 [LIFECYCLE] [org.gradle.internal.buildevents.BuildResultLogger] Total time: 3.378 secs
What am I doing wrong?
Update
Opened AndroidManifest.xml and found this message in the Merged Manifest
Merging Errors: Error: Attribute data#host at AndroidManifest.xml requires a placeholder substitution but no value for <auth0Domain> is provided. app main manifest (this file) Error: Attribute data#scheme at AndroidManifest.xml requires a placeholder substitution but no value for <auth0Scheme> is provided. app main manifest (this file)
Answering my own question here:
The merged manifest had the error
Attribute data#host at AndroidManifest.xml requires a placeholder substitution but no value for <auth0Domain> is provided. app main manifest (this file) Error: Attribute data#scheme at AndroidManifest.xml requires a placeholder substitution but no value for <auth0Scheme> is provided. app main manifest (this file)
Basically saying that auth0Domain and auth0Scheme needed values declared.
I needed to enter the line
manifestPlaceholders = [auth0Domain: "#string/com_auth0_domain", auth0Scheme: "demo"]
in the build.gradle file and then it compile just fine.
Basically follow through instructions before deciding that you're stuck, those instructions were here.

How to level Maven dependencies in Android Studio

I have tried to add a library (odata4j) in Android Studio 1.1.0.
I used the Project Structure:
When Gradle started to sync, it gave me this error:
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find org.eclipse.persistence:eclipselink:2.1.2.
Searched in the following locations:
https://jcenter.bintray.com/org/eclipse/persistence/eclipselink/2.1.2/eclipselink-2.1.2.pom
https://jcenter.bintray.com/org/eclipse/persistence/eclipselink/2.1.2/eclipselink-2.1.2.jar
file:/C:/Users/Nestor/AppData/Local/Android/sdk/extras/android/m2repository/org/eclipse/persistence/eclipselink/2.1.2/eclipselink-2.1.2.pom
file:/C:/Users/Nestor/AppData/Local/Android/sdk/extras/android/m2repository/org/eclipse/persistence/eclipselink/2.1.2/eclipselink-2.1.2.jar
file:/C:/Users/Nestor/AppData/Local/Android/sdk/extras/google/m2repository/org/eclipse/persistence/eclipselink/2.1.2/eclipselink-2.1.2.pom
file:/C:/Users/Nestor/AppData/Local/Android/sdk/extras/google/m2repository/org/eclipse/persistence/eclipselink/2.1.2/eclipselink-2.1.2.jar
Required by:
MyApp:app:unspecified > org.odata4j:odata4j-dist:0.7.0 > org.odata4j:odata4j-core:0.7.0
So, to take care of it, I searched for eclipselink in the library dependency selector:
After I added it, Gradle could sync but on compile, I get another error:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:704)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access$300(Main.java:83)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
...while parsing org/eclipse/persistence/internal/indirection/jdk8/IndirectCollectionsProvider.class
1 error; aborting
Error:Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0\bin\java.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
It seems, eclipselink uses Java 8 so it can't work together with my Java 7 Android application.
What should I do to make this work?

Categories

Resources