问题描述
我想使用摇篮发布插件在 Android项目
。
我配置它,一切都没有问题,除了一件事:
摇篮发布插件
在其任务之一 gradle.properties
文件更改项目版本,但这种变化不会不影响 Android项目的
VERSIONNAME
,因为当我发现使用的println()
摇篮初始化它运行任何任务之前。
有没有办法来改变 Android项目
VERSIONNAME
在它被初始化后,一些摇篮任务?
下面是我的一部分 build.gradle
安卓{
compileSdkVersion 19
buildToolsVersion '19 .1.0
defaultConfig {
的minSdkVersion 14
targetSdkVersion 19
版本code 213
VERSIONNAME版本//改变它,请访问gradle.properties文件
的println(Project版本:'+版本)//这一行之前的任何摇篮任务执行:(
}
...
}
我可以看到只有一个解决方案:不同的摇篮执行
- 将改变版本gradle.properties
- 将执行的构建过程,但是这是不好的解决方法尤其适用于
摇篮发布插件
由于2.1.0版本的 gradle-发布插件正在执行建立在一个单独的进程。这可以确保版本是正确的整个构建过程以及依赖于版本从一开始就被设定的所有其他插件。
I want to use Gradle Release Plugin in Android Project
.
I configured it and everything is okay, except one thing:
Gradle Release Plugin
changes project version in gradle.properties
file in one of its tasks, but this change does not affect Android Project's
versionName
, because as I found with using println()
gradle initialising it before running any tasks.
Is there a way to change Android Project
versionName
in some gradle task after it was initialised?
Here is part of my build.gradle
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 213
versionName version // to change it, please visit gradle.properties file
println('Project version: ' + version) // this line executed BEFORE any gradle task :(
}
...
}
I can see only one solution: different gradle executions
- Will change version in gradle.properties
- Will execute build process, but this is bad workaround especially for
Gradle Release Plugin
Since version 2.1.0 the gradle-release plugin is executing the build in a separate process. This ensures the version is correct throughout the build process and for all other plugins which rely on the version being set from the beginning.
这篇关于Android的建立与摇篮发布插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!