Sharing Code in Android Studio using "AAR"

Believe it or not, but Android Studio was launched with absolute no support to share code across several projects. You would need to keep a separate copy of "shared library" with in each project that uses it ! I was sarcastically impressed (or rather depressed) by Google's product owner for Android Studio who dared to give out that kinda IDE to developers.

Finally, they gave out some way to share code through "AAR" files. Thank you !

However, adding ".aar" files is not recommended locally as per this article. AAR files should be referenced from maven repos. You can always publish them to local maven repos for development purposes.

Other easy way is to put the ".aar" files in "libs" or any other newly created folder of your choice and refer it from build.gradle like this:

repositories {
    flatDir {
        dirs 'libs'    }

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile (name:'yourAwesomeAndroidLibraryName', ext:'aar')

No comments:

Post a Comment

Scheduling Repeating Local Notifications using Alarm Manager

Learn about Scheduling Repeating Local Notifications using Alarm Manager in this post .