I've been experimenting with the new android build system and I've run into a small issue. I've compiled my own aar package of ActionBarSherlock which I've called 'actionbarsherlock.aar'. What I'm trying to do is actually use this aar to build my final APK. If I include the whole ActionBarSherlock library as an android-library module to my main project using compile project (':actionbarsherlock') I'm able to build successfully without any problems.
But my problem is that I want to provide that dependency as a aar file package MANUALLY just if I would a JAR then I can't seem to figure out how to properly include it into my project. I've attempted to use the compile configuration but this doesn't seem to work. I keep on getting cannot find symbol during compile which tells me that the classes.jar from aar package isn't getting included in the classpath.
Does anyone know of the syntax to manually include an aar package as a file?
build.gradle
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.4' } } apply plugin: 'android' repositories { mavenCentral() } dependencies { compile files('libs/actionbarsherlock.aar') } android { compileSdkVersion 15 buildToolsVersion "17.0" }
EDIT: So the answer is that it's not currently supported, here's the issue if you want to track it.
EDIT: Currently as this is still not supported directly the best alternative seems to be the proposed solution from @RanWakshlak
EDIT: Also simpler by using the syntax proposed by @VipulShah
Add your AAR or JAR as a dependency To use your Android library's code in another app module, proceed as follows: Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Jar Dependency in the dropdown. In the Add Jar/Aar Dependency dialog, first enter the path to your .
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. A AAR file can be included in the build process of an Android application similar to a JAR file.
The main difference is aar is splitted inside android to jar. If your app will be used only in user app only in android studio then aar is preferred. If you are planning for app to communicate with c/c++ compiled lib.so file jar is preferred.
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.
Please follow below steps to get it working ( I have tested it up to Android Studio 2.2)
Lets say you have kept aar file in libs folder. ( assume file name is 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 did below
allprojects { repositories { jcenter() flatDir { dirs 'libs' } } }
and now open app level build.grdle 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With