【问题标题】:How to set buildConfigField parameters dynamically while building an apk through Jenkins如何在通过Jenkins构建apk时动态设置buildConfigField参数
【发布时间】:2018-05-04 14:01:25
【问题描述】:

我在 build.gradle 的 ProductFlavors 中有以下字段,

productFlavors {

    Flavor1 {
        applicationId "com.example.A"
        buildConfigField 'int', 'ID', '123'
    }
}

如何根据 Jenkins 提供的输入更新这两个字段?

提前致谢!!

【问题讨论】:

    标签: android android-studio jenkins android-gradle-plugin build.gradle


    【解决方案1】:

    您可以使用以下步骤:

    在您的应用级别 build.gradle:

    buildscript {
        ext{
            appId="com.example.A"
            Id=123 
        }
        ...
    }
    

    如下更改您的字段:

    productFlavors {
    
        Flavor1 {
            applicationId appId
            buildConfigField 'int', 'ID', "$Id"
        }
    }
    

    从 jenkins 传递参数:

    gradlew assesmbleFlavor1 -PappId="${APPLICATION_ID}" -PId="${ID}"

    其中${APPLICATION_ID}和${ID}是jenkins中定义的参数

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-30
      • 2021-06-03
      • 1970-01-01
      • 2016-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      相关资源
      最近更新 更多