简体   繁体   中英

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)

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:

: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? Thanks

It looks some of your library projects haven't defined their Schemas as library modules. If they do not, they will also create the file DefaultRealmModule which is why you get the conflict in the app project.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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