2

My project is an Android Library which depends on Dropbox's android library.

dependencies {
    ...
    provided fileTree(dir: '../Libraries/Dropbox', include: ['*.jar'])
    ...
}

Everything works well excepts Gradle puts all the .jar files from Dropbox into my output .aar file.

MyLib.aar
|-classes.jar
|-AndroidManifest.xml
|-...
|-libs
    |-bcprov-jdk16-146.jar
    |-commons-logging-1.1.1.jar
    |-dropbox-android-sdk-1.6.1
    |-json_simple-1.1.jar

How can I avoid this?

CopperCash
  • 563
  • 5
  • 15
  • Did none of the answers solve your problem? Please consider accepting one of them as the answer if they helped you. Or clarify why they did not help. – Dirk Jäckel Dec 06 '15 at 23:20

2 Answers2

2

something like this might help you:

android.libraryVariants.all { variant ->
    variant.outputs.each { output ->
        def packageLib = output.getPackageLibrary()
        packageLib.exclude('libs/externalLibrary.jar')
    }
}

inside android {} block

kaps
  • 190
  • 3
  • 9
0
  1. Why do you want to avoid this? When you give your library to someone, they have all the dependencies already in one file.

  2. You can include the dependencies via

compile 'com.dropbox.core:dropbox-core-sdk:1.7.7' 
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'commons-logging:commons-logging:1.2'
compile 'org.bouncycastle:bcprov-jdk16:1.46'

in your build.gradle file and remove it from the libs folder. Do the same with the other dependencies. This way they will not be packaged into your .aar file.

Dirk Jäckel
  • 2,979
  • 3
  • 29
  • 47
  • Can I interpret your answer this way: 1. .aar library file will automatically include .jar file dependency. 2. .aar library file will **not** include gradle dependencies, client using .aar file must also add the same gradle dependencies manually? – Lim CHAN Feb 07 '17 at 02:40
  • Gradle dependencies are transitive. So if you depend on a certain library which in turn depends on others they will pulled in automatically. – Dirk Jäckel Feb 09 '17 at 20:53