android - 如何使用 Azure Pipelines 自动增加 Android 应用的构建 ID 和版本号

标签 android azure-devops continuous-integration azure-pipelines continuous-delivery

这是我的 build.gradle

defaultConfig {
        applicationId "com.xyz.abc.na"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 36
        versionName "5.0.2"
        multiDexEnabled true
    }

在我的 YML 中,我有
 - task: android-manifest-version@1
  displayName: 'Version Update'
  inputs:
  sourcePath: '$(manifestDirectory)'
  versionCodeOption: 'buildid'
  versionCode: '$(Build.BuildId)'
  versionCodeOffset: '1'
  printFile: true

  - task: Gradle@2
    displayName: 'Building Gradle'
    inputs:
      workingDirectory: ''
      gradleWrapperFile: 'gradlew'
      gradleOptions: '-Xmx3072m'
      publishJUnitResults: false
      testResultsFiles: '**/TEST-*.xml'
      tasks: $(gradleTask)
      codeCoverageToolOption: 'None'
      javaHomeOption: 'JDKVersion'
      jdkVersionOption: 'default'
      jdkArchitectureOption: 'x64'
      checkStyleRunAnalysis: false
      findBugsRunAnalysis: false

除非我手动更改 versionCodeversionName在我的 build.gradle 中,这些值永远不会自动更新。

如何获取最新值,递增 1 并更新 build.gradle,然后从新版本代码和版本名称生成构建?

以下是对我不起作用的现有引用资料。

Ref1

Ref2

Ref3

最佳答案

要在本地进行,您可以按照以下步骤操作:

  • gradle.properties添加这 2 个属性
  • appVersionCode=1
    appVersionName="1.0"
    
  • build.gradle应用

  • 代替
    versionCode 36
    versionName "5.0.2"
    
    versionCode appVersionCode.toInteger()
    versionName appVersionName.toString()
    
  • 在您的 YAML 文件中添加 Gradle options并通过 $(MyAppBuildNumber)$(MyAppVersionNumber)通过变量
  • - task: Gradle@2
          inputs:
            ...
            options: '-PappVersionCode=$(MyAppBuildNumber) -PappVersionName=$(MyAppVersionNumber)'
            ...
    

    关于android - 如何使用 Azure Pipelines 自动增加 Android 应用的构建 ID 和版本号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62315203/

    相关文章:

    c# - 如何从azure应用程序服务访问 key 保管库

    azure-devops - 是否可以将 azure 管道连接到本地服务器?

    ios - 为 react-native ios 应用程序构建 ci/cd 管道 : How to run expo build in gitlab-ci?

    java - 在基于促销的ci环境中,如何处理项目的jira版本和maven版本控制

    ruby-on-rails - 使用适用于 Ruby on Rails 的 AWS CI/CI 流程进行部署

    android - ViewDataBinding getVariable?

    java - 即使按下停止按钮也无法停止警报响起

    azure-devops - 有没有办法在 Azure DevOps 查询中进行总估算和完成的工作?

    android - 为什么我在android内核中遍历内核模块中目录的dentry时不能正确提取所有文件名?

    android - 如何在 CMakeLists.txt 文件中获取 android 构建类型(调试、发布)作为变量,以便在 android studio 中进行外部 native 构建?