下面是我使用动态分配版本代码和版本名称到AndroidManifest.xml。它仅在使用ant构建时才有效,因此您必须先安装它。然后转到命令行中的项目目录并执行“android update project -p。”,它将创建用于使用ant构建的必要文件,如local.properties和build.xml。
然后打开的build.xml并将此内:
<target name="-pre-build" depends="-custom-git-version,-custom-manifest-version">
</target>
<!-- Packages the application. -->
<target name="-post-build">
<antcall target="-custom-restore-manifest"/>
<property name="suffix" value="${git.commits}-${git.version}.apk" />
<exec executable="sed" inputstring="${out.final.file}" outputproperty="out.final.renamedfile">
<arg value="s/\.apk/-${suffix}/" />
</exec>
<copy file="${out.final.file}" tofile="${out.final.renamedfile}" />
<echo>Final file copied to: ${out.final.renamedfile}</echo>
</target>
<!-- Custom targets -->
<target name="-custom-git-version">
<exec executable="sh" outputproperty="git.commits">
<arg value="-c" />
<arg value="git log --pretty=format:'' | wc -l" />
</exec>
<echo>git.commits: ${git.commits}</echo>
<exec executable="git" outputproperty="git.version">
<arg value="describe" />
<arg value="--tags" />
<arg value="--long" />
</exec>
<echo>git.version: ${git.version}</echo>
</target>
<target name="-custom-manifest-version">
<echo>Creating backup of AndroidManifest.xml</echo>
<copy file="AndroidManifest.xml" tofile="AndroidManifest.xml.antbak" preservelastmodified="true" />
<replaceregexp
file="AndroidManifest.xml"
match='android:versionCode="(\d+)"'
replace='android:versionCode="${git.commits}"' />
<replaceregexp
file="AndroidManifest.xml"
match='android:versionName="(\d+\.\d+)\.\d+"'
replace='android:versionName="\1.${git.commits}"' />
</target>
<target name="-custom-restore-manifest">
<echo>Restoring backup of AndroidManifest.xml</echo>
<move file="AndroidManifest.xml.antbak"
tofile="AndroidManifest.xml"
preservelastmodified="true"
overwrite="true" />
</target>
的这个输出是不正是你想要的,但它是一个开始 - 随意修改:)结果像“yourapp - APK
使用此你会与执行来构建应用程序” 蚂蚁干净调试“或‘蚂蚁干净发布’,这取决于你想要什么你也可以创造。” 个ant.properties“文件与此内容:
key.store=keystore_file
key.store.password=some_password
key.alias=some_alias
key.alias.password=some_other_password
,使您的应用程序的自动签名。
你也应该阅读:如果使用Maven http://developer.android.com/tools/building/building-cmdline.html
不错...我也期待答案.. – prakash
易一块,看看manifestVersionCode和manifestVersionName [这里](HTTP:// Maven的Android的插件-m2site.googlecode.com/svn/manifest-update-mojo。HTML)。 – yorkw