わかりました。新しいAndroid ビルド システムに関する Xavier Ducrohet の YouTube ビデオを見てきました。私は Android Studio の使用に切り替えましたが、満足しています。ここで、ビルド ルールをカスタマイズして、自分のやりたいように処理する必要があります。そのうちの 1 つで、マニフェスト ファイルにcodeVersion
andが自動的に設定されます。codeName
Xavier は、スライドの 1 つでこれを行う方法の開始を示しています。
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
次のスクリプトを試しましたが、成功しませんでした。問題なくビルドできますが、インストールしたアプリの [アプリ情報] ページのバージョン名が変わりません。
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 getVersionName()
構成を置き換えるversionName 'Some Text'
と、機能し、ビルド名がSome Text
アプリ情報になります。では、なぜ getVersionName 関数が機能しないのでしょうか?
更新 2
まだ機能していませんが、ほとんどです!
シェルスクリプト:
#/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}
これは機能し、ログ行は、プロジェクトの作成時にスクリプトが複数回呼び出されることを確認します。しかし、versionName はまだ空白のままです。まだ stdout を取得していないのは 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()
}
}