【问题标题】:How to read versioncode from manifest.xml in build.xml using ant如何使用ant从build.xml中的manifest.xml读取版本代码
【发布时间】:2012-02-15 10:17:54
【问题描述】:

我想将我的 apk 从 myapp-release.apk 重命名为 myapp-1.0.30.apk。我想在 build.xml 中执行此操作。我想阅读清单中的版本,然后重命名 apk。 我正在使用 ant 进行此操作。

谢谢, sneha

【问题讨论】:

    标签: android ant


    【解决方案1】:

    我找到了自己问题的答案:

    <path id="android.antlibs">
                <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
    </path>
    <taskdef name="xpath" classname="com.android.ant.XPathTask" classpathref="android.antlibs" />
    <xpath input="./AndroidManifest.xml" expression="/manifest/@android:versionName" output="manifest.versionName" />
    <echo message="versionName = ${manifest.versionName}" />
    

    【讨论】:

    • 在我的情况下,jar 位于 ${sdk.dir}/tools/lib/ant-tasks.jar :)
    【解决方案2】:

    只需使用来自 https://stackoverflow.com/a/5318044/130683 的宏定义并根据您的需要进行调整,这意味着:

    <macrodef name="mfgrep">
      <attribute name="jar"/>
      <attribute name="key"/>
      <attribute name="keysave"/>
        <sequential>
          <loadproperties>
            <zipentry zipfile="@{jar}" name="META-INF/MANIFEST.MF"/>
          </loadproperties>
          <echo>@{key} => ${@{key}}</echo>
          <property name="@{keysave}" value="${@{key}}"/>
        </sequential>
    </macrodef> 
    
     <!-- Grep a key from Manifest -->
     <mfgrep 
       jar="/home/gilreb/temp/test.jar"
       key="Specification-Version"
       keysave="foobar"
     />
    

    之后使用属性 ${foobar} 重命名您的文件:

    <move file="myapp-release.apk" tofile="myapp-${foobar}.apk"/>
    

    【讨论】:

      猜你喜欢
      • 2013-11-20
      • 2011-10-04
      • 2015-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多