23

I have created a library module in my project. Now, I want to share/publish this library with others. Sharing a .aar file would be fine for now.

I went through the article - https://developer.android.com/studio/projects/android-library and found the following options.

  1. When you want to build the AAR file, select the library module in the Project window and then click Build > Build APK.
  2. However, if you want to share your AAR file separately, you can find it in project-name/module-name/build/outputs/aar/ and you can regenerate it by clicking Build > Make Project.

I have tried these two options, but couldn't find /aar folder in the path project-name/module-name/build/outputs/

This is the first time I am building a library that needs to be shared with others.

Is there something else I need to do? Please share your thoughts.

Suneesh Ambatt
  • 1,347
  • 1
  • 11
  • 41

2 Answers2

54

You should do it using gradle. Just follow these steps and you will get .aar file:

1) At right side of your android studio there is a pane name Gradle. Open it and then do open library portion and run assemble. Like in the picture below.

enter image description here

2) When it is successfully ran just go to your library folder and you will find your .aar files there.

C:\projectPath\libraryPath\build\outputs\aar
Umair
  • 6,366
  • 15
  • 42
  • 50
  • thanks. I have already found out it myself. Anyway, I am marking this answer as correct. :) – Suneesh Ambatt May 10 '18 at 07:21
  • That worked! can you please help me m facing problem while adding aar file into library module. M able to create aar file but app crash when calling aar file from project. – corda dev Aug 28 '18 at 10:48
  • @Android what error does it throws and do you want to change the aar file too ? – Umair Aug 28 '18 at 10:50
  • @Umair M able to call the method of library module but while calling the method of aar file that is in lib folder of library module then app crashed. Error occcured java.lang.NoClassDefFoundError: Failed resolution – corda dev Aug 28 '18 at 11:10
  • @Umair if m using direct library module instead of aar then it worked, but due to my requirement i need to use aar. It worked because i have defined dirs project(':openkeysdk-release').file('libs') into project level, but when i used aar then this code we need to removed. It complied successfully but run time error occured. is there any way to define dirs of lib folder of library module ? – corda dev Aug 28 '18 at 11:13
  • when we assemle the module then we need to define flatDir { dirs 'libs'} or not? – corda dev Aug 28 '18 at 11:36
  • @Android you cannot access a class through .aar file that's why it is recommended to add library as a module in your project. if you include .aar file then you can only able to call it and use it but not able to change anything in it. And moreover it can also happen that your desired .aar files does not support older versions of your project that's why you are unable to access it. – Umair Aug 28 '18 at 12:09
  • @Android you only need to assemble the module when you add your library as a module. when you add it as .aar then you don't need to assemble it. – Umair Aug 28 '18 at 12:10
1

Android create .aar from command line

You can try manually create .aar from command line

./gradlew <moduleName>:assemble

output is located

<project_path>/build/outputs/aar/<module_name>-<build_variant>.aar

[Read more]

yoAlex5
  • 29,217
  • 8
  • 193
  • 205