com.android.builder.dexing.DexArchiveMergerException: Error while merging dex

问题:

导入第三方库或者框架之后没有任何问题,在编译运行的时候出现:Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex 异常;

 

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:78)
org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
	at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:80)
	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:53)
	at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:57)
	at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:32)
Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
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.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: E:\Demo\liyu\app\build\intermediates\transforms\dexBuilder\debug\135.jar, 

原因和解决办法:

第三方框架中包含了,我目前项目中已经依赖的库或者框架;导致重复依赖或者重复导入库;总之是库重复造成的;仔细查找自己项目中之前已经依赖的库和最近依赖的库中是否也依赖了相同的库,既是最近依赖的第三方库中引入的第三方库和之前项目中依赖的库重复,有点绕;

举个我的例子:

项目中之前已经依赖了第三方库:

    //视频缓存
    implementation 'com.danikula:videocache:2.7.0'

最近引入的第三方库:

    implementation 'com.shuyu:gsyVideoPlayer-java:6.0.3'
    //根据你的需求ijk模式的so
    implementation 'com.shuyu:gsyVideoPlayer-armv7a:6.0.3'

但是最近引入的第三方库gsyVideoPlayer中也依赖了 implementation 'com.danikula:videocache:2.7.0'导致重复依赖了com.danikula:videocache:2.7.0第三库;

你可能感兴趣的:(常见问题)