嵌入版本细节在android APK [英] embed version details in android APK
问题描述
我的代码存储在SVN版本控制中。我使用Eclipse构建我的Android应用程序。
在我的应用程序中,我有一个约箱。我想要显示正确的源代码控制版本/标签/这个中的任何东西。
有没有一种自动化的方法,以便我的版本字符串在about-box中始终对,或者这是我每次提交时都要手动编辑的东西?
Thx是关于$关键字$的早期答案。
将SVN属性 svn:keywords
设置为修订版
扩展了一个 private String m_svn_rev =$ Rev:$
每次我提交 文件。
SVN是每个文件的版本控制系统。
哪个导致,想知道我是否可以以某种方式预处理Android构建的一些文件来注入svnversion输出?
一种可能的方法。
在您的AndroidManifest.xml中,您的活动中添加元数据以保留修订版本或您想要使用的任何内容。
活动android:name =SampleActivity>
< meta-data android:value =$ Rev:164 $android:name =com.example.version/>
< / activity>
然后在您的活动中
try {
final ActivityInfo ai = getPackageManager()。getActivityInfo(getComponentName(),PackageManager.GET_META_DATA);
final String version =(String)ai.metaData.get(com.example.version);
System.out.println(version:+ version);
} catch(NameNotFoundException e){
// TODO自动生成的catch块
e.printStackTrace();
}
您可能还想设置 要自动执行 首先,将一个构建器添加到你的项目中>我的项目 - >属性 - >建设者) 这个构建器应该调用 android-increment-manifest-version脚本就像 My code is stored in SVN version control. I use Eclipse to build my Android application. In my application, I have an about-box. I want to show the correct source control revision/tag/whatever in this. Is there a way of automating this so that my version string in the about-box is always right, or is this something I have to hand-edit each time I commit? Thx for the early answers about $keywords$. Setting the SVN property SVN is a per-file version control system. Which leads instead to wonder if I can somehow pre-process some files in the Android build thingy to inject svnversion output? One possible approach.
In your AndroidManifest.xml add metadata to your Activities to keep the revision or whatever you want to use then in your Activity You may also want to set To automate the process of incrementing the version number in First, add a builder to your project (My Project -> Properties -> Builders) this builder should invoke the android-increment-manifest-version script is something like
这篇关于嵌入版本细节在android APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! android:versionName =
中增加版本号的过程android:versionCode
并提交 AndroidManifest.xml
有各种选项,使用 maven
或 ant
可以是替代方法,但是我们来使用Eclipse和ADT。
android -increment-manifest-version
使用项目的 AndroidManifest.xml
作为参数
#! / bin / bash
#android-increment-manifest-version:
#增加AndroidManifest.xml文件中找到的版本号
#(android:versionCode =n)到位,承诺颠覆。
#
#版权所有(C)2010 Diego Torres Milano - http://dtmilano.blogspot.com
usage(){
echousage:$ PROGNAME AndroidManifest.xml>& 2
退出1
}
PROGNAME = $(basename $ 0)
如果[$# - ne 1]
然后
用法
fi
MANIFEST =$ 1
perl -npi -e'/ ^(。 * android:versionCode =)(\d +)(。*)$ /$ 1。 ($ 2 + 1)。 $ 3/ e;'$ MANIFEST
svn ci -m版本增加$ MANIFEST
svn:keywords
to Rev
does expand a private String m_svn_rev = "$Rev:$"
every time I submit that file.<activity android:name="SampleActivity">
<meta-data android:value="$Rev: 164 $" android:name="com.example.version" />
</activity>
try {
final ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
final String version = (String)ai.metaData.get("com.example.version");
System.out.println("version: " + version);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
android:versionName="$Rev$"
in your manifest.android:versionCode
and committing the AndroidManifest.xml
there are various options, building with maven
or ant
could be alternatives but let's do it using Eclipse and ADT.android-increment-manifest-version
using the project's AndroidManifest.xml
as the argument#! /bin/bash
# android-increment-manifest-version:
# increment the version number found in the AndroidManifest.xml file
# (android:versionCode="n") in place and commit it to subversion.
#
# Copyright (C) 2010 Diego Torres Milano - http://dtmilano.blogspot.com
usage() {
echo "usage: $PROGNAME AndroidManifest.xml" >&2
exit 1
}
PROGNAME=$(basename $0)
if [ "$#" -ne 1 ]
then
usage
fi
MANIFEST="$1"
perl -npi -e 's/^(.*android:versionCode=")(\d+)(".*)$/"$1" . ($2+1) . "$3"/e;' $MANIFEST
svn ci -m "Version incremented" $MANIFEST