How to include an external jar file to aar file in Android

血红的双手。 提交于 2020-01-15 06:18:09

问题


I want to develop a solution that allows me to use an external jar library in an SDK generated in aar file for an Android project.

What I have as inputs :

SDK : "de.xx.sdk:xxx-android-v1.0.0"

external library : "libs/xxxx-v1.0.0"

what I found out in my investigation is how to exclude a library from project like the following :

implementation('android.arch.work:work-runtime:1.0.0') {
        exclude group: 'com.google.guava', module: 'listenablefuture'
    }

Is there something similar to write in gradle file how to include a library instead of exclude it.

implementation('de.xx.sdk:xxx-android-v1.0.0') {
        include group: 'libs/xxxx-v1.0.0'
    }

Thank you


回答1:


You should try to put your jar into a module (File->New->New Module->Import JAR/AAR Package) and then add the module as a dependency.




回答2:


implementation('de.xx.sdk:xxx-android-v1.0.0') { include group: 'libs/xxxx-v1.0.0' }

You can't do it in this way.

Something like exclude group: 'com.google.guava', module: 'listenablefuture' is possible because you have an artifact with a pom file published in a maven repo.
In the pom file there is the list of the transitive dependencies, and if there is a match with the group/module gradle is able to exclude it.

To achieve something similar, you have to publish the lib a in maven repo with a group/name (it can't be lib/....v1.0.0)



来源:https://stackoverflow.com/questions/57852292/how-to-include-an-external-jar-file-to-aar-file-in-android

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