在游戏开始之前,我已经能够通过脚本文件自动将我的versionCode更改为androidmanifest.xml中的内部版本号用作我当前的git提交号。但由于特殊原因,我不想使用versionCode作为我的游戏版本号。我想使用除versionCode和VersionName以外的东西,我可以在游戏开始之前通过脚本保存我的git提交号码,之后我可以在游戏中读取该值并显示在游戏中。所以我需要两件事
我使用以下脚本来更改清单
中的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
感谢您的帮助。谢谢!
答案 0 :(得分:1)
答案 1 :(得分: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()来执行此操作,但如果您正在获取数据,则可以使用您的活动上下文。
答案 2 :(得分:0)
我设法更改了之前发布的脚本。我还在清单文件中创建元数据,并通过以下脚本更改其值。谢谢你的帮助干杯! 这是改变
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&gt; new $ manf&amp;&amp; cp new $ manf $ manf&amp;&amp; rm -f new $ manf