简体   繁体   English

如何在同一应用程序项目中多次将一个库模块包含到多个库模块中?

[英]How to include a library module multiple times into multiple library modules in the same app project?

I have a project structure as: 我有一个项目结构为:
- app module -应用模块
- multiple library modules.. -多个库模块。
- ... -...
- common library module (commonlib) consumed by the library modules above^ (has realm (compile 'io.realm:realm-android:0.82.2') included as dependency) -上面的库模块消耗的公共库模块(commonlib)^(具有领域(编译为io.realm:realm-android:0.82.2'作为依赖项)

now the commonlib is included as dependency in many modules and when I tried to run the project then I got the multiple dex files found error: 现在commonlib作为依赖项包含在许多模块中,当我尝试运行该项目时,我发现了多个dex文件错误:

:app:preDexDebug UP-TO-DATE
:app:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lio/realm/DefaultRealmModule;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/home/user/java/jdk1.7.0_75/bin/java'' finished with non-zero exit value 2

Can anyone help me in how I can include the realm library but at the same time include it and the commonlib module in all the dependent modules as well? 有人可以帮助我如何包含领域库,但同时又将其以及commonlib模块也包含在所有从属模块中吗? Thanks 谢谢

It looks some of your library projects haven't defined their Schemas as library modules. 看起来您的某些库项目尚未将其Schema定义为库模块。 If they do not, they will also create the file DefaultRealmModule which is why you get the conflict in the app project. 如果不这样做,他们还将创建文件DefaultRealmModule ,这就是为什么您在应用程序项目中遇到冲突的原因。

All your libraries should have a class that looks something like this: 您所有的库都应该有一个类似于以下内容的类:

@RealmModule(library = true, allClasses = true)
public class MyLibraryModule() {

}

You can read more how to include Realm in both library and app projects here: https://realm.io/docs/java/latest/#sharing-schemas 您可以在此处阅读更多有关如何在库和应用程序项目中包含Realm的信息: https : //realm.io/docs/java/latest/#sharing-schemas

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM