升级到gradle插件3.2.0时,出现错误“无法在main-dex文件中容纳请求的类”

时间:2019-04-14 03:27:51

标签: android android-gradle

我试图将我的android项目gradle版本从3.1.0升级到3.2.0,并收到有关DexArchiveMergerException的错误,同时还原回来使其工作正常。

我正在使用android studio 3.3.2,当我第一次将gradle版本更改为3.2.0时,它开始给出有关我解决的kotlin数据绑定的错误 通过从我的应用依赖项中删除这一行

kapt "com.android.databinding:compiler:3.1.0

但是现在我遇到了这个错误

Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:132)
    at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:117)
    at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:101)
    at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:36)
    at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
    ... 4 more
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
    at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:65)
    at com.android.tools.r8.utils.ExceptionUtils.withD8CompilationHandler(ExceptionUtils.java:43)
    at com.android.tools.r8.D8.run(D8.java:90)
    at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:115)
    ... 7 more
Caused by: com.android.tools.r8.utils.AbortException: Error: Cannot fit requested classes in the main-dex file (# methods: 143948 > 65536 ; # fields: 73772 > 65536)
    at com.android.tools.r8.utils.Reporter.failIfPendingErrors(Reporter.java:116)
    at com.android.tools.r8.utils.Reporter.fatalError(Reporter.java:74)
    at com.android.tools.r8.utils.Reporter.fatalError(Reporter.java:96)
    at com.android.tools.r8.dex.VirtualFile.throwIfFull(VirtualFile.java:192)
    at com.android.tools.r8.dex.VirtualFile$DistributorBase.fillForMainDexList(VirtualFile.java:317)
    at com.android.tools.r8.dex.VirtualFile$FillFilesDistributor.run(VirtualFile.java:369)
    at com.android.tools.r8.dex.ApplicationWriter.distribute(ApplicationWriter.java:178)
    at com.android.tools.r8.dex.ApplicationWriter.write(ApplicationWriter.java:199)
    at com.android.tools.r8.D8.run(D8.java:179)
    at com.android.tools.r8.D8.lambda$run$1(D8.java:93)
    at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:55)
    ... 10 more

在我的应用程序build.gradle的defaultConfig中,我已经包含了

 multiDexEnabled true

还有我的minSDk = 19,因此我还包括了独立性:

implementation "com.android.support:multidex:1.0.3"

如果我只是将gradle版本还原为3.1.0,则一切正常。如果gradle 3.2.0有任何错误,这里需要一些帮助??

0 个答案:

没有答案