简体   繁体   中英

Include external module in Android Library aar

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM