How to include version string in the filename when building Android apk with ant?
Normally we build android package in debug mode with the command
ant debug
and got the apk filename Ap开发者_运维百科pName-debug.apk.
Is there any way to generate the apk file in the format of AppName-debug-<version-number>.apk
directly without 'mv' command?
Thanks.
I have done this in an automated way, by using the info from the Android manifest.
My approach was to modify the local project ant build.xml
file to import a custom copy of the master build.xml
file, in the latest version of the SDK the master file that is imported into your local file is located at <SDK>/tools/ant/build.xml
(was android_rules.xml in previous versions) Note the import
line in the default build.xml
file local to your project.
The comments in the local build.xml
created by the Android tools contain details on how to do customization, such that future updates to the tools will not break your changes.
In the custom rules file add:
<xmlproperty file="AndroidManifest.xml" prefix="mymanifest" collapseAttributes="true"/>
This reads in the manifest as a set of ant properties, with a custom prefix to ensure no name collision.
You can then add ${mymanifest.manifest.android:versionName} to any of the spots that the apk name is defined, just search for .apk
in the custom rules file.
I've used this process to automate versioning files from a build server.
With some additional tweaks it is also possible to have your release app signed automatically, buy setting the passwords in properties and using those in the signing task. The actual passwords where stored in a separate properties file that only lived on the build server. While a minor security risk, in some cases it is out weighed by the need for full end to end build automation.
Another, more Android-like solution is to use the XPATH task as it is done in the ${sdk.dir}/tools/ant/build.xml:
<xpath input="AndroidManifest.xml" expression="/manifest/@android:versionName"
output="versionName" default="unknown"/>
<echo message="name: ${versionName}"></echo>
This requires the definition of the task:
<path id="android.antlibs">
<pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
</path>
<taskdef name="xpath"
classname="com.android.ant.XPathTask"
classpathref="android.antlibs" />
I don't know which is the minimum SDK version, but it works with SDK14.
Regards, Michael
Solution described in the following post has custom_rules.xml file that can be just copied to achieve the desired result. http://jeffreysambells.com/2013/02/14/build-your-android-apk-with-the-manifest-version-number
Yes there is a way to generate apk file with any name i give a process to you fallow this process the you got .apk mention your name.
1-Right click on application in package explorer . 2-Chose export. 3-chose Android 4-Choose Export Android application. 5-Create new keystore . 6- fill the form. 7-: Give apk file name what you want 8-:give location to apk to store apk .
Then you find solution of your problem. I hope this is help.
精彩评论