Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Exclude or add reference for JAR file hard included inside library classes.jar

I'm running into some trouble with a library I included into my project: At the beginning it was just a conflicting dependencies issue that I resolved by excluding support-v4 which is the commonly shared module.

The problem is that one of those lbsLib-release seems to have been built with a plain .jar file inside of the root project before the developer build.

By running ./gradlew app:dependencies I verified that the dependency is not referenced in the build graph.

And I found this support-v4 embedded into the classes.jar located at : app/build/intermedites/exploded-aar/MyQaaAndroid/lbsLib-release/unspecified/classes.jar/ as you can see on the picture below:

enter image description here

I can't rebuild the project myself because it is not an open-sourced lib, so there is two problem:

  1. If I add compile 'com.android.support:support-v4:18.0.+' to the build.gradle a multiple dex file error is thrown at build time so the library is referenced twice.

    UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/app/BackStackState;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)
    

    `

  2. If I remove all libs which require support-v4 it throws a missing dependencies error at the application runtime.

So I would like to know if it is possible to exclude this .jar file from the build or to make the others libs depends on the lbsLib-release embedded support-v4 .jar.

compile (project(':lbsLib-release')) {
    exclude module: 'support-v4'
}

compile ('com.sothree.slidinguppanel:library:2.0.4'){
    exclude module: 'support-v4'
}

compile('com.google.android.gms:play-services:6.5.87') {
    exclude module: 'support-v4'
}
like image 687
Glenn Sonna Avatar asked Jan 15 '15 14:01

Glenn Sonna


1 Answers

Try to use resolutionStrategy (API reference) at root build.gradle.

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
    configurations.all((Closure) {
        resolutionStrategy {
            force 'com.android.support:support-v4:21.0.2' // your version of support library
        }
    })

}
like image 117
gio Avatar answered Nov 15 '22 00:11

gio