Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio how to package single AAR from multiple library projects?

I am building android library project, which has a dependency on another internal library project.

I am wondering if there is a way to package a single AAR library, which already contains internal library inside it. I would like to share only 1 AAR library package to my application developers.

This is how my build.gradle files look currently, but currently they produce separate AAR files and both needs to be included in Application's build.gradle. As application is being built by another company, we need to share the final AAR file with them and not the complete library projects.

----- internalLib -------->>>>>>>>>>

buildscript {     repositories {         mavenCentral()     }     dependencies {         classpath 'com.android.tools.build:gradle:0.7.+'     } } apply plugin: 'android-library'  repositories {     mavenCentral() }  android {     compileSdkVersion 18     buildToolsVersion '18.1.1' }  dependencies {     compile 'com.android.support:support-v4:18.0.0' } 

----- externalLib --------

buildscript {     repositories {         mavenCentral()     }     dependencies {         classpath 'com.android.tools.build:gradle:0.7.+'     } } apply plugin: 'android-library'  repositories {     mavenCentral() }  android {     compileSdkVersion 18     buildToolsVersion '18.1.1' }  dependencies {     compile 'com.android.support:support-v4:18.0.0'     compile project(':internalLib') } 
like image 307
Rahul Jain Avatar asked Dec 20 '13 09:12

Rahul Jain


People also ask

How do I add an AAR file to a libs folder?

Add your AAR or JAR as a dependency To use your Android library's code in another app module, proceed as follows: Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Jar Dependency in the dropdown. In the Add Jar/Aar Dependency dialog, first enter the path to your .

How do I extract a .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.

Where will you add the value library in Android Studio project?

Right click on the app folder -> Open Module settings -> go to the dependencies tab -> Click on the '+' button -> click on Module Dependency. The library module will be then added to the project's dependencies.


2 Answers

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 165
Xavier Ducrohet Avatar answered Oct 04 '22 16:10

Xavier Ducrohet


For the sake you have to upload each library as separately on maven and use its implementation in parent library modules till the main library module. Only then when you publish your main library on maven will include your all child dependencies.

like image 27
Muhammad Omer Avatar answered Oct 04 '22 17:10

Muhammad Omer