Avoid packing .jar into Android Library (.aar)

放肆的年华 提交于 2019-12-07 19:25:16

问题


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?


回答1:


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




回答2:


  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.



来源:https://stackoverflow.com/questions/26908072/avoid-packing-jar-into-android-library-aar

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