自动版本编号的Andr​​oid应用程序使用Git和Eclipse [英] Auto Version numbering your Android App using Git and Eclipse

查看:151
本文介绍了自动版本编号的Andr​​oid应用程序使用Git和Eclipse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信计算机是做重复任务的最好的事情。我当然我不是,我不是忘了,或(大部分)不以一致的方式做的事情 - 这是不是我想要的。

I believe that computers are the best things for doing repetitive tasks. I certainly am not, I either forget, or (mostly) don't do things in a consistent way - which isn't what I want.

有一件事我可能会做的是忘记了清单中的版本信息,当我发布的Andr​​oid应用程序的新版本。在过去我曾与具有自动版本编号功能配置构建系统的工作,我得到了使用它(或者也许我偷懒)。

One of the things I am likely to do is forget to up the version information in the manifest when I publish a new version of an Android app. In the past I've worked with configured build systems that have a auto version numbering feature and I got use to it (or maybe I got lazy).

我发现这个<一href="http://stackoverflow.com/questions/6758685/auto-increment-version-$c$c-in-android-app">Stackoverflow帖子非常有用想出一个解决方案,但我花了一段时间来微调它,所以它的工作原理只是他们的方式我想它。较早尝试将某个时候导致继续建设,这是一个痛苦。所以,我想我会在这里发布我的解决方案,希望别人会发现它很有用。

I found this Stackoverflow post very useful in coming up with a solution, but it took me a while to fine tune it so it works just they way I want it. Earlier attempts would sometime cause continues building, which was a pain. So I thought I would publish my solution here in the hope that someone else will find it useful.

推荐答案

此溶液在Linux上开发的。我敢肯定,熟练的Windows和放大器;苹果开发者可以使其适应自己的平台,但我不是这样的开发商。 Linux是在我的技能的生活。

This solution was developed on Linux. I'm sure skilled Windows & Mac developers can adapt it to their platforms, but I am not such a developer. Linux is where my skill set lives.

Git有在 git的一个很好的功能描述--dirty 命令。它扫描回落提交日志,发现该标签,然后从那里建立一个版本字符串。如果这是一个生产建设,其中最后一次提交已被标记,所有文件都在被选中,那么这是你的版本字符串。如果这是一个开发版本则最后一个标签附加有额外提交的数量和缩写的散列code。该 - 脏标志只是蛋糕上的糖霜樱桃:追加字如果有没有承诺还没有任何修改过的文件。这是完美的你机器人:VERSIONNAME 清单文件的属性。

Git has a nice feature in the git describe --dirty command. It scans back down the commit log and finds the tag and then builds a version string from there. If this is a "production build" where the last commit has been tagged and all files have been checked in then that is your version string. If this is a development build then the last tag is appended with the number of additional commits and an abbreviated hash code. The --dirty flag is just the cherry on the icing on the cake: it appends the word dirty if there are any modified files not committed yet. This is perfect for your android:versionName attribute in the manifest file.

对于安卓版本code 若干要求。这需要时钟版本而不是开发版本,并为每一个版本的将会的有一个版本字符串我简单地计算这些标签。我总是标记我的版本的形式 V&LT;大&GT;&LT;轻微&GT;&LT;。补丁&GT;] ,其中&LT;大&GT; &LT;轻微&GT; &LT;补丁&GT; 只是数字。所以计数开始的小写V的标签,随后以一个数字都算的上是所有这就是必须。

For the android:versionCode a number is required. This needs to clock for releases but not for development build, and as every release will have a tag with a version string I simply count these. I always tag my versions in the form v<major>.<minor>[.<patch>] where <major>, <minor> and <patch> are just numbers. So counting tags that start with a lower case 'v' followed with a digit are counted is all thats really needed here.

与模板清单文件尾部后,我发现,最好的方法是简单地使用AndroidManifest.xml文件中的项目基地,使用流编辑器编辑 SED 和存放于斌/ AndroidManifest.xml中的结果。

After trailing with a template manifest file I discovered that the best way was to simply use the AndroidManifest.xml file in the project base, edited using the stream editor sed and deposit the result in bin/AndroidManifest.xml.

所以,我开发下面的脚本,把它放在一个脚本文件夹在同一级别为我的项目(​​使他们能够共享相同的脚本),然后配置在Eclipse中自定义生成器。

So I developed the script below, placed it in a scripts folder at the same level as my projects (so that they can all share the same script) and then configured a custom builder in Eclipse.

有我称之为 version.sh 脚本:

#/bin/bash

echo "Auto Version: `pwd`"

CODE=`git tag | grep -c ^v[0-9]`
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

echo "   Code: ${CODE}"
echo "   Ver:  ${VERSION}"

cat AndroidManifest.xml | \
    sed -e "s/android:versionCode=\"[0-9][0-9]*\"/android:versionCode=\"${CODE}\"/" \
        -e "s/android:versionName=\".*\"/android:versionName=\"${VERSION}\"/" \
    > bin/AndroidManifest.xml

exit 0

要配置建设者这里的步骤:

To configure the builder here are the steps:

1)。右键单击该项目基地,并选择属性,然后在建设者。

1). Right click the project base and select "Properties" and then "Builders".

2)。点击新建按钮,选择程序选项。

2). Hit the "New" button and select the "Program" option.

3)。命名您的版本类似&LT;项目&GT;自动版本。此字符串需要在所有项目中是唯一的。

3). Name your version something like "<project> Auto Version". This string needs to be unique across all projects.

4)。配置主要选项卡,如下所示:

4). Configure the "Main" tab as follows:

4a)中。在位置部分使用浏览文件系统,并浏览并选择脚本文件。

4a). In the "Location" section use "Browse File System" and navigate and select the script file.

图4b)。在工作目录部分使用浏览工作区,选择该项目。

4b). In the "Working directory" section use "Browse Workspace" to select the project.

5)。选中在刷新选项卡完成后刷新资源离开。

5). Leave the "Refresh resources upon completion" unchecked in the "Refresh" tab.

6)。不要设置任何变量,在环境选项卡。

6). Don't set any variables up in the "Environment" tab.

7)。在构建选项选项卡:

7). In the "Build Options" tab:

图7a)。确保在手动建立打勾,以及

7a). Make sure that "During manual builds" is ticked, and

图7b)。这在自动构建也选中。

7b). That "During auto builds" is also ticked.

图7c)。我现在拥有一切左​​边选中。我甚至不分配控制台它。鹰看着那里可能已经发现,该脚本确实输出一些信息,但现在我已经得到了它的工作我只是想事情不会困扰我默默运行。

7c). I now have everything else left unselected. I don't even allocate a console to it. The eagle eyed out there may have spotted that the script does output some information, but now I've got it working I just want the thing to run silently without bothering me.

8)。好吧构建设置,然后位置之间的建设者的Andr​​oid pre-编译和Java构建器。

8). Okay the build settings and then position your builder between "Android Pre-Compile" and "Java Builder".

回到开发你的应用程序安全的,因为它们被正确版本的知识,并检查了你的应用程序的信息。这不就是版本号凉爽。 : - )

Go back to developing your apps safe in the knowledge that they are being properly versioned, and check out your app's info. Isn't that version number cool. :-)

史蒂夫

这篇关于自动版本编号的Andr​​oid应用程序使用Git和Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆