question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gradle error when building

See original GitHub issue

I’m trying to test Sonar with android, I created a new application with android studio, and added the dependency to the build.gradle

dependencies {
    // ...
    debugImplementation 'com.facebook.sonar:sonar:0.0.1'
}

When I try to build the app, I get the following error:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
	at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
	at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
	at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
	at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
	at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
	at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
	at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
	at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
	at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/0.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/62.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/90.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/96.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/97.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/98.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/99.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/100.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/101.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/102.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/103.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/104.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/105.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/106.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/107.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/108.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/109.jar
	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:212)
	at sun.reflect.GeneratedMethodAccessor465.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
	at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:46)
	at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
	at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
	... 32 more
Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/0.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/62.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/90.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/96.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/97.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/98.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/99.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/100.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/101.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/102.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/103.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/104.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/105.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/106.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/107.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/108.jar, /Users/rigor789/Code/SonarTest/app/build/intermediates/transforms/dexBuilder/debug/109.jar
	at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:124)
	at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:109)
	at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:101)
	at com.android.build.gradle.internal.transforms.ExternalLibsMergerTransform.transform(ExternalLibsMergerTransform.kt:123)
	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)
	... 47 more
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
	at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:76)
	at com.android.tools.r8.utils.ExceptionUtils.withD8CompilationHandler(ExceptionUtils.java:45)
	at com.android.tools.r8.D8.run(D8.java:67)
	at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:107)
	... 52 more
Caused by: com.android.tools.r8.utils.AbortException
	at com.android.tools.r8.utils.Reporter.failIfPendingErrors(Reporter.java:77)
	at com.android.tools.r8.utils.Reporter.fatalError(Reporter.java:58)
	at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:67)
	... 55 more

In the Android Issues section this error appears as well:

Program type already present: android.support.v4.app.BackStackState$1
Message{kind=ERROR, text=Program type already present: android.support.v4.app.BackStackState$1, sources=[Unknown source file], tool name=Optional.of(D8)}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:34
  • Comments:29 (15 by maintainers)

github_iconTop GitHub Comments

16reactions
friederbluemlecommented, Jun 12, 2018

There is definitely a packaging problem with version 0.0.1 of the library. It includes all class files of the dependencies (including the support library, Guava files, OkHttp, …):

The exclude group statements for debugImplementation suggested above won’t work in this case. They only work for dependencies that are declared in the pom file (sonar-0.0.1 does not declare any dependencies there - they are all bundled inside of the aar).

The only way I could get it to work is to manually extract the aar file (and the contained classes.jar file), repackage them, then directly reference them in my build.gradle file.

It went something like this:

mkdir -p ~/tmp/sonar-0.0.1
cp ~/.gradle/caches/modules-2/files-2.1/com.facebook.sonar/de84b64d6ab7a9b71e80875f5fb6cabf040eb06/sonar-0.0.1.aar ~/tmp/sonar-0.0.1/
cd ~/tmp/sonar-0.0.1
unzip sonar-0.0.1.aar -d aar-0.0.1
cp aar-0.0.1/classes.jar .
unzip classes.jar -d classes-0.0.1

# Now delete all the unwanted packaged class files, e.g.
rm -rf classes-0.0.1/android classes-0.0.1/javax classes-0.0.1/jsr-305

# Repackage classes file
jar cvf classes.jar -C classes-0.0.1/ .

# Repackage aar file
cp classes.jar aar-0.0.1/
jar cvf sonar-0.0.1-LOCAL.aar -C aar-0.0.1/ .

# Now use the new aar file directly:

cp sonar-0.0.1-LOCAL.aar ~/path/to/android-project/app/libs

# build.gradle

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

# app/build.gradle

dependencies {
    // ...
    debugImplementation(name: 'sonar-0.0.1-LOCAL', ext: 'aar')
}
12reactions
kypelicommented, Jun 20, 2018

I have a hard time understanding how the Sonar library in its current form would work with any external real application out there. I am facing similar issue but with OkHttp3

Program type already present: okhttp3.Authenticator$1 Message{kind=ERROR, text=Program type already present: okhttp3.Authenticator$1, sources=[Unknown source file], tool name=Optional.of(D8)}

And since OkHttp3 is pretty common [sarcasm], how on earth can Sonar in its current form work in real production apps? So this library has to be slimmed down and not ship with all these baked in dependencies.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gradle build fails - java - Stack Overflow
When building A , I get the following error: FAILURE: Build failed with an exception. * What went wrong: Could not determine the...
Read more >
Different Ways to fix "Error running android: Gradle project ...
Method 1: Restarting your project using Invalidate Caches and Restart option ; Method 2: Sync your project with Gradle files ; Method 3:...
Read more >
How do I solve an Android Studio build Gradle error? - Quora
Try running Build > Clean and/or Build Rebuild. The should reset the indexes. · Alternatively ,you can try to reopen the project… OR...
Read more >
How to solve gradle build failed error | Edureka Community
Make sure you have your jdk updated and the jars you are using are compatible. answered Dec 7, 2018 by ...
Read more >
Gradle setup and build errors - MCreator
It can happen that you get gradle errors during the setup of MCreator or even later when suddenly builds stop working. Most of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found