I'm aware of this question: Adding local .aar files to my gradle build but the solution does not work for me.
I tried adding this statement to the top level of my build.gradle
file:
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
I've also put the slidingmenu.aar
file into /libs
and referenced it in the dependencies
section: compile 'com.slidingmenu.lib:slidingmenu:1.0.0@aar'
but it did not work at all.
I tried compile files('libs/slidingmenu.aar')
as well but with no luck.
What am I missing? Any ideas?
P.S. Android Studio 0.8.2
Update : As @amram99 mentioned, the issue has been fixed as of the release of Android Studio v1.3.
Tested and verified with below specifications
What works now
Now you can import a local aar file via the File>New>New Module>Import .JAR/.AAR Package option in Android Studio v1.3
However the below answer holds true and effective irrespective of the Android Studio changes as this is based of gradle scripting.
Old Answer : 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. Irrespective of anything that goes in and out of IDE's feature list , the below method works when it comes to working with local aar files.(Tested it today):
Put the aar file in the libs directory (create it if needed), then, add the following code in your build.gradle :
This is my structure, and how I solve this:
On build.gradle
from Project/app/myModulesFolder/myLibXYZ
I have put this:
Done and working fine, my submodule XYZ depends on somelibrary from main module.
I got this working on Android Studio 2.1. I have a module called "Native_Ads" which is shared across multiple projects.
First, I created a directory in my Native_ads module with the name 'aars' and then put the aar file in there.
Directory structure:
Then, the other changes:
Top level Gradle file:
App module's build.gradle file: - no changes
Settings.gradle file (to include the module):
Gradle file for the Native_Ads module:
That's it. Clean and build.
For anyone who has this problem as of Android Studio 1.4, I got it to work by creating a module within the project that contains 2 things.
build.gradle with the following contents:
configurations.create("default")
artifacts.add("default", file('facebook-android-sdk-4.7.0.aar'))
the aar file (in this example 'facebook-android-sdk-4.7.0.aar')
Then include the new library as a module dependency. Now you can use a built aar without including the sources within the project.
Credit to Facebook for this hack. I found the solution while integrating the Android SDK into a project.
You can do it this way. It needs to go in the maven format:
And then your AAR needs to go in a folder structure for a group id "com.example":
Then reference as a dependency:
compile 'com.example:myaar:version@aar'
Where
version
is the version of your aar file (ie, 3.0, etc)The easiest way now is to add it as a module
This will create a new module containing the aar file, so you just need to include that module as a dependency afterwards