7

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.

2 Answers 2

7

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'
       }
 }
Sign up to request clarification or add additional context in comments.

Comments

4

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.