beshoy samy
beshoy samy

Reputation: 144

how to exclude a jar from an sdk in gradle

Hi guys I am trying to exclude a jar libs from this vungle sdk compile 'com.admost.sdk:vungle:5.3.0', the common libs that are in the sdk and I am using which causing the prob are dagger-2.7, gson-2.7 and rxjava-1.2.0 I have tried all the ways I found all did not work. the error I am getting when building the project is

Error:Execution failed for task ':app:transformClassesWithMultidexlistForStagingDebug'. java.io.IOException: Can't write [D:\Geeky\Work\UFL\UFL-Android\app\build\intermediates\multi-dex\staging\debug\componentClasses.jar] (Can't read [C:\Users\bisho.gradle\caches\transforms-1\files-1.1\vungle-5.3.0.aar\b93710fa3315099ee82cab738c995134\jars\libs\dagger-2.7.jar(;;;;;;**.class)] (Duplicate zip entry [dagger-2.7.jar:dagger/Reusable.class]))

Upvotes: 2

Views: 1709

Answers (3)

Raman Sharma
Raman Sharma

Reputation: 177

**To find duplicate dependencies or its required dependencies, you can visualize library dependencies in tree. Execute gradle command as below.**

run gradlew in Windows as below. 
**gradlew -q dependencies yourProject:dependencies --configuration compile**

The command result will show you human-readable tree hierarchy of all dependencies as below.

compile - Classpath for compiling the main sources.
+--- org.androidannotations:androidannotations-api:3.2
+--- com.android.support:support-annotations:22.1.1
+--- com.squareup:otto:1.3.6
+--- in.srain.cube:grid-view-with-header-footer:1.0.10
+--- com.nostra13.universalimageloader:universal-image-loader:1.9.3
+--- com.github.chrisbanes.photoview:library:1.2.3
+--- org.simpleframework:simple-xml:2.7.1
+--- com.google.android.gms:play-services-base:6.5.+ -> 6.5.87
+--- project :yourProject
|    +--- com.loopj.android:android-async-http:1.4.6
|    +--- org.apache.httpcomponents:httpmime:4.2.5
|    |    \--- org.apache.httpcomponents:httpcore:4.2.4
|    \--- com.google.code.gson:gson:2.3.1
+--- project :facebook
|    \--- com.android.support:appcompat-v7:22.1.1
|         \--- com.android.support:support-v4:22.1.1
|              \--- com.android.support:support-annotations:22.1.1 -> 22.2.0

You can see overriden dependencies and decide in mind which ones should be avoided. 
In above example, last line com.android.support:support-annotations presents overriden from 22.1.1 to 22.2.0 internally.
**To avoid duplicates**,you can add exclude clauses in each project build.gradle file.

compile('com.github.chrisbanes.photoview:library:1.2.3') {
exclude group: 'com.android.support'
}
compile('org.simpleframework:simple-xml:2.7.1') {
    exclude module: 'stax'
    exclude module: 'stax-api'
    exclude module: 'xpp3'
}
compile('com.google.android.gms:play-services-base:6.5.+')
{
        exclude module: 'support-v4'
}

Upvotes: 1

Raman Sharma
Raman Sharma

Reputation: 177

You can build this sdk like below example:


    compile("com.github.vungle:vungle-android-sdk:5.3.0") {
            exclude group: 'com.google.dagger', module: 'dagger'
            exclude group: 'com.google.code.gson', module: 'gson'   
            exclude group: 'io.reactivex.rxjava2', module: 'rxjava'
    }

Upvotes: 1

gorp88
gorp88

Reputation: 105

Select Project instead of android in the left pane window. See the image below.

Delete the jar if not using. Remove the reference from gradle too. It should work.

enter image description here

Upvotes: 1

Related Questions