Conflicting gradle tasks from different plugins [duplicate] - android

I want to install android library project to local maven repository.
Here is build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
apply plugin: 'maven'
version = "1.0.0-SNAPSHOT"
group = "com.example"
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 18
}
}
When I run:
gradle install -i
it gets stuck here:
Executing task ':project:installTest' due to:
Task has not declared any outputs.
Starting process 'command 'd:\android-sdk-windows\platform-tools\adb.exe''. Working directory: D:\Projects\java\....... Command: d:\android-sdk-windows\platform-tools\adb.exe install -r D:\Projects\java\.......\build\apk\project.apk
An attempt to initialize for well behaving parent process finished.
Successfully started process 'command 'd:\android-sdk-windows\platform-tools\adb.exe''
> Building > :project:installTest
So first thing I noticed is that it's trying for some odd reason to deploy it on a device as APK.
Am I doing something wrong or is it just android-library plugin not compatible with maven plugin?

Edit: Please refer to the github page (https://github.com/dcendents/android-maven-gradle-plugin) for the latest instructions and find the correct version to use. The original instructions are not suitable anymore with the latest gradle release.
Original Post:
I've modified the maven plugin to be compatible with android library projects. See the project on github: https://github.com/dcendents/android-maven-gradle-plugin
Configure your android library projects to use it:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.dcendents:android-maven-plugin:1.0'
}
}
apply plugin: 'android-library'
apply plugin: 'android-maven'
Then you should be able to install aar into your local maven repository using the install task.
Hope this helps, if you find issues with the plugin please let me know on github and I'll fix it.

Elaborating on CyclingSir's answer, I propose to add a separate "installArchives" task. This should also take care of picking up your custom artifacts (e.g. sources).
apply plugin: 'maven'
task installArchives(type: Upload) {
description "Installs the artifacts to the local Maven repository."
configuration = configurations['archives']
repositories {
mavenDeployer {
repository url: repositories.mavenLocal().url
}
}
}
Note that with Gradle Android plugin v0.5.5, gradle install still tries to install something on a device.

There's an easier solution if you don't want to use a custom plugin. Instead, just recreate the install task with a different name. I called it installArchives. Add the following code to your build.gradle:
task installArchives(type: Upload) {
description "Installs the artifacts to the local Maven repository."
repositories.mavenInstaller {
configuration = configurations.default
pom.groupId = 'my.group'
pom.artifactId = 'my-artifact'
pom.version = '1.0.0'
}
}
You can now run gradle installArchives to install your aar locally.

UPDATE 2014-11-26
The answer below made sense at the time of writing, when Android Build Tools were at version 0.5.5. It is most likely outdated now and probably does not work anymore.
I have personally switched my projects to use android-maven-plugin as described in the answer above, the plugin works fine with the recent versions of Android Build Tools too.
THE ORIGINAL ANSWER FROM FEBRUARY 2014
Publishing as AAR
If you don't mind using an older version of com.android.tools.build:gradle (i.e. 0.5.4), you can use the approach described in this blogpost. Not that according to the discussion in adt-dev mailing-list, this does not work in 0.5.5.
Add the following lines to your build.gradle:
apply plugin: 'maven-publish'
// load bundleRelease task
// this will not load the task in 0.5.5
android.libraryVariants
publishing {
publications {
maven(MavenPublication) {
artifact bundleRelease
}
}
}
To publish to your local maven repo, call this command:
gradle publishToMavenLocal
Publishing as JAR
If your Android Library does not have custom resources and can be published as JAR, then you can use the following build.gradle that works even with 0.5.5.
// build JAR file
task androidReleaseJar(type: Jar, dependsOn: assembleRelease) {
from "$buildDir/classes/release/"
}
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
artifact androidReleaseJar
}
}
}
To publish to your local maven repo, call this command:
gradle publishToMavenLocal

I just solved the issue by defining an upload archive as described here:
Gradle documentation 52.6.2. Deploying to a Maven repository
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://${System.env.HOME}/.m2/repository/")
}
}
}
calling
gradle uploadArchives
deploys the artefact to the (in my case local) Maven repo.
I havn't found a simple and more flexible way to specify the local repo's url with e.g. mavenLocal() yet but the above suits my needs.

Related

3rd-party Gradle plug-ins may be the cause

After updating to Android Studio 3.1 I got this error message:
The project works fine and this is mostly just a warning, so my question is what's the meaning of the warning and how can I get rid of it?
The relevant parts from gradle files:
This is my project's build.gradle
buildscript {
ext {
kotlin_version = '1.2.31'
anko_version = '0.10.4'
room_version = '1.0.0'
support_version = '27.1.0'
firebase_version = '12.0.0'
gms_version = '12.0.0'
}
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
}
}
And this is my app's build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
To solve the issue, remove Instant App Provision from the "Run Configurations" and leave only the Gradle-Aware Make.
Run -> Edit Configurations..
I have AndroidStudio 3.1, Gradle Plugin 3.1.0 and Kotlin library version 1.2.30.
I restarted Android Studio and the problem disappeared.
Click File -> Invalidate Caches/Restart
Every time I change the gradle file, I must restart Android Studio to or the problem returns.
You can also try this:
Re-ordered repositories to:
mavenCentral()
maven { url 'https://jitpack.io' }
google()
jcenter()
Clearing this folder: user's ~/.gradle/caches and deleting app
build folder manually, then clean and rebuild.
What fixed the issue for me:
Change gradle plugin version to 3.1.0
Change Kotlin version to 1.2.30
Then Android studio changed gradle wrapper to version 4.4
Then Android studio was saying that the build tools version used was
27.0.3 and that I should change it to 27.0.3 so I also changed the target SDK to 27
I added this to my gradle.build:
kapt {
generateStubs = true
}
I hope it helps
at android studio v3.1.2 , happen Error:
Folder D:\AndroidProjects\app\build\generated\source\kaptKotlin\debug
Folder D:\AndroidProjects\app\build\generated\source\kaptKotlin\release
3rd-party Gradle plug-ins may be the cause
because dataBinding use apply plugin: 'kotlin-kapt' so add
kapt {
generateStubs = true
}
Change gradle plugin version to 3.1.2
Change Kotlin version to 1.2.30
Then Android studio changed gradle wrapper to version 4.4
Then Android studio was saying that the build tools version used was
27.1.1 and that I should change it to 27.1.1 so I also changed the target SDK to 27
Here are some steps that I've followed. In my case it's fixed the issue!
Platform modules targeting Android
The update of the experimental multiplatform projects feature introduces support for Android platform modules. These modules should apply the corresponding plugin in the Gradle build script and can use the shared code from a common module:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-platform-android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
// ...
// ...
Kapt diagnostic locations
As of now, kapt, the Kotlin annotation processing tool, can offer links to locations in the original Kotlin code rather than generated Java stubs as it reports errors encountered during annotation processing. You can enable this feature by adding these lines to the Gradle build script (build.gradle):
kapt {
mapDiagnosticLocations = true
}
Add this:
allprojects {
repositories {
jcenter()
google()
}
}
Don't forget the next:
// Architecture Component - Room
implementation "android.arch.persistence.room:runtime:1.1.0-beta1"
kapt "android.arch.persistence.room:compiler:1.1.0-beta1"
// Lifecyles, LiveData and ViewModel
kapt 'com.android.databinding:compiler:3.1.0'
// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:1.1.1"
// alternatively, just ViewModel
implementation "android.arch.lifecycle:viewmodel:1.1.1"
// alternatively, just LiveData
implementation "android.arch.lifecycle:livedata:1.1.1"
kapt "android.arch.lifecycle:compiler:1.1.1"
// Room (use 1.1.0-beta1 for latest beta)
implementation "android.arch.persistence.room:runtime:1.0.0"
kapt "android.arch.persistence.room:compiler:1.0.0"
// Paging
implementation "android.arch.paging:runtime:1.0.0-alpha7"
// Test helpers for LiveData
testImplementation "android.arch.core:core-testing:1.1.1"
// Test helpers for Room
testImplementation "android.arch.persistence.room:testing:1.0.0"
Clean your project
Build and That's it!
Add all of this, Clean your project, build and That's it! :) Let me know if this works! (If it is not working for you, I will help you with another solution)
More Info: Android Site
:) Let me know if it works! (If it does not work, I will
try to help you finding a better way)
If you give a downVote explain why
What actually helped for me is adding this
kapt {
generateStubs = true
}
into build.gradle
Try removing Instant run from settings and gradle will good to go.
It worked for me.
Here are some steps that i have followed and it's fixed the issue in my case.
First of all install kotlin plugin version to '1.2.31' and update it in build.gradle file like below.
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$1.2.31"
}
Clean Project.
Finally Rebuild the project.
In my case none of the above solutions solved my problem, I was using 1.2.50 Kotlin version without any mention to Instant Run, and the build wasn't generating the Dagger classes, so I find out this question that solved my issue, apparently, in my situation it's an issue related to the new Kotlin version, so I downgraded to version 1.2.41 and worked fine.
By the way, I just tracked to that point because I used the Toggle View on Build screen.
1:Select the Toggle View and build your project
2:You're going to be able to see exactly what happened
Stackoverflow question:
Kotlin 1.2.50 asks for baseFeatureInfoDir
Issue tracker:
https://issuetracker.google.com/issues/110198434
remove apply plugin: 'kotlin-kapt'
add mavenCentral() in build.gradle like:
allprojects {
repositories {
mavenCentral()
google()
jcenter() } }
Sync and Clean project
Here is the some approach how I fix this issue for my case:
First of all update your android gradle plugin version from project build gradle file and then update your gradle version from gradle properties.
Finally update your kotlin version(Mandatory) to kotlin_version = '1.2.30' or later from project build gradle file.
Now try to clean your project and build. Issue should be resolved.
Each time after build if you build again then probably issue will occur again so, just clean your project again and then build.
This happens because the Kapt annotation processor uses this directory to store Kotlin generated files. Android currently does not recognize the path by default.
See Further Details
Adding another answer for those who could not remove Instant App Provision, because it keeps reappearing.
Build the project manually: ./gradlew assembleDebug
It is a hotfix, but it will work (because the issue is probably related to Android Studio).
I had this issue when using Realm with kotlin in android studio.
To solve follow these steps :
After adding Realm to project build.gradle, Make sure your app build.gradle file is like this:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
.
.
.
androidExtensions {
experimental = true
}
Use kapt instead of annotationProcessor in your app build.gradle dependencies.
Go to Run -> Edit Configurations.. and remove Instant App Provision option.
Run this command in Android studio's terminal :
gradlew assembleDebug
It's OK !
Note: If you see "3rd-party Gradle plug-ins may be the cause" message again, Do step 3 & 4 again.
Configuration on demand with Gradle 4.6 and above: If you're using
Android Gradle Plugin 3.0.x or 3.1.x with Gradle 4.6 and above, you
should disable configuration on demand to avoid some unpredictable
build errors. (If you are using Android Gradle Plugin 3.2.0 or higher,
you do not need to take any action to disable configuration on
demand.)
Disable configuration on demand in your gradle.properties file as
shown below:
org.gradle.configureondemand=false To disable configuration on demand
in the Android Studio settings, choose File > Settings (Android Studio
Preferences on Mac), select the Compiler category in the left pane, and clear the Configure on demand checkbox.
In Android Studio 3.2 Beta 1 and higher, the options for enabling
configuration on demand have been removed.
Please read known issues section from below link.
enter link description here
Actually,I was also facing the same error.
What i did is updating my kotlin version to the latest.
This may resolve Your problem.
Well, I found it is because of apply plugin: 'kotlin-kapt',if you delete this line in build.gradle(app), then you will build successfully...
Have no idea why this plugin results in these warnings.

Android archive library integration using Maven

I am trying to integrate an Android archive (aar) from local Maven to Android studio in my sample project.
I am getting the following build error in Android studio:
A problem occurred evaluating project :app Could not find property HOME on org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository_Decorated#181db40.
If you are using local maven to work with android studio you need to do this means that to add a reference to an .aar package it would have to ideally be stored in the central maven repository.
A simple and extremely straightforward option is to create a local maven repository on your dev machine, and install your library in there. Then reference it from your gradle build. And doing it is surprisingly simple!.
Since you're developing for android, I assume you already installed the latest JDK and set the JAVA_HOME environment variable, but if you didn't - now is the time.
Then you'd want to install Maven. You can download it here: http://maven.apache.org/download.cgi
Set the MAVEN_HOME environment variable to the path where you extracted maven, and add the maven's bin folder to the PATH environment variable.
To test that maven is working fine, open a new console window and run the following:
mvn -version
If everything is fine, it's time to add your library to the maven repository. In the command prompt run the following:
mvn install:install-file -Dfile=d:\mylibrary-{version}.aar -DgroupId=com.example -DartifactId=mylibrary -Dversion={version} -Dpackaging=aar
Don't forget to replace the proper path to your library, setting your groupId, artifactId and version number.
Finally, edit your build.gradle to start looking at the local maven repository. For example, if you want to use both maven central and your local repo you can add both of them to the repositories configuration.
Here's an example of a very basic build.gradle for an android app using the library we registered above:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile('com.example:mylibrary:0.2')
}
android {
compileSdkVersion 17
buildToolsVersion '17.0.0'
}
Finally, run the build command to build your app:
gradle clean build.
The main problem is to get the resulting .aar file in the maven publication profile. To do that we'll run a call to android.libraryVariants, which will initialise this object, and create all the subtasks required for the build, including "bundleRelease" which is creating the .aar file.
Here is what my build.gradle file looks like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android-library'
apply plugin: 'maven-publish'
version '0.2'
group 'com.example'
android {
compileSdkVersion 17
buildToolsVersion '17.0.0'
defaultConfig {
versionCode 2
versionName '0.2'
}
}
android.libraryVariants
publishing {
publications {
maven(MavenPublication) {
artifact bundleRelease
}
}
}
If you want to change the artifactId to something custom, you can change the project name in settings.gradle by adding this line:
rootProject.name = 'mylibrary'
That's it. Now open a command prompt in your project's folder and run the following to build and publish your library to the local maven repository:
gradle clean build publishToMavenLocal
A couple basic articles that I used to get this to work:
How to install maven on windows.
Adding local .aar to gradle build

How do I upload an aar library to Nexus?

I have an Android aar library I am using with an Android application. It is working correctly with the aar library included directly in the Android project. I would like to move this library to my internal Nexus maven repository, so that other developers can use the library too.
How do I upload the aar to Nexus (the Maven repository)? There is no apparent option to do so in the web interface:
For Android, we normally have two build.gradle files the one at the top level folder, and another one in the specific module:
app/
---build.gradle
---module/
------build.gradle
In the app/build.gradle file of the clients of this library you will have to add:
repositories {
jcenter()
maven {
url "http://localhost:8081/repository/test-maven-repo/"
}
}
For you library app/module/build.gradle file:
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "http://localhost:8081/repository/test-maven-repo/") {
authentication(userName: "admin", password: "admin123")
pom.groupId = "com.example.test"
pom.artifactId = "myexample.test"
pom.version = '1.0.0'
}
}
}
}
And you might want to run it just with:
./gradlew upload
Link to official documentation:
Maven Publish Plugin.
I used gradle's maven plugin to upload to Nexus by modifying the Android build.gradle file.
apply plugin: 'maven'
dependencies {
deployerJars "org.apache.maven.wagon:wagon-http:2.2"
}
uploadArchives {
repositories.mavenDeployer {
configuration = configurations.deployerJars
repository(url: "https://my.example.com/content/repositories/com.example/") {
authentication(userName: "exampleUser", password: "examplePassword")
pom.groupId = "com.example"
pom.artifactId = "myexample"
pom.version = '1.0.0'
}
}
}
To upload: gradlew upload, using the gradlew script that is provided by the Android Studio project.
You can also move the authentication parameters into a file that is not version controlled.
Use maven deploy plugin. Example command:
mvn deploy
This assumes you have correctly configured your pom.xml with distributonManagement section, telling all it needs to know about your Nexus repo
If you're that kind of people who dislike changing your pom.xml, or worse if your code doesn't even have pom.xml but you still want to upload to Nexus anyway, then you can still do it using
mvn deploy:deploy-file -Durl=http://mycompany/nexus/repo/blah -Dfile=/path/to/my/foo.aar -Dpackaging=aar -DgroupId=com.mycompany -DartifactId=foo -Dversion=1.2.3
Refer to maven deploy plugin doc for more info: https://maven.apache.org/plugins/maven-deploy-plugin/
If you are building your project using Gradle, here there is a good tutorial to push your artifacts to Nexus:
https://medium.com/#scottyab/how-to-publish-your-open-source-library-to-maven-central-5178d9579c5#.acynm6j49
Basically, it adds a new Gradle task (uploadArchives) to push your artifacts. So doing something like:
>gradle clean build uploadArchives
You can upload it with Maven or Gradle or manually.
For the manual upload you can just type the package value in the input to be 'aar' and upload as you desire.
It doesn't make any sense that why nexus package have nothing for #aar file but if you try to upload it as a jar then it will not block you and everything is work as it is..

Install library module jar to local maven repository

I am migrating from Eclipse & maven to Android Studio & Gradle build.
My project structure now in Android Studio looks like this:
MyApp
->LibModule
-src
-...
-lib_repo/
-build.gradle
->AnotherModule
...
LibModule is my library module, I want to install the build jar of LibModule to my local maven repository. What I tried in build.gradle (under LibModule/ )is:
apply plugin: 'android-library'
apply plugin: 'maven'
...
group = 'com.my.lib'
uploadArchives {
repositories {
description "Installs the artifacts to the local Maven repository."
mavenDeployer {
repository(url: "file://${System.properties['user.home']}/.m2/repository")
pom.version = '1.1.0'
pom.artifactId = 'MyLib'
}
}
}
}
I also tried:
install {
repositories.mavenInstaller {
pom.version = '1.1.0'
pom.artifactId = 'MyLib'
}
}
I got error "unsupported Gradle DSL method found 'install()'! ".
When I build it in Android Studio IDE, in gradle console, I didn't see anything happen to upload the archive to my local maven repository. I also checked the content of build/ directory, there is no poms/ folder at all. It seems it is not triggered, I followed the gradle document here. Why? What is wrong?
For installing to the local Maven repository (which is mainly useful when exchanging artifacts with local Maven builds), use the install task rather than uploadArchives. For details, check the Gradle User Guide.

Android Gradle build, Android Plugin version

I know that the Android Plugin version and the Gradle version
have to "match", or it wants you to use a specific version of Gradle.
So my question is, how can I find what version, '0.9.2', of the Android Plugin
it wants in:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.2.+'
}
}
apply plugin: 'android'
I've found that if the version is "close enough" it will download/update what
it needs to make it happy, otherwise it'll give you an error.
So is there any command I can issue, or file to look at, that will
tell me what version to put in place of '0.9.2' so that I can
do a 'gradle build' with the version of Gradle that I have installed?
And I want to be able to just run 'gradle' and not 'gradlew.bat'
Thanks!

Categories

Resources