Using AndroidManifest.xml version code in ant

Does anyone know if it is possible to get variables from AndroidManifest.xml for ant to use ?

In particular, I'm trying to get versionCode, versionNameand packageNamesomehow.

Thanks in advance.


Conclusion

This seems to be too troublesome to do, and since this problem is easily resolved with Maven, I have given up the possibility of a quick fix for now.

+3
source share
2 answers

Perhaps there is a special solution for Android that I don’t know, but besides this, you can consider the android manifest file as any other XML file β†’ so you only need the ant task to parse the XML file and get the values ​​from it.

ant java - -, .

. xml ANT

( http://www.oopsconsultancy.com/software/xmltask/):

<target name="retrieveFromManifest" desciption="retrieveFromManifest">
    <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
    <xmltask source="${pathToAndroidManifestFile}">
        <copy path="/manifest/@android:versionCode" property="androidVersionCode"/>
        <copy path="/manifest/@android:versionName" property="androidVersionName"/>
        <copy path="/manifest/@package" property="androidPackage"/>
    </xmltask>
    <echo message="Version code: ${androidVersionCode}" />
    <echo message="Version name: ${androidVersionName}" />
    <echo message="package: ${androidPackage}" />
</target>

EDIT:

android project build.xml, xpath " ". android sdk <import file="${sdk.dir}/tools/ant/build.xml" />, :

<taskdef name="xpath"
        classname="com.android.ant.XPathTask"
        classpathref="android.antlibs" />

:

<xpath input="AndroidManifest.xml" 
                expression="/manifest/application/@android:hasCode"
                output="manifest.hasCode" default="true"/>
+5

:

<xmlproperty file="AndroidManifest.xml" prefix="mymanifest" collapseAttributes="true"/>

:

${mymanifest.manifest.android:versionName}
+3

All Articles