1

在游戏开始之前,我已经能够通过脚本文件将我的 versionCode 自动更改为 androidmanifest.xml 中的内部版本号为我当前的 git 提交号。但由于某种特殊原因,我不想使用 versionCode 作为我的游戏版本号。我想使用除 versionCode 和 VersionName 以外的东西,我可以在游戏开始之前通过脚本保存我的 git 提交号,然后在游戏期间我可以读取该值并在我的游戏中显示。所以我需要两件事

  1. 如何在 androidManifest 文件中创建一个额外的标签,我可以在其中保存这个值
  2. 以及在游戏运行之前更改要在脚本文件中使用的标记值的脚本

我使用以下脚本更改清单中的 versionCode 标记

newverfull=$(git --git-dir="../../.git" --work-tree="../../" rev-list master | wc -l)

manf=AndroidManifest.xml

newvers=`echo $newverfull | sed 's/[^0-9].*$//'`

vers=`sed -n '/versionCode=/s/.*"\([0-9][0-9]*\)".*/\1/p' $manf`

sed /versionCode=/s/'"'$vers'"'/'"'$newvers'"'/ $manf  >new$manf && cp new$manf $manf && rm -f new$manf

我感谢您的帮助。谢谢!

4

3 回答 3

1

我设法更改了我之前发布的脚本。我还在清单文件中创建了一个元数据,并使用下面的脚本更改了它的值。

谢谢您的帮助。干杯!


newverfull=$(git --git-dir="../../.git" --work-tree="../../" rev-list master | wc -l)
manf=AndroidManifest.xml
verbase=`echo $newverfull | sed 's/\(.*\.\)\([0-9][0-9]*\).*$/\1/'`
vername=`sed -n '/GameVersion/s/.*"\([^"]*\)".*/\1/p' $manf`
sed /GameVersion/s/'"'$vername'"'/'"'$verbase'"'/ $manf  >new$manf && cp new$manf $manf && rm -f new$manf

于 2012-12-13T08:20:33.020 回答
1

看看这个 shell 脚本。

https://github.com/eaglesakura/jenkins-script/blob/master/update-AndroidManifest.sh

于 2013-08-27T23:42:19.427 回答
0

这是一个例子。自定义标签是 GameVersion。

<application android:name=".MyApplication"
             android:icon="@drawable/icon"
             android:label="@string/app_name">

    <meta-data android:name="GameVersion" android:value="1.9" />

    <activity android:name="com.someone.something.MainActivity"
              android:theme="@android:style/Theme.Translucent.NoTitleBar"
              android:screenOrientation="sensor"
              android:label="@string/app_name">

要访问它:

    ApplicationInfo ai = _context.getPackageManager().getApplicationInfo(_context.getPackageName(),PackageManager.GET_META_DATA);
    ai.metaData.get("GameVersion")

如您所见,您需要一个上下文来获取对 PackageManager 的引用。我更喜欢使用 getApplicationContext() 来执行此操作,但如果您正在获取数据,则可以使用您的活动上下文。

于 2012-12-12T19:32:19.740 回答