Duplicate libraries in two different project modules

心不动则不痛 提交于 2019-12-11 10:18:33

问题


I have project with two modules. I'm using SalesforceSDK which is included as separate module and inside SalesforceSDK I have Cordova which is using okhttp. In second module I have retrofit library which is using okhttp too and when I try to build the project I get

duplicate dex files error

I tried to delete okhttp dependency from SalesforceSDK and include it from my second module but I'm getting

symbols not found error

Only thing left to do is to include okhttp as different module but before I do that I want to ask you if there is another way to fix this problem ?

EDIT:

I tried solution proposed by Aayushi but still I get errors :

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.

java.util.zip.ZipException: duplicate entry: com/squareup/okhttp/Address.class


回答1:


if you are using android studio no need to delete you can use both library

just use

android {
    defaultConfig {
     ...
      multiDexEnabled = true
  }
}

using this statement is also required

dependencies 
{
    compile 'com.android.support:multidex:1.0.0'
}



回答2:


I also have another solution for this issue. Firstly, I run this command line:

and this is result:

I saw that Paypal also use okhttp library.So, I added this line to gradlew:

compile('com.paypal.sdk:paypal-android-sdk:2.13.3')
        {
            exclude group: 'com.squareup.okhttp3', module: 'okhttp'
        }

And It aslo works fine for me.




回答3:


Take a look at jarjar, which can let you use one version of OkHttp in one place and another somewhere else.

There are other similar tools (shade), and most of ‘em will work for you.



来源:https://stackoverflow.com/questions/32945025/duplicate-libraries-in-two-different-project-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!