Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to release an AAR with another android library project dependency?

Here is my development project structure:

projectFolder
  |
  +--App
  |
  +--MyLib
  |
  +--Libraries
      |
      +--LibA

MyLib depends on LibA, I have packaged MyLib as an AAR and release it to a Maven repo, But when I include MyLib in another project(TestProj) as a remote aar dependency, I get build error(can't resolve dependency of LibA, LibA is not included with the release of MyLib), This is the build.gradel in app folder of TestProj:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile ('xxx.xxxxxx:yyyyy:1.0-SNAPSHOT@aar'){
      transitive = true
  }
}

And here is the build.gradle of MyLib:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile project(':Libraries:LibA')
}

How can I release MyLib with LibA already packaged in the AAR?

like image 223
FlyingHorse Avatar asked Nov 09 '14 12:11

FlyingHorse


People also ask

How do I add AAR dependency to AAR library?

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 .

What is the difference between AAR and jar?

The main difference is aar is splitted inside android to jar. If your app will be used only in user app only in android studio then aar is preferred. If you are planning for app to communicate with c/c++ compiled lib.so file jar is preferred.

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 .AAR file in Android Studio?

Android Studio can be used to create an Android archive file (*. aar) that can contain classes and methods that make use of Android classes and related files. Like creating the Jar file, an Android project must be created first, then the Android library module can be created and added.


1 Answers

Answer the question myself. finally I changed the build.gradle in MyLib to:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  provided project(':Libraries:LibA')
}

so LibA will only be used in the build process of MyLib, TestProj will not ask for the LibA dependency anymore at compile time. NOTE THAT this may cause NoClassDefFoundError at runtime, so you must told the guys who used your library to include the LibA themselves in build.gradle of their project.

At first, I was looking for a method to package LibA with MyLib, but it seems diffcult.

See this question: Android Studio how to package single AAR from multiple library projects?

like image 167
FlyingHorse Avatar answered Oct 05 '22 21:10

FlyingHorse