Include external module in Android Library aar

ぃ、小莉子 提交于 2019-12-10 18:45:38

问题


I have a simple enough Android Library build.gradle file (irrelevant parts removed),

apply plugin: 'com.android.library'

repositories {
    maven { url 'https://dl.bintray.com/alexeydanilov/maven' }
}

dependencies {
    compile 'com.danikula:videocache:1.0.1'
}

And I would like to be able to build an Android Library .aar which has all the files I want in it, but also all the files which come down from the videocache external module.

I've tried many different techniques to try and achieve this (another project, changing settings of 'transitive', attempting 'export = true') but all have proven unsuccessful and I'm not sure what else I can try.

If I download the source .jar file drop it in to libs, add the necessary bits to the settings file, it packages into the .aar correctly, but I can't seem to find any way to do it via referencing the external module like this.


回答1:


First of all it is not recommended to include external lib into aar file. A previous answer for this can be found here:

I quoted the text as below:

Using an artifact will not include it in the aar. The whole point of using remote artifacts is to not rely on jars but instead on the artifact adress so that the project using your 'aar' can resolve all its dependency graph, find duplicates, resolve conflicts, etc...

If you publish your 'aar' on Maven, the artifact POM will contain the dependencies. If you use it from a multi-project setup, the project generating the 'aar' will send those dependencies to projects referencing it.

For local jars, because those are no ways of knowing what the jar file is we have to package it locally, but this is really not something you should use if you are going to submit the 'aar' to an artifact repo.

So if you want to include and use your 'aar' lib from remote repo, you can publish it first and then add this line to your dependencies:

compile 'Replace with the link to your lib'

If you want to use the 'aar' file from a local place, there is also a not so perfect but working way to include all the external libs, which is simply copy this line:

compile 'com.danikula:videocache:1.0.1'

to dependencies in the project which is using your lib. But anyhow this is not recommended.

Hope my answer can help you.



来源:https://stackoverflow.com/questions/31792342/include-external-module-in-android-library-aar

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