0

I am using two different libraries, but they both have same base(webrtc). Because of which there is a duplicity in many classes. Therefore, android studio is not letting me create an apk.

I tried below solution which isn't working.

dexOptions {
    preDexLibraries = false
}

Also, I have multiDexEnabled true in build.gradle file.

Can anyone please provide a solution to the issue?

EDIT: Here is the error that I am getting.

AGPBI: {"kind":"error","text":"\tat java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)","sources":[{}]}
:app:transformDexArchiveWithDexMergerForBonumHealthDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithDexMergerForBonumHealthDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lorg/webrtc/NetworkMonitor;
Arshdeep_somal
  • 206
  • 1
  • 13

2 Answers2

0

try the solution provided in the link below

https://medium.com/@nhancv/android-deal-with-multidex-fix-java-lang-noclassdeffounderror-8daf4d2135af

afhamu
  • 930
  • 11
  • 17
0

It's not a multi dex issue (although it says multiple dex files define X).

It's because you have duplication in your dependencies. According to error, there's a class org.webrtc.NetworkMonitor that exists in more than one place.

Checkout your code and see why it's been defined again. Any libraries causing this?

You can search around all the libraries you have added for this class to find the source of the problem.

One case that might cause duplication is that both libraries include one or more libraries that have the same classes which dex maker can not decide which one to use. In this situation, you can use excluding the dependency of one library.

Assume I have made a custom RxJava library, and also have a library that uses RxJava.
When syncing Gradle, this will cause duplication. To resolve this I can exclude the RxJava used by that library, so it will not be included to classPath and I can use mine with no duplication issue.

implementation("android.arch.work:work-rxjava2:${versions.workManager}")
  { 
     exclude group: 'io.reactivex.rxjava2', module: 'rxjava'
  }

These means don't include io.reactivex.rxjava2:rxjava from work manager library, in the dependency tree (So you will add one yourself)

So you can exclude that library from one of those libraries, so the other one will add it, or you can exclude from both of them and add that library yourself.

Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117
  • Yes. I am using 2 different libraries. Both pointing to same class. I cannot edit those libraries. – Arshdeep_somal Aug 03 '19 at 10:44
  • I have not tested this: but see if this works for you: https://stackoverflow.com/a/38886815/6678991 – Mahdi-Malv Aug 03 '19 at 10:54
  • Can't you use another library to resolve duplication? And one more question: Are these classes bundled to libraries? Or they use them as libraries? I mean are they using other libraries that cause duplication? – Mahdi-Malv Aug 03 '19 at 11:39
  • 1: I can't use other library. 2: Yes. Both libraries are using one same library, that is why there is duplication of classes. – Arshdeep_somal Aug 03 '19 at 13:45
  • Well, sorry. I can't help you with your issue. – Mahdi-Malv Aug 04 '19 at 12:25