我的项目有多个模块,一个模块需要保持包名与“app”模块相同。当我编译项目并运行它运行正常,但当我尝试构建发布APK时,它显示以下错误:
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/sumit/example/BuildConfig;
Error:com.android.dex.DexException: Multiple dex files define Lcom/sumit/example/BuildConfig;
Error: at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
Error: at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
Error: at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
Error: at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Error: at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error: at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error: at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error: at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error: at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error: at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error: at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error: at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForRelease'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lcom/sumit/example/BuildConfig;
Information:BUILD FAILED in 1m 42s
我在gradle文件中启用了multidex支持,并且还在主应用程序类中包含了multidex安装功能。
只有我能想到的是,由于存在多个BuildConfig类具有相同的包名,因此其他模块将包名称共享为app模块。
有关如何解决此问题的任何帮助?我们可以解决这个问题,让两个模块共享一个包名吗?
答案 0 :(得分:1)
尝试在库模块中添加packageBuildConfig(false)
:
android{
...
packageBuildConfig(false)
}