I want to install android library project to local maven repository. Here is build.gradle:
我想将android库项目安装到本地maven存储库。这是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.
所以我首先注意到的是,它试图将一些奇怪的原因作为APK部署在设备上。
Am I doing something wrong or is it just android-library plugin not compatible with maven plugin?
我做错了什么或只是android-library插件与maven插件不兼容?
5 个解决方案
#1
31
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.
编辑:请参阅github页面(https://github.com/dcendents/android-maven-gradle-plugin)获取最新说明并找到要使用的正确版本。最新的gradle版本不再适用原始说明。
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
我修改了maven插件以与android库项目兼容。请参阅github上的项目:https://github.com/dcendents/android-maven-gradle-plugin
Configure your android library projects to use it:
配置你的android库项目使用它:
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.
然后,您应该能够使用安装任务将aar安装到本地maven存储库中。
Hope this helps, if you find issues with the plugin please let me know on github and I'll fix it.
希望这有帮助,如果你发现插件的问题,请告诉我github,我会解决它。
#2
17
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).
详细说明CyclingSir的答案,我建议添加一个单独的“installArchives”任务。这也应该照顾你的自定义工件(例如来源)。
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.
请注意,使用Gradle Android插件v0.5.5时,gradle install仍会尝试在设备上安装某些内容。
#3
11
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
:
如果您不想使用自定义插件,可以使用更简单的解决方案。相反,只需使用其他名称重新创建安装任务。我称之为installArchives。将以下代码添加到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.
您现在可以运行gradle installArchives来在本地安装您的aar。
#4
6
UPDATE 2014-11-26
更新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.
下面的答案在撰写本文时是有意义的,当Android Build Tools的版本为0.5.5时。它现在很可能过时,可能不再起作用了。
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.
我已经亲自切换我的项目使用android-maven-plugin,如上面的答案所述,该插件也适用于最新版本的Android Build Tools。
THE ORIGINAL ANSWER FROM FEBRUARY 2014
2014年2月的原始答案
Publishing as AAR
作为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.
如果您不介意使用较旧版本的com.android.tools.build:gradle(即0.5.4),则可以使用此博客文章中描述的方法。不是根据adt-dev邮件列表中的讨论,这在0.5.5中不起作用。
Add the following lines to your build.gradle
:
将以下行添加到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:
要发布到本地maven存储库,请调用以下命令:
gradle publishToMavenLocal
Publishing as JAR
作为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.
如果您的Android库没有自定义资源并且可以作为JAR发布,那么您可以使用以下与0.5.5一起工作的build.gradle。
// 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:
要发布到本地maven存储库,请调用以下命令:
gradle publishToMavenLocal
#5
0
I just solved the issue by defining an upload archive as described here: Gradle documentation 52.6.2. Deploying to a Maven repository
我刚刚通过定义上传档案解决了这个问题,如下所述:Gradle文档52.6.2。部署到Maven存储库
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.
将人工制品部署到(在我的情况下是本地的)Maven回购中。我没有找到一种简单而灵活的方式来指定本地回购的网址,例如mavenLocal()但上面适合我的需要。
#1
31
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.
编辑:请参阅github页面(https://github.com/dcendents/android-maven-gradle-plugin)获取最新说明并找到要使用的正确版本。最新的gradle版本不再适用原始说明。
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
我修改了maven插件以与android库项目兼容。请参阅github上的项目:https://github.com/dcendents/android-maven-gradle-plugin
Configure your android library projects to use it:
配置你的android库项目使用它:
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.
然后,您应该能够使用安装任务将aar安装到本地maven存储库中。
Hope this helps, if you find issues with the plugin please let me know on github and I'll fix it.
希望这有帮助,如果你发现插件的问题,请告诉我github,我会解决它。
#2
17
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).
详细说明CyclingSir的答案,我建议添加一个单独的“installArchives”任务。这也应该照顾你的自定义工件(例如来源)。
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.
请注意,使用Gradle Android插件v0.5.5时,gradle install仍会尝试在设备上安装某些内容。
#3
11
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
:
如果您不想使用自定义插件,可以使用更简单的解决方案。相反,只需使用其他名称重新创建安装任务。我称之为installArchives。将以下代码添加到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.
您现在可以运行gradle installArchives来在本地安装您的aar。
#4
6
UPDATE 2014-11-26
更新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.
下面的答案在撰写本文时是有意义的,当Android Build Tools的版本为0.5.5时。它现在很可能过时,可能不再起作用了。
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.
我已经亲自切换我的项目使用android-maven-plugin,如上面的答案所述,该插件也适用于最新版本的Android Build Tools。
THE ORIGINAL ANSWER FROM FEBRUARY 2014
2014年2月的原始答案
Publishing as AAR
作为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.
如果您不介意使用较旧版本的com.android.tools.build:gradle(即0.5.4),则可以使用此博客文章中描述的方法。不是根据adt-dev邮件列表中的讨论,这在0.5.5中不起作用。
Add the following lines to your build.gradle
:
将以下行添加到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:
要发布到本地maven存储库,请调用以下命令:
gradle publishToMavenLocal
Publishing as JAR
作为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.
如果您的Android库没有自定义资源并且可以作为JAR发布,那么您可以使用以下与0.5.5一起工作的build.gradle。
// 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:
要发布到本地maven存储库,请调用以下命令:
gradle publishToMavenLocal
#5
0
I just solved the issue by defining an upload archive as described here: Gradle documentation 52.6.2. Deploying to a Maven repository
我刚刚通过定义上传档案解决了这个问题,如下所述:Gradle文档52.6.2。部署到Maven存储库
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.
将人工制品部署到(在我的情况下是本地的)Maven回购中。我没有找到一种简单而灵活的方式来指定本地回购的网址,例如mavenLocal()但上面适合我的需要。