Search code examples
androidandroid-studioaar

How to create new Android AAR in Android Studio


I am trying to create an Andoid AAR library to contain commonly used utility functions. I followed the instructions in https://developer.android.com/studio/projects/android-library exactly. Namely:
1. File->New->New Module
2. Click "Android Library" then Next
3. Tried to use defaults: "My Library", "mylibrary" and SDK Version, but Finish button is grayed out and error message appeared: "The module location is inside Studio's install location." I see no place to enter a module's location. I've tried variations on Libray name and Module name with no joy.
Am I doing something wrong?


Solution

  • After days of unsuccessful head-banging with the IDE, I found an astoundingly simple solution in some Google results, namely:

    1. Manually edit project/app/build.gradle
    2. Change apply plugin: 'com.android.application' to apply plugin: 'com.android.library'
    3. Remove the line specifying applicationId.
    4. Build->Clean Project and Build->Rebuild Project.

    Voila! New library app-debug.aar appears in project/app/build/outputs/aar/
    I don't know where the name app-debug came from, but you can rename it afterwards if you like.

    UPDATE 7/2/18

    I omitted precursor steps to this procedure. They are
    1. Create a base project however you normally do.
    2. Delete classes and other stuff you don't need in the aar.
    3. Follow the steps above.