当我使用自己创建的两个Android库时,我偶然发现了这个问题:
implementation 'me.aflak.libraries:freesmsapi:1.0'
implementation 'me.aflak.libraries:fingerprint:2.5.2'
我收到以下错误:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
如果我使用stacktrace选项运行构建,则会得到以下附加信息:
Multiple dex files define Lme/aflak/libraries/BuildConfig;
因此,我有这种感觉,因为这两个库的具有相同的包名称。但是,为什么Google的某些库(例如Firebase)具有相同的包名称,并且一切正常?
您知道如何修复我的库,以便可以在同一个项目中包括其中的几个库吗?或者如何使用gradle修复此特定错误?
谢谢 !
附言我已经尝试过
multiDexEnabled true
,在我的情况下不起作用。
最佳答案
So I have the feeling this is happening because the two libraries have the same package name.
你是对的。真正的原因是同一Java包中的两个
BuildConfig
类。这是因为具有相同的程序包名称。But then how it comes that some of Google's libraries (e.g. Firebase) have the same package name, and everything goes right ?
它们可能没有相同的程序包名称(在 list 的根
package
元素中定义为<manifest>
)。即使他们这样做,也不会发布BuildConfig
。Do you know how I can fix my libraries so I can include several of them in the same project ?
最简单的解决方案是更改其中一个库的软件包名称。
关于android - 无法合并dex:库具有相同的包名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49039303/