How to import a .aar file into Android Studio 1.1.0 and use it in my code
Asked Answered
B

4

38

I have read a lot answers related to this topic, but none of them have worked to solve my problem, so need help with this:

I need to import a .aar file into a project created with Android Studio 1.1.0, I have imported it using the "New Module" option and actually I don't receive any error, I can build the application and run it, but when I try to use a class from this .aar file Android Studio doesn´t find the reference to it, let's say it can´t recognize the package that I want to include in my code.

You are maybe thinking that I must add the dependency, I have already done that, It seems to not work.

So someone could tell me which is the correct way to import and use a .aar file in Android Studio 1.1.0

Bylaw answered 23/4, 2015 at 14:37 Comment(3)
.aar's are not so easy to import locally, they are intented to be provided through a maven/ivy server. They are not like .jar libs.Demetriusdemeyer
possible duplicate of Adding local .aar files to Gradle build using "flatDirs" is not workingTraditionalism
It is similar, but any of thoses answers worked for me, so I need a very well explain process of how to import a .aar file and use it in my code, but using Android Studio 1.1.0Bylaw
B
24

After reading a lot of answers on Stackoverflow, I found the solution for my problem, I want you to know which were the steps I followed in order to reproduce it:

  1. Add a .aar file in my libs folder.
  2. Use "New Module" option under File menu.
  3. Import the .aar file.
  4. Build gradle and compile the project.

When I tried to use the new module in my app, It didn't recognize any class inside the new module.

The problem is related to the version of Gradle, I was using 1.1.0 and there is a bug in this version, so my suggestion is to change the version to 1.0.1, there is an Issue already open in order to fix this problem https://code.google.com/p/android/issues/detail?id=162634

You should change the version in the build.gradle file located in the root of your project.

buildscript {
repositories {
    jcenter()
}
dependencies {

    //classpath 'com.android.tools.build:gradle:1.1.0'
    classpath 'com.android.tools.build:gradle:1.0.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

You can find additional information about this problem here https://groups.google.com/forum/#!topic/adt-dev/1Ho_c8dALQQ

I guess in version 1.2.0 this problem will be solved.

Bylaw answered 23/4, 2015 at 19:16 Comment(2)
You made my day as well. :) And the problem still seems to exist in version 1.3.0. :(Gothart
Upgrade gradle version 1.3.1Devalue
O
95

To import an .aar library:

  1. Go to File>New>New Module
  2. Select "Import .JAR/.AAR Package" and click next.
  3. Enter the path to the .aar file and click finish.
  4. Go to File>Project Structure (Ctrl+Shift+Alt+S).
  5. Under "Modules," in left menu, select "app."
  6. Go to "Dependencies" tab.
  7. Click the green "+" in the upper right corner.
  8. Select "Module Dependency"
  9. Select the new module from the list.
Overstrung answered 3/8, 2016 at 17:11 Comment(4)
"Enter the path to .aar file and click finish." when I click finish, the window trembles and nothing happens, im guessing the trembling means an error, any ideas?Pliner
I was trying to do step 3 (enter the path to .aar file and click finish) but I could only enter the path to .aar file. The finish button was faded (could click on it)...Scandent
@pb772, did you type in the file path of the .aar file? If so, try locating it in the file browser, you might have made a typo in the path. It would also be worth testing a different .aar file to see if the problem is with the file you are trying to use.Overstrung
Thank you.. Worked like a charmMinefield
B
24

After reading a lot of answers on Stackoverflow, I found the solution for my problem, I want you to know which were the steps I followed in order to reproduce it:

  1. Add a .aar file in my libs folder.
  2. Use "New Module" option under File menu.
  3. Import the .aar file.
  4. Build gradle and compile the project.

When I tried to use the new module in my app, It didn't recognize any class inside the new module.

The problem is related to the version of Gradle, I was using 1.1.0 and there is a bug in this version, so my suggestion is to change the version to 1.0.1, there is an Issue already open in order to fix this problem https://code.google.com/p/android/issues/detail?id=162634

You should change the version in the build.gradle file located in the root of your project.

buildscript {
repositories {
    jcenter()
}
dependencies {

    //classpath 'com.android.tools.build:gradle:1.1.0'
    classpath 'com.android.tools.build:gradle:1.0.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

You can find additional information about this problem here https://groups.google.com/forum/#!topic/adt-dev/1Ho_c8dALQQ

I guess in version 1.2.0 this problem will be solved.

Bylaw answered 23/4, 2015 at 19:16 Comment(2)
You made my day as well. :) And the problem still seems to exist in version 1.3.0. :(Gothart
Upgrade gradle version 1.3.1Devalue
M
1

I follow steps in both answers but finally I need to add this line to my build.gradle:

allprojects {
    repositories {
        mavenCentral()
        flatDir { dirs 'aars'} // this line
    }
}
Mahala answered 1/11, 2016 at 12:48 Comment(0)
M
1

Use the gradle dependency

compile 'com.facebook.android:facebook-android-sdk:4.8.0'
Marchall answered 5/4, 2017 at 17:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.