Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add '.aar' file in Android Studio

I have some .aar files. I added them in Project by right clicking on project, then add new Module, there i selected Import .jar .aar Package.

This added the .aar file in my project, along with a newly created .gradle file.

New Gradle File

configurations.maybeCreate("default")
artifacts.add("default", file('SDKTest-rel-1.01.aar'))

Now when i try to add this file in my build.gradle file, it gives me error messages

Failed to resolve: SDKTest-rel-1.01.

and i am unable to use classes of this SDK in my program.

Kindly guide me and tell me some other way of adding and using .aar files.

like image 509
dev90 Avatar asked Jun 11 '16 13:06

dev90


People also ask

Where is my AAR file in Android Studio?

gradle file. This will output an . aar when it's built. It will show up in the build/outputs/aar/ directory in your module's directory.

How do I open AAR files on Android?

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.

What is AAR file in Android?

In addition to JAR files, the Android uses a binary distribution format called Android ARchive(AAR). The . aar bundle is the binary distribution of an Android Library Project. An AAR is similar to a JAR file, but it can contain resources as well as compiled byte-code.

How do I create an AAR file?

To do that, you can execute the build task of Gradle. Your AAR file will be created! If you're not using Gradle command line tools, you can build an AAR using the Gradle navigation tab option within Android Studio. You can open the Gradle tab by pressing shift button twice while you're in Android Studio.


2 Answers

In a recent update the people at android broke the inclusion of local aar files via the Android Studio's add new module menu option. Check the Issue listed here. Following method works for local .aar files Put the aar file in the libs directory (create it if needed), then, add the following code in your build.gradle

dependencies {
   compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
 }
repositories{
      flatDir{
              dirs 'libs'
       }
 }
like image 176
USKMobility Avatar answered Nov 06 '22 21:11

USKMobility


To add .aar file as dependency, you need to create folder in the application module, copy the .aar file to it, and add the file as repository.

repositories {
    flatDir {
      dirs 'aars'
        }
   }

This will make it possible to add any file inside the folder as dependency. You can reference the dependency as follow:

dependencies {
    compile(name:'libraryname', ext:'aar')
   }

This tell the Gradle to look for a library with a certain name that has the .aar extension.

like image 20
Harin Kaklotar Avatar answered Nov 06 '22 20:11

Harin Kaklotar