Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export AAR including its dependencies?

I have an Android Studio library project which uses library.aar and library.jar. When I export it as mylib.aar and use this new AAR into a different app/project, it cannot find the classes defined in the library.aar and library.jar.

My build.gradle looks like this:

apply plugin: 'com.android.library'
android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile project(':library_dot_aar')
    compile project(':library_dot_jar')
}

I imported the AAR and JAR files in Android Studio using New -> Module -> Import .JAR or .AAR Package and add them as dependencies in Project Structure -> Module Settings -> Dependencies -> Add Module Dependencies.

When I unzipped mylib.aar it was only 25KB (considering library.aar was over 300KB, I assume mylib.aar's size would be in the same range) and the included dependencies were not included in it. How do I export an AAR that includes all its dependencies inside itself?

like image 759
alxcyl Avatar asked Apr 15 '15 02:04

alxcyl


People also ask

How do I extract an AAR file?

In android studio, open the Project Files view. Find the . aar file and double click, choose "arhcive" from the 'open with' list that pops up. This will open a window in android studio with all the files, including the classes, manifest, etc.

What is the difference between AAR and JAR?

Unlike JAR files, AAR files offer the following functionality for Android applications: AAR files can contain Android resources and a manifest file, which allows you to bundle in shared resources like layouts and drawables in addition to Java classes and methods.


1 Answers

You must check this answer:

There is no mechanism to combine library. It's a bit complicated as you probably want to control which dependencies get merged (for instance you probably don't want to include support-v4 in there). Also you'd need to merge the resources and Android manifest.

At this time there's no way to easily hack something, unless you are sure the resources have no conflicts between the two res folders (for instance you could have strings_a.xml in one lib and strings_b.xml in the other lib). This way you can just "merge" the two res folders by copying them both into the same location (as opposed to do a merge at the android res level).

For the Manifest it'd be more complicated, but doable with some custom code.

Providing a built-in mechanism for this is very low on our priority so don't expect it anytime soon.

like image 146
Mou Avatar answered Oct 10 '22 23:10

Mou