Android的建立与摇篮发布插件 [英] Android build with Gradle Release plugin

查看:163
本文介绍了Android的建立与摇篮发布插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用摇篮发布插件 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版本:'+版本)//这一行之前的任何摇篮任务执行:(
    }

    ...
}
 

我可以看到只有一个解决方案:不同的摇篮执行

  1. 将改变版本gradle.properties
  2. 将执行的构建过程,但是这是不好的解决方法尤其适用于摇篮发布插件
解决方案

由于2.1.0版本的 gradle-发布插件正在执行建立在一个单独的进程。这可以确保版本是正确的整个构建过程以及依赖于版本从一开始就被设定的所有其他插件。

  

2.1.0

     

...

     

常见的有:发行期间重构的构建过程中单独运行   处理。希望这将解决所有与某些其他问题   像新的插件Maven的发布或bintray插件。

     

普通:增加beforeReleaseBuild和afterReleaseBuild挂钩,这   无论是在相同的过程作为生成本身运行。

     

...

看到完整的更新

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

  1. Will change version in gradle.properties
  2. 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.

2.1.0

...

COMMON: Refactored the build process during release to run in separate process. This will hopefully resolve all the issues with certain other plugins like the new maven-publish or the bintray plugin.

COMMON: Added beforeReleaseBuild and afterReleaseBuild hook, which both run in the same process as the build itself.

...

see full changelog

这篇关于Android的建立与摇篮发布插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆