Android studio gradle 编译异常 Error while merging dex archives:

最近在android studio 4.0.1 版本导入 androidcharts 这个库的时候,编译遇到报错 Error while merging dex archives:

AGPBI: {"kind":"error","text":"Type cn.limc.androidcharts.BuildConfig is defined multiple times: C:\\anson\\Android-Charts-develop\\androidcharts\\build\\.transforms\\9278aac33344f828e328877d0a8a0523\\classes\\classes.dex, C:\\anson\\Android-Charts-develop\\androidchartsdemo\\build\\intermediates\\external_libs_dex\\debug\\out\\classes.dex","sources":[{"file":"C:\\anson\\Android-Charts-develop\\androidcharts\\build\\.transforms\\9278aac33344f828e328877d0a8a0523\\classes\\classes.dex"}],"tool":"D8"}
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Type cn.limc.androidcharts.BuildConfig is defined multiple times: C:\anson\Android-Charts-develop\androidcharts\build\.transforms\9278aac33344f828e328877d0a8a0523\classes\classes.dex, C:\anson\Android-Charts-develop\androidchartsdemo\build\intermediates\external_libs_dex\debug\out\classes.dex
	at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:132)
	at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:119)
	at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:102)
	at com.android.build.gradle.internal.tasks.DexMergingTaskRunnable.run(DexMergingTask.kt:445)
	at com.android.build.gradle.internal.tasks.Workers$ActionFacade.run(Workers.kt:348)
	at org.gradle.workers.internal.AdapterWorkAction.execute(AdapterWorkAction.java:50)
	at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:47)
	at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1$1.create(NoIsolationWorkerFactory.java:65)
	at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1$1.create(NoIsolationWorkerFactory.java:61)
	at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:98)
	at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.execute(NoIsolationWorkerFactory.java:61)
	at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
	at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
	at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
	at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
	at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:56)
	at org.gradle.workers.internal.DefaultWorkerExecutor$3.call(DefaultWorkerExecutor.java:215)
	at org.gradle.workers.internal.DefaultWorkerExecutor$3.call(DefaultWorkerExecutor.java:210)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
	at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
	at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
	at java.lang.Thread.run(Thread.java:748)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
	at com.android.tools.r8.utils.O.a(:65)
	at com.android.tools.r8.D8.run(:11)
	at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:117)
	... 34 more
Caused by: com.android.tools.r8.utils.b: Error: C:\anson\Android-Charts-develop\androidcharts\build\.transforms\9278aac33344f828e328877d0a8a0523\classes\classes.dex, Type cn.limc.androidcharts.BuildConfig is defined multiple times: C:\anson\Android-Charts-develop\androidcharts\build\.transforms\9278aac33344f828e328877d0a8a0523\classes\classes.dex, C:\anson\Android-Charts-develop\androidchartsdemo\build\intermediates\external_libs_dex\debug\out\classes.dex
	at com.android.tools.r8.utils.y0.a(:21)
	at com.android.tools.r8.utils.x0.a(:30)
	at com.android.tools.r8.utils.x0.a(:10)
	at java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:1990)
	at com.android.tools.r8.utils.x0.a(:6)
	at com.android.tools.r8.graph.A0$c.a(:6)
	at com.android.tools.r8.dex.a.a(:85)
	at com.android.tools.r8.dex.a.a(:12)
	at com.android.tools.r8.D8.d(:6)
	at com.android.tools.r8.D8.b(:1)
	at com.android.tools.r8.utils.O.a(:30)
	... 36 more


Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete

Caused by: com.android.tools.r8.utils.b: Error: C:\anson\Android-Charts-develop\androidcharts\build\.transforms\9278aac33344f828e328877d0a8a0523\classes\classes.dex, Type cn.limc.androidcharts.BuildConfig is defined multiple times: C:\anson\Android-Charts-develop\androidcharts\build\.transforms\9278aac33344f828e328877d0a8a0523\classes\classes.dex, C:\anson\Android-Charts-develop\androidchartsdemo\build\intermediates\external_libs_dex\debug\out\classes.dex

折腾一番后发现 原来在旧版本的android studio 环境,build 不用配置

android{
 defaultConfig{
      // Enabling multidex support.
         multiDexEnabled true
    }
}

现在导入新环境,只需加上   multiDexEnabled true  就好

你可能感兴趣的:(android,android,studio,android,gradle,debug)