I've create a flutter plugin with:
flutter create --template plugin flutter_plugin
I've put my aar file inside flutter_plugin/android/src/main/libs folder
I've modified flutter_plugin/android/build.gradle
and changed rootProject.allprojects section to
rootProject.allprojects {
repositories {
google()
jcenter()
flatDir {
dirs "src/main/libs"
}
}
}
And added dependencies section, after android {}:
dependencies {
implementation (name:"mylib",ext:"aar")
}
but when i try running with: flutter run
I get gradle exception, apparently it tried to look for my mylib.aar inside example directory: example/src/main/libs/mylib.aar and failed.
I can put my lib inside example dir, but i don't think it's the right way,
as i want my aar to be part of the plugin.
My solution to add local .aar depencies to a flutter plugin is as follows (based on the instructions here How to add .aar dependency in library module?):
create a libs folder in your android plugin source code (<plugin_name>/android/libs) (on top level of your plugin, not in the example project)
add your .aar files in this folder (e.g. myFirstDependency.aar)
add your .aar dependencies (without the .aar extension) to your plugins build.gradle file (<plugin_name>/android/build.gradle) e.g.
dependencies {
...
implementation (name: 'myFirstDependency', ext: 'aar')
implementation (name: 'myOtherDependency', ext: 'aar')
}
in order for gradle to be able to find these dependencies you need to instruct gradle to search in the libs folder inside of the plugin. Therefore add the following to your plugins build.gradle (<plugin_name>/android/build.gradle, same as for your dependencies) under rootProject.allprojects repositories section.
(NOTE: there is also a buildscripts a repositories section which you should not change for this).
rootProject.allprojects {
repositories {
google()
jcenter()
//Add this below <plugin_name> is whatever your plugin is called eg. url_launcher
flatDir {
dirs project(':<plugin_name>').file('libs')
// e.g. dirs project(':url_launcher').file('libs') - don't miss the ':'
}
}
}
With that, you don't have the .aar library dependencies directly in your plugin.
I created a libs directory in the android directory of my plugin. I placed the aar I generated in the libs directory:
I updated the build.gradle file for the android code to include the following:
rootProject.allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}
And in the dependencies section:
implementation fileTree(dir: 'libs', include: ['*.aar'])
In my experience, adding direct plugin aar in another plugin project (flutter plugin's android project) is either very difficult or not allowed, so in that case, you have two options,
If your aar dependancy is available on gradle, use gradle that in your build file. You can search for it here
Or if you are building aar yourself from another project, then you can publish aar to your local maven and use that dependency in your flutter plugin by adding "mavenLocal()" to your plugins build file.
For example here is what I did to fix same issue:
My dependancy's build.gradle
group 'com.companyname.artifactname'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenLocal()
google()
jcenter()
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
apply plugin: 'com.android.library'
uploadArchives {
repositories {
mavenLocal()
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 2
versionName "2.0.1"
}
lintOptions {
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
apply plugin: 'maven-publish'
publishing {
publications {
library(MavenPublication) {
version "1.1"
artifact(bundleRelease)
}
}
}
Then just run following command to publish it to local maven repository
gradlew publishToMavenLocal
And then just add mavenLocal() in your flutter plugin's repositories section and add dependancy as
compile 'com.companyname.artifactname:libraryname:1.1#aar'
With the flatDir solution you will get a warning when you try to sync your project with the Gradle files:
using flatDir should be avoided because it doesn't support any meta-data formats.
You can put this in your build.gradle instead to get rid of the warning:
android {
sourceSets {
main.jniLibs.srcDirs += project(':<plugin_name>').file('libs')
}
}
dependencies {
implementation files('libs/<dependency_name>.aar')
}
Unfortunately, with both solutions you'll get this error when you try to build the project:
Direct local .aar file dependencies are not supported when building an AAR.
The resulting AAR would be broken because the classes and Android resources from any local .aar
file dependencies would not be packaged in the resulting AAR. Previous versions of the Android
Gradle Plugin produce broken AARs in this case too (despite not throwing this error).
The accepted answer seems to be correct. I put the library inside the app's project instead because both options of the accepted answer were not possible in my case.
For this I had to create a new directory in the android directory of my app (i.e. example/android/<dependency_name>) and put my .aar file and a new build.gradle in that directory.
android/build.gradle:
dependencies {
implementation project(':<dependency_name>')
}
example/android/<dependency_name>/build.gradle:
configurations.maybeCreate("default")
artifacts.add("default", file('<dependency_name>.aar'))
example/android/settings.gradle:
include ':<dependency_name>'
i managed to make it work by adding
maven { url("${project(':test_flutter_plugin').file('libs').path}/my_lib") }
into rootProject.allprojects
of plugin/android/build.gradle
Related
I am building a sample project from Udacity. This was working fine till now, but after upgrading to Android Studio 3.2.1, I am facing the build error below.
Gradle version: 4.6
Project link: https://github.com/udacity/ud851-Sunshine/tree/student/S02.02-Solution-Menus
Could not find com.android.tools.build:aapt2:3.2.1-4818971**. Searched in the following locations:
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar Required by:
project :app
How can I fix it?
For Android Studio 3.2.1 update
Just add google() in root level build.gradle
buildscript {
repositories {
google() // <--here
jcenter()
}
}
allprojects {
repositories {
google() // <-- here
jcenter()
}
}
and see the magic - error is gone.
The project gradle version is pretty old:
classpath 'com.android.tools.build:gradle:2.2.3'
And you are using Android Studio v3.2.1 so, update the gradle:
classpath 'com.android.tools.build:gradle:3.2.0' // or 3.2.1 maybe
Also, as you can see, it was looking for some packages in :
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
Which means you probably forgot to add google() as the top level repository. Just add google()
to your repositories in your root build.gradle.
To get this solved
Firstly download the missing Jar file from the link below. I see you are missing version 3.2.1-4818971
https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
Switch your folder structure from Android to Project.
Now navigate to the libs folder inside the app - build folder. (If the libs folder does not exist, you can create it by right clicking on the app folder - select New - select Directory.)
Paste the downloaded.jar file inside libs folder. Right click on the jar file and at the bottom click on Add as library. This will take care of adding implementation files('libs/library_name.jar') in build.gradle [You don't have to manually enter this in your build file].
Everything should be okay once you sync after doing the above.
Here is the source link to this solution: https://developer.android.com/studio/command-line/aapt2#download_aapt2
Let me know if you run into any other issues whilst doing the above.
Yeah, as d4rkcon said download https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
But you can do simplier - just put this file in directory where Andoid Studio is trying to find it. If you don't have directories like /tools/build/aapt2/3.2.1-4818971/ in AndroidSDK folder just create them and then put aapt2-3.2.1-4818971-windows.jar file in.
Add Google repository in your build.gradle(Project:xxxxx)
allprojects {
repositories {
google()
}
}
clear gradle cache
rm -rf $HOME/.gradle/caches/
and resync to download all dependencies
Change your build.gradle as follows.
android {
compileSdkVersion 26
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "your package name here"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:26.1.0'
}
add google() on your build script > repositories
add google on allprojects > repositories
use implementation as replacement of compile keyword,
also on your filetree.
EX.
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:25.3.1'
implementation 'com.android.support:design:25.3.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:25.3.1'
For Android Studio 3.6.3 update : just adding google maven tag in buildscript and all projects repositories in build.gradle file of project file solves the issue.
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I just downloaded Android Studio and created a new project and I'm getting gradle build errors:
Failed to resolve: com.android.support.test.espresso-core:2.2.2
and
Failed to resolve: com.android.support.appcompat-v7:25.3.1
This error was resolved reinstalling the SDK Tools + Repository + API when launching android studio as admin.
I've installed API Level 25 which what I want to build on and have downloaded the SDK Build-Tools. I have also already download the support repository
Here's my app file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
defaultConfig {
applicationId "com.jtsalas.mirrorcontrol"
minSdkVersion 25
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_7
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
From the SDK manager, make sure you have both the Android Support Repository and Google Repository installed and up to date. You should then be able to find the relevant artifacts in sub folders of your /extras/android/m2repository directory
From your error it seems that you are not including espresso libraries. The solution to this is adding espresso core library which is part Android Testing support library which is hosted in the google's Maven repository think this as kind of git repository but for dependencies.
So we tell the gradle build system to look in the Maven repository for dependencies by specifying its URL.
This is done by adding Maven url in the application level build.gradle file under repositories block
repositories {
jcenter()
maven{
url "https://maven.google.com"
}
}
and in the module level build.gradle file mention the dependencies that you want from the maven repository by mention their name as follows:
dependencies{
//other dependencies go here
//testing dependencies
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
}
That is the reason for including Maven repository url in the app level build.gradle file, hope this helps.
In project.gradle file, the allprojects root align this way:
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
jitpack is used as the dependency for multiple libraries, if you're not using any sort of library that don't requires it then not include maven line.
Well, I don't know the perfect answer but..... how about comparing with my SDK Tools?
I solved it by uninstalling Android Studios and deleting old versions of Android Studios in my C:\Users[Username] and reinstalled Android Studio as administrator.
It seems like you updated android studio and opening previous project in it.The simplest way is create new project and copy
1. compileSdkVersion 26
2. buildToolsVersion "26.0.1"
3. targetSdkVersion 26
4. compile 'com.android.support:appcompat-v7:26.+'
and paste them in appropriate places in app level build gradle.
it will ask to update to take advantages .. allow it to update.
best luck ... It worked for me.
if your project is Flutter,
clean project [by 'flutter clean' command]
In project.gradle file add [ google() ]
in Android studio: File Menu -> Invalidate...
project.gradle:
allprojects {
repositories {
google()
jcenter()
}
}
i have a hello world full screen android studio 1.5.1 app that i added a gradle/eclipse-mars subproject to. no other files were modified except for adding include ':javalib' to settings.gradle. adding a project lib dependency:
project(':app') {
dependencies {
compile project(':javalib') // line 23
}
}
to the root build build file and running gradle from the command line , gets:
Where:
Build file 'D:\AndroidStudioProjects\AndroidMain\build.gradle' line: 23
What went wrong:
A problem occurred evaluating root project 'AndroidMain'.
Could not find method compile() for arguments [project ':javalib'] on org.grad
le.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#46
3ca82f.
adding the java plugin to the root build file did not help.
i don't think it's in the wrong place.
both the root project and the added subproject have the gradle wrapper.
any pointers will be appreciated.
thanks
edit: for clarification, the root build file is:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
task hello << { task -> println "I'm $task.project.name" }
}
project(':app') {
dependencies {
//compile project(':javalib') // causes problems
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and the app build file is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "acme.androidmain"
minSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile project(':javalib') // use :javalib:jar?
//testCompile project(':javalib')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
}
edit: the whole purpose of this exercise is to get core java code into an android project. currently the core code is a standalone gradle/eclispe project. i have a batch in the android project that does a gradle -p standaloneprojectdir/ jar and copied the jar into libs/.
i just though there would be an easier way other than to publish the jar and get it from a repository since this all done on my pc.
it would be nice to have all the code live and just do a build :(
edit: as per RaGe's suggestion, here is a virgin android studio project and a virgin gradle/eclipse project. no editing has been done to these files. you mission should you choose to accept it is to get the android app to easily access the java project classes (i.e. new Library(); in MainActivity.onCreate() will compile and run). i don't care where the java project lives. ideally, both sources would be live in both ide's.
atempting this fails also. says: > Could not find :virginjavaproject, but directory does exist.
edit: what actually worked was RaGe's pull request to the virgin android project.
You already have
compile project(':javalib')
in your :app project, you don't have to also inject the dependency from your root build.gradle. If you still want to do it from the root build.gradle, the correct way to do it is:
configure(':app') {
dependencies {
compile project(':javalib') // causes problems - NOT ANYMORE!
}
}
the virgin android studio head is what worked.
We have 2 files named "build.gradle".
make sure you have copied your "compile code" in the build.gradle file that is inside "app" folder
As stated by #peter-niederwieser:
The build script is mixing up buildscript dependencies (i.e. dependencies of the build itself; typically this means Gradle plugins) with regular dependencies (i.e. dependencies of the code to be compiled/run). The latter need to go into dependencies { ... }, not into buildscript { dependencies { ... } }. Everything but the classpath dependencies are regular dependencies.
Also have a look at this: Could not find method compile() for arguments Gradle.
Simply paste this on build.gradle(Project:"Your prject name")
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I had this problem but with my own library. The way to correctly compile was:
compile project(path: ':MyLib')
I am trying to install Picasso (http://square.github.io/picasso/) for use in Android Studio. One of the steps is to add this line: compile 'com.squareup.picasso:picasso:2.5.2' in build.gradle under dependencies. However, there is a message in gradle that tells me not to insert individual dependencies in the dependencies folder. What should I do?
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
You need to add it to the gradle.build file that is located in the "app" directory, not the one in your project directory. find the gradle.build file that sits within the "app" directory of your project.
Here is mine as an example:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.your.packagename"
minSdkVersion 15
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
repositories { mavenCentral() }
dependencies {
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
}
And a link to some supporting documentation:
http://developer.android.com/tools/building/configuring-gradle.html
Screenshot of the build.gradle(Module:app file)
Take a look at the image.
Do you see that there are actually 2 build.gradle files?
what you need is the (Module:app) gradle build file select that and paste the link in the dependencies part in the bottom of that file just like what i have done , then Android Studio will ask you to sync the file.
Do it.
It will download the dependency from your link provided and integrate with the project
Hope this helps..
So I have created an Android library and successfully compiled it into a .aar file. I called this aar file: "projectx-sdk-1.0.0.aar". Now I want my new project to depend on this aar so what I have done is follow this post.
But the post confuses me since I do not get the desired result:
The package name of the aar is : com.projectx.photosdk and the module inside is called sdk
Here is my current project structure:
|-SuperAwesomeApp
|--.idea
|--gradle
|--App
|---aars
|----projectx-sdk-1.0.0.aar
|---build
|---jars
|---src
|---build.gradle
And here is my Gradle build file:
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
flatDir {
dirs 'aars'
}
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:gridlayout-v7:19.0.1'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.projectx.photosdk:sdk:1.0.0#aar'
// compile files( 'aars/sdk-1.0.0.aar' ) // Does not work either
}
EDIT
The errors I am getting:
Failed to refresh Gradle project 'SuperAwesomeApp'
Could not find com.projectx.photosdk:sdk:1.0.0.
Required by:
SuperAwesomeApp:App:unspecified
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.
With recent versions of Android Studio, tested with 1.3, to use local .AAR file and not one fetched from maven/jcenter repository, just go to File > New > New module and choose Import .JAR/.AAR Package.
What you will end up with is a new module in your project that contains very simple build.gradle file that looks more or less like this:
configurations.create("default")
artifacts.add("default", file('this-is-yours-package-in-aar-format.aar'))
Of course, other projects have to reference this new module with regular compile project directive. So in a project that uses this new module which is simple a local .aar file has this in it's build.gradle
[...]
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
[...]
compile project(':name-of-module-created-via-new-module-option-described-above')
}
[...]
In Android Studio 3.1.3 with gradle 3.0.1.
Simply adding implementation fileTree(dir: 'libs', include: ['*.aar']) or implementation files('libs/app-release.aar') without any other flatdir works.
These days (over 1 year after this question) with Android Studio >1.0, local dependency does work properly:
The android sdk looks for dependencies in a default local repo of: $ANDROID_HOME/extras/android/m2repository/
In a local library project you can publish the aar to this directory. Here's a snippet that can be added to your module's build.gradle file (ex: sdk/build.gradle)
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://localhost" + System.getenv("ANDROID_HOME")
+ "/extras/android/m2repository/")
pom.version = '1.0-SNAPSHOT'
pom.groupId = 'your.package'
pom.artifactId = 'sdk-name'
}
}
}
some reference gradle docs http://gradle.org/docs/current/userguide/artifact_management.html
In your library project, run ./gradlew uploadArchives to publish the aar to that directory
In the application project you want to use the library in, add the dependency to your project/app/build.gradle. compile 'your.package:sdk-name:1.0-SNAPSHOT'
For local dependency, the next gradle build should find the previously deployed archive and that's it!
In my case, I use the above for local dev, but also have a Bamboo continuous integration server for the Library that publishes each build to a shared Nexus artifact repository. The full library code to deploy the artifact then becomes:
uploadArchives {
repositories {
mavenDeployer {
if (System.getenv("BAMBOO_BUILDNUMBER") != null) {
// Deploy to shared repository
repository(url: "http://internal-nexus.url/path/") {
authentication(userName: "user", password: "****")
}
pom.version = System.getenv("BAMBOO_BUILDNUMBER")
} else {
// Deploy to local Android sdk m2repository
repository(url: "file://localhost" + System.getenv("ANDROID_HOME")
+ "/extras/android/m2repository/")
pom.version = '1.0-SNAPSHOT'
}
pom.groupId = 'your.package'
pom.artifactId = 'sdk-name'
}
}
}
In order to tell applications to download from my internal Nexus repository, I added the internal Nexus maven repository just above jcenter() in both "repositories" blocks in the project/build.gradle
repositories {
maven {
url "http://internal-nexus.url/path/"
}
jcenter()
}
And application dependency then looks like compile 'your.package:sdk-name:45' When I update the 45 version to 46 is when my project will grab the new artifact from the Nexus server.
With the newest Gradle version there is now a slightly updated way of doing what Stan suggested (see maving publishing)
apply plugin: 'maven-publish'
publishing {
publications {
aar(MavenPublication) {
groupId 'org.your-group-id'
artifactId 'your-artifact-id'
version 'x.x.x'
// Tell maven to prepare the generated "*.aar" file for publishing
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
}
}
repositories {
maven {
url("file:" + System.getenv("HOME") + "/.m2/repository")
}
}
}
It seems adding .aar files as local dependency is not yet supported(Planned to be supported in 0.5.0 Beta)
https://code.google.com/p/android/issues/detail?id=55863
But the way you are using your library in dependency will only work if your library is on central maven repository or in the local maven repository.
Refer this for How to use local maven repository to use .aar in module dependencies.
http://www.flexlabs.org/2013/06/using-local-aar-android-library-packages-in-gradle-builds
This is for Kotlin DSL (build.gradle.kts) assuming you put the files in my-libs subdirectory relative to where the build file is located:
dependencies {
implementation(
fileTree("my-libs/") {
// You can add as many include or exclude calls as you want
include("my-first-library.aar")
include("another-library.aar")
// You can also include all files by using a pattern wildcard
include("*.jar")
exclude("the-bad-library.jar")
}
)
// Other dependencies...
}
For more ways to do this, see Gradle documentations and this post and this post.