简体   繁体   English

Android Studio 3.4多个dex文件定义

[英]Android Studio 3.4 Multiple dex files define

I am using two different libraries, but they both have same base(webrtc). 我正在使用两个不同的库,但是它们都具有相同的base(webrtc)。 Because of which there is a duplicity in many classes. 因此,许多班级都有重复。 Therefore, android studio is not letting me create an apk. 因此,android studio不允许我创建apk。

I tried below solution which isn't working. 我尝试了下面的解决方案,这是行不通的。

dexOptions {
    preDexLibraries = false
}

Also, I have multiDexEnabled true in build.gradle file. 另外,我在build.gradle文件中具有multiDexEnabled true

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;

It's not a multi dex issue (although it says multiple dex files define X). 不是一个多dex问题 (尽管它说多个dex文件定义了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. 根据错误,在多个地方存在一个类org.webrtc.NetworkMonitor

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. 一种可能导致重复的情况是,两个库都包含一个或多个库,这些库具有dex maker无法决定使用哪个库的相同类。 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. 假设我已经制作了一个自定义的RxJava库,并且也有一个使用RxJava的库。
When syncing Gradle, this will cause duplication. 同步Gradle时,这将导致重复。 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. 为了解决这个问题,我可以排除该库使用的RxJava,因此它不会包含在classPath中,并且可以使用我的RxJava,而不会出现重复问题。

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) 这些意味着在依赖关系树中不要包括来自工作管理器库的io.reactivex.rxjava2:rxjava (因此您将自己添加一个)

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. 因此, 您可以从一个库中排除该库 ,以便另一个将其添加, 也可以从两个库中排除并自己添加该库。

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

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