我的code存储在SVN版本控制。我使用Eclipse来构建我的Android应用程序。
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约$关键字$早期的答案。
Thx for the early answers about $keywords$.
设置SVN属性 SVN:关键字
到修订
并展开私人字符串m_svn_rev =$修订:$。
我每次提交的是的文件
Setting the SVN property svn:keywords
to Rev
does expand a private String m_svn_rev = "$Rev:$"
every time I submit that file.
SVN是每个文件的版本控制系统。
SVN is a per-file version control system.
这导致,而不是怀疑我是否能以某种方式pre-过程中的一些文件在Android编译啄到svnversion,如果输出注入?
Which leads instead to wonder if I can somehow pre-process some files in the Android build thingy to inject svnversion output?
一个可行的方法。 在你的AndroidManifest.xml中添加元数据到你的活动,让修订或任何你想用
One possible approach. In your AndroidManifest.xml add metadata to your Activities to keep the revision or whatever you want to use
<activity android:name="SampleActivity">
<meta-data android:value="$Rev: 164 $" android:name="com.example.version" />
</activity>
然后在您的活动
then in your 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();
}
您可能还需要设置机器人:VERSIONNAME =$修订版$在你的清单
要自动递增的版本号 Android的过程:版本code
和提交的的AndroidManifest.xml
有各种选项,建设有行家
或蚂蚁
可能是替代品,但让我们使用Eclipse和ADT做到这一点。
To automate the process of incrementing the version number in 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.
首先,制造商添加到您的项目(我的项目 - >属性 - >建设者的)
First, add a builder to your project (My Project -> Properties -> Builders)
这建设者应该调用 Android的增量,清单版本
使用项目的的AndroidManifest.xml
作为参数
this builder should invoke the android-increment-manifest-version
using the project's AndroidManifest.xml
as the argument
Android的增量,清单版本的脚本是像
android-increment-manifest-version script is something like
#! /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