Adding local .aar files to Gradle build using flatDirs is not working
Building upon Josiah's answer, here's how I got it to work.
Following his instructions (under edit) (File -> New-> New Module -> Import .JAR/.AAR) and import your .AAR.
Then in your project build.gradle (not the top level one, the one under 'app') add the following (in the dependencies section):
dependencies {
compile project(':Name-Of-Your-Project')
}
Note Name-Of-Your-Project should match the name of the folder that was added after you imported the AAR file (at the same level as app/.idea
under the top most level folder). Or to put it another way...
MyApplication
.idea
app
build.gradle (here's where to add compile project(':ProjectName') to dependency section)
ProjectName (added automatically after importing, matching the name of your aar file)
build
gradle
etc
This worked for me running Android Studio 0.8.0. Don't forget to synchronize gradle (using toolbar button or in File->Synchronize) after you do this.
(Thanks to Josiah for getting me going in the right direction)
(Note: prior to this I tried adding it to the libs folder, trying to manipulate the top level build.gradle
and the app level build.gradle
, but none of that worked for my aars files--jar's will work fine, but not the aar files)
Adding local .aar files to my gradle build
You put your flatDir
block in the wrong repostories
block. The repositories
block inside buildscript
tells Gradle where to find the Android-Gradle plugin, but not the rest of the dependencies. You need to have another top-level repositories
block like this:
repositories {
mavenCentral()
flatDir {
dirs 'aars'
}
}
I tested this and it works okay on my setup.
Error building Android library: Direct local .aar file dependencies are not supported
I recently encountered the same issue, the fix was to remove the library from libs/
and import it using File -> New -> New Module -> Import .JAR/.AAR Package
, then referencing it in the library module build.gradle
file:
dependencies {
implementation project(":imported_aar_module")
}
If you are on a newer Android Studio version (4.0.0+), this option is not available. Instead you have to do it manually.
- Create a new directory and put the following content into the
build.gradle
file withing the new directory:
configurations.maybeCreate("default")
artifacts.add("default", file('[nameOfTheAar].aar'))
- Place the
aar
into this new directoy. Next to thebuild.gradle
file. - Add the new created Gradle project to the
settings.gradle
file:
include(":pathToTheCreatedDirectory")
- Include the project in your library where you want to use the
aar
:
implementation project(":pathToTheCreatedDirectory", configuration = "default")
How to manually include external aar package using Gradle for Android
Please follow the steps below to get it working (I tested it up to Android Studio 2.2).
Let's say you have an .aar
file in libs
folder (e.g. cards.aar
).
Then in app build.gradle
specify following and click Sync Project with Gradle files.
Open Project level build.gradle
and add flatDir {dirs 'libs'}
like below:
allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
}
Open app level build.gradle
file and add .aar
file:
dependencies {
implementation(name:'cards', ext:'aar')
}
If everything goes well, you will see library entry is made in build
-> exploded-aar.
Also note that if you are importing a .aar
file from another project that has dependencies you'll need to include these in your build.gradle
, too.
Add local .aar files to Titanium SDK 9 Android module
Found the libraries at https://github.com/polarofficial/polar-ble-sdk
Using this build.gradle
repositories {
maven { url "https://oss.jfrog.org/libs-snapshot" }
}
dependencies {
implementation files('../../libs/polar-ble-sdk.aar')
implementation files('../../libs/polar-protobuf-release.aar')
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'io.reactivex.rxjava3:rxjava:3.0.0'
}
works fine. No problems using import polar.com.sdk.api.PolarBleApi;
or auto-completion with Android Studio.
Compiling works fine (but I didn't try the module in Titanium at the end).
edit:
- add the build.gradle to your app, too:
platform/android/build.gradle
(same content) - app: create
/build/libs
and add the libs - module:
@Kroll.method
public void create()
{
PolarBleApi api = PolarBleApiDefaultImpl.defaultImplementation(TiApplication.getAppCurrentActivity(), PolarBleApi.FEATURE_HR);
Log.i("Polar", "Version: " + PolarBleApiDefaultImpl.versionInfo());
}
- app:
var window = Ti.UI.createWindow({
title: "Test"
});
var polar = require("ti.polar");
polar.create();
window.open();
output: [INFO] Polar: (main) [92,92] Version: 2.2.2
How to add a local aar dependency into a bintray published library?
I ended up using Kezong:
apply plugin: 'com.kezong.fat-aar'
I will create a fat arr containing all the dependencies you want.
In your gradle.build file you and the dependency to your local aar like this:
embed project(path: ':myLocalARR-1.3.1-release')
Using embed will ensure that your final arr will contain the java files from your local dependency.
Related Topics
How to Check Whether the Sim Card Is Available in an Android Device
Connecting to Wifi Using Adb Shell
Check Whether Activity Is Active
Configuration with Name 'Default' Not Found. Android Studio
An Android App Remembers Its Data After Uninstall and Reinstall
How to Create Tests in Android Studio
How to Know When the Recyclerview Has Finished Laying Down the Items
How to Align Title at Center of Actionbar in Default Theme(Theme.Holo.Light)
Difference Between Ontouch and Onclick Android
Android Expandablelistview - Looking for a Tutorial
Hide Ics Back Home Task Switcher Buttons
How to Create Android Spinner Without Down Triangle on the Right Side of the Widget
Libpng Error: Not a Png File Error Showing in Android Studio
Cannot Enable Gradle's Offline Mode on Android Studio 3.6
How to Prevent Going Back to the Previous Activity