-1

I would like to create my own library .aar library file, and add it to different projects as a dependency in gradle. Also, how can I add *.aar library with own gradle file in local repository?

Dezso Gabos
  • 2,297
  • 5
  • 21
  • 29

2 Answers2

0

So, I guess you should move your .aar file to lib directory in the project folder (create it if necessary). After that in your build.gradle file in dependency section write like that

dependencies {
    ...
    implementation(name: 'your-library-name', ext: 'aar')
    ...
}
aLT
  • 326
  • 3
  • 9
0

If you are planning to release the lib, it will be better not to include the dependent libraries in the packaged aar and instead add the same compile dependencies found in lib build script inside the build script of the app as such:

app build.gradle:

dependencies {
    compile ':my-lib'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.facebook.android:facebook-android-sdk:4.14.1'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    compile 'com.google.android.gms:play-services:11.0.4'
}

That way users of your library won't face merging conflicts when they use public libraries like your library does, gradle will automatically resolve them.

If you are looking looking for a better way to include all dependencies in a single library: Don't. Gradle cannot resolve merging conflicts if a aar contains a certain lib packaged inside while the app as well depends on the lib and contains code calling methods from lib

You can read more details here: Exclude jar-library from aar And here Generate AAR file with all dependencies

Dezso Gabos
  • 2,297
  • 5
  • 21
  • 29