Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update module created from local aar

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?

like image 744
Raphael Royer-Rivard Avatar asked Jan 20 '15 17:01

Raphael Royer-Rivard


People also ask

What is the difference between AAR and jar?

The main difference is aar is splitted inside android to jar. If your app will be used only in user app only in android studio then aar is preferred. If you are planning for app to communicate with c/c++ compiled lib.so file jar is preferred.

How do I extract an AAR file?

In android studio, open the Project Files view. Find the . aar file and double click, choose "arhcive" from the 'open with' list that pops up. This will open a window in android studio with all the files, including the classes, manifest, etc.

How do I add a dependency to AAR?

Add your AAR or JAR as a dependency Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Jar Dependency in the dropdown. In the Add Jar/Aar Dependency dialog, first enter the path to your .


1 Answers

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?)
like image 88
Raphael Royer-Rivard Avatar answered Oct 30 '22 19:10

Raphael Royer-Rivard