hhg
hhg

Reputation: 687

com.android.ide.common.process.ProcessException: Multiple dex files define (...) BuildConfig

I've got a raw project using

compile            "com.library1:library1:2.0.4"
compile             "com.library2:library2:3.0.0"

whereas both library1:2.0.4 and library2:3.0.0 share the same namespace (have the same package names). Is there a clean way to let them coexist within one project without build time errors like:

Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define (...)/BuildConfig;

Upvotes: 1

Views: 156

Answers (1)

Xavier Rubio Jansana
Xavier Rubio Jansana

Reputation: 6583

What you need is Gradle Shadow plugin. I haven't used it, so I cannot give you more specific advice than pointing you to the docs, but I think that's the way to go, as some colleagues have told me that they've successfully used it for similar cases.

Notice that this process renames one of the libraries package name, and you will end up with something similar to:

  • library1 -> com.library1
  • library2 -> com.newlibrary1 (instead of com.library1 too)

So, if you rename the second library, at the end of the process (after removing old library) you will either have to disable the renaming of the second library and do a "Find in files" to change all the references to the renamed package; or leave the rename enabled forever. For me, first option will be the best.

See also this question Repackaging .jar-s in Android .aar library, though I'm not sure if it's already outdated.

Upvotes: 1

Related Questions