17

Here is my setup : I have an android library that creates an aar when exported and I have an android app that uses the library as a module (it's the only way to import a local aar file).

To import the aar file as a module in my android app, I click on File -> New Module... -> Import .JAR or .AAR Package and I choose my exported aar file. After that I only need to add a compile project line in my gradle file to be able to use my library.

I update very often my library because I am currently developing it and I want to test it frequently. The problem is that I don't know how to update the module in my android app project...

What I am doing now is that I issue a gradlew assembleRelease in my android library project to create the new aar file, then in my android app project I delete the module in the Module Settings (or Project Structure) window, I delete the module folder at the root of my project and then I import it again. This whole operation takes around 3 minutes each time I want to test my library and I am tired of this. Do you know if there is a faster way of updating an android module created from an aar file?

Raphael Royer-Rivard
  • 2,252
  • 1
  • 30
  • 53
  • I don't see how this would help, since the project does not keep a reference on the aar file that was used to create the module. – Raphael Royer-Rivard Jan 20 '15 at 17:46
  • If it's copying the .aar into your project, you could just replace it with the new version, and if necessary do a clean build. I'm not sure if the build system will automatically detect the changed version of the .aar or not; if not, you'll have to do that clean. – Scott Barta Jan 20 '15 at 17:52
  • It is extracting the aar file (and even suggest you to delete the source file), so I guess it would not detect that the source file was edited. Anyway I found a cleaner way of using a local aar file. I am posting the answer. – Raphael Royer-Rivard Jan 20 '15 at 17:55

1 Answers1

17

I thought that importing a aar file as a module was the only solution to include a local aar file, but it seems that it can be done easily by simulating a repository with a flat directory.

In your project gradle file in the allprojects.repositories tag, add the following :

flatDir {
    dirs 'libs'
}

In your app module, make sure you have a libs folder with the aar file in it. Then add the compile line in the dependencies tag of your app module gradle file.

dependencies {
    compile 'package:name:version@aar'
}

Now, when you update the aar file in your libs directory, your app will use the updated version of your library.

Note:

  • In compile 'package:name:version@aar', name is physical file name of the library. For example lib-debug or lib-release etc.
  • version and package can be found in AndroidManifest.xml inside .aar file. (How to open .aar file?)
Mangesh
  • 5,491
  • 5
  • 48
  • 71
Raphael Royer-Rivard
  • 2,252
  • 1
  • 30
  • 53
  • 5
    notice : in `compile 'package:name:version@aar'` `name` - physical file name of library *ex. lib-debug* , `version` and `package` can be found in `AndroidManifest.xml` inside `.aar` file. – tchelidze Mar 22 '17 at 14:03
  • hey, just to make sure I understood you. I create a `libs` folder inside my my already imported library? i.e: http://i.imgur.com/VKeOK7H.png or do I create the `libs` folder inside my library that I use it to export ? – Suhaib Jul 27 '17 at 16:34
  • @Suhaib I can't recall if you have to create your libs folder in your app folder or at the same level, but definitely not in your library. – Raphael Royer-Rivard Aug 03 '17 at 15:57
  • I'm not able to see documentation in the popup when hovered. Any idea? – Mangesh Aug 15 '17 at 18:38