Gradle Exclude or add a reference to the JAR file contained within the classes.jar library

I am having problems with the library included in my project: At first it was a conflicting issue that I resolved by excluding support-v4 , which is a public module.

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

By running ./gradlew app:dependencies , I confirmed that the dependency is not listed in the build graph.

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

enter image description here

I cannot rebuild the project myself because it is not an open source library, so there are two problems:

  • If I add compile 'com.android.support:support-v4:18.0.+' to build.gradle , a multiple dex file error is build.gradle during build, 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) 

    `

  • If I remove all libraries that require support-v4 , it will produce the missing dependency errors at runtime.

So, I would like to know whether it is possible to exclude this .jar file from the assembly or make other libs dependent on 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' } 
+6
source share
2 answers

Try using resolutionStrategy ( API link ) in the root directory of 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 } }) } 
+4
source

The Multiple dex files define Landroid / support / v4 / accessibilityservice / AccessibilityServiceInfoCompat easily as an exclude module: 'support-v4'

Example

 dependencies { compile('com.commonsware.cwac:camera-v9:0.5.4') { exclude module: 'support-v4' } compile 'com.android.support:support-v4:18.0.+' } 
0
source

Source: https://habr.com/ru/post/981060/


All Articles