android - 无法合并dex:库具有相同的包名称

标签 android gradle

当我使用自己创建的两个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/

相关文章:

java - gradle 类转换异常 : cannot cast to 'java.lang.iterable'

java - 如何通过gradle在特定文件夹中运行jUnit测试?

gradle - 在gradle中使用插件

android - 如何防止希伯来语和阿拉伯语的自动从右到左文本方向?

android - 插入 sqlite 数据库时出错

android - 工具栏上的标题文本对齐方式

android - Gradle 无法解析 com.google.android.gms :play-services-auth:11. 6.0

java - 当键盘被调用时删除 "Persistent Footer Button"- Material Design

javascript - 找不到com.android.tools.build:graddle-链接返回404

java - 如何从JAR文件的 `lib`子目录加载DLL?