Android:如何在 ant 命令行构建期间传递版本信息?

标签 android android-build

当我使用 Ant 在命令行中构建 Android 项目时,我想更新 AndroidManifest.xml 文件中的 android:versionCode 和 android:versionName。有什么方法可以使用属性文件注入(inject)版本号吗?

最佳答案

您可以通过多种方式设置版本信息,

  1. 作为命令行参数传递
  2. 使用属性文件。

作为命令行参数传递,

 <target name="set-version-using-commandline-args">
    <!-- Load properties from "version.properties" file -->     
    <replaceregexp file="AndroidManifest.xml" match="android:versionCode(.*)" 
        replace='android:versionCode="${Version.Code}"'/>
    <replaceregexp file="AndroidManifest.xml" match="android:versionName(.*)" 
        replace='android:versionName="${Version.Name}"'/>       
</target>

然后像这样运行ant build,

ant -DVersion.Code=100 -DVersion.Name=5.0.0.1201011 debug 

如果您想使用属性文件传递版本信息,请使用此目标,

 <target name="set-version-using-file">
    <!-- Load properties from "version.properties" file -->             
    <property file="version.properties" />

    <replaceregexp file="AndroidManifest.xml" match="android:versionCode(.*)"
        replace='android:versionCode="${Version.Code}"'/>
    <replaceregexp file="AndroidManifest.xml" match="android:versionName(.*)"
        replace='android:versionName="${Version.Name}"'/>       
</target>

有关详细说明,请参阅此博客文章。 Android: How to version command line build?

关于Android:如何在 ant 命令行构建期间传递版本信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14161564/

相关文章:

java - FRONT_CAMERA 不支持 d 错误 : Video Chat Feature powered by Applozic

java - Android Sqlite 查询返回什么?

android - 在 fragment 中显示后退箭头

android - CoordinatorLayout 底部的工具栏

gradle - 如何解决 CIrcleCI 上的 gradlew ./assembleRelease 上未设置 $TERM 的问题?

android - 是否可以获得我的 Android 设备的源代码?

Android Gradle 构建生成的 apk 包含混淆和非混淆类

android - 来电屏幕上的弹出窗口,如 truecaller

flutter - 应用程序在使用 flutter 构建发布 apk 时停止工作,但在 razorpay 网关打开时在模拟器中工作

Android Studio : Switching a URL depending on buildtype?(用于调试/发布测试)