好的,我已经观看了Xavier Ducrohet关于新的Android构建系统的YouTube视频。我甚至已经开始使用Android Studio并对其感到满意。现在我需要自定义构建规则以按照我的方式执行操作,其中之一是自动设置清单文件中的
请问有没有好的资源可以帮我填补这些空白呢?
更具体地说,我想运行像
谢谢
更新
我尝试了以下的
如果我用
Shell脚本:
这样做是有效的,日志行确认了在构建项目时脚本被多次调用。但是版本名称仍然为空。我怀疑问题出在Gradle方面,仍然无法得到标准输出。
codeVersion
和codeName
。Xavier在他的幻灯片中展示了如何开始执行此操作。def getVersionCode() {
def code = ...
return code
}
android {
defaultConfig {
versionCode getVersionCode()
}
}
请问有没有好的资源可以帮我填补这些空白呢?
更具体地说,我想运行像
git describe --dirty | sed -e 's/^v//'
这样的脚本来确定 versionName
,并且使用 git tag | grep -c ^v
来获取 versionCode
。谢谢
更新
我尝试了以下的
gradle.build
脚本,但没有成功。它可以正常构建,但是我的已安装应用程序的 App Info 页面上的版本名称没有改变。task getVersionName(type:Exec) {
commandLine '../scripts/version-name.sh'
//store the output instead of printing to the console:
standardOutput = new ByteArrayOutputStream()
//extension method stopTomcat.output() can be used to obtain the output:
ext.output = {
return standardOutput.toString()
}
}
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile project(':Common')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
versionName getVersionName()
}
}
如果我用
versionName 'Some Text'
替换配置文件中的versionName getVersionName()
,那么它就能正常工作了,并且在应用信息中构建名称变为Some Text
。那么为什么我的getVersionName函数不起作用呢?
更新2
仍然无法工作-但几乎可以!Shell脚本:
#/bin/bash
NAME=`git describe --dirty | sed -e 's/^v//'`
COMMITS=`echo ${NAME} | sed -e 's/[0-9\.]*//'`
if [ "x${COMMITS}x" = "xx" ] ; then
VERSION="${NAME}"
else
BRANCH=" (`git branch | grep "^\*" | sed -e 's/^..//'`)"
VERSION="${NAME}${BRANCH}"
fi
logger "Build version: ${VERSION}"
echo ${VERSION}
这样做是有效的,日志行确认了在构建项目时脚本被多次调用。但是版本名称仍然为空。我怀疑问题出在Gradle方面,仍然无法得到标准输出。
task getVersionCode(type: Exec) {
exec { commandLine '../scripts/version-code.sh' }
//store the output instead of printing to the console:
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}
}
task getVersionName(type: Exec) {
exec { commandLine '../scripts/grMobile/scripts/version-name.sh' }
//store the output instead of printing to the console:
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}
}
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile project(':Common')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
versionCode getVersionCode()
versionName getVersionName.output()
}
}