Exporting Android Library as aar with sources in Android Studio

Ever wanted to view through the aar library sources in your android studio project, but got the decompiled class files instead. For seeing the source code, when going to function declarations inside the aar file you can attach the sources for the aar library inside the Android Studio like this.

  1. First build a sources.jar file from the library project. This can be done by adding following task in the app.gradle file. (reference : stackoverflow.com)
task generateSourcesJar(type: Jar) {
     classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}

2. Run the task from the gradle menu

Source jar file will appear in the …\MyLibrary\app\build\libs\ path

3. To Attach this file to the project using the aar file, change to project view. Right Click on the library aar file, from the external libraries expanded menu.

4. In the displayed dialog, click on the add button, and you can select the sources.jar we build earlier, or you can point it directly to your library project source folder ( src/main/java subfolder ) source : ROS Wiki

Hope you get some benefits from this post. Keep creating awesome stuffs.

266 Total Views 3 Views Today

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *