使用build.gradle中定义的buildConfigField在build.gradle

时间:2016-04-27 11:52:31

标签: android android-gradle build.gradle

我的build.gradle中有下一段代码:

productFlavors {
        //DIMENSION - APP
        slid {
            dimension "app"
            applicationId "com.slid"
            versionCode 1
            versionName "1.0.0"

            manifestPlaceholders = [one_app_id : "273e0-b8f-4c7f-87-0f4eb68da"]
        }
}

我想要做的是从我的java代码中的one_app_id访问manifestPlaceholders

由于我无法这样做(或者至少我无法找到方法),我想要定义一个buildConfigField String,其值273e0-b8f-4c7f-87-0f4eb68da但是我'我想把它作为manifestPlaceholders/one_app_id的引用,所以我不会两次写ID。

我的问题是: buildConfigField "String", "ONE__ID", '[reference_here]' 我应该设置什么而不是[reference_here]

我该如何操作,即将ID设置为buildConfigField,然后在manifestPlaceholder中设置该引用 例如manifestPlaceholders = [one_app_id: [?!reference_here?!]]

P.S。不用担心,ID无效:)

1 个答案:

答案 0 :(得分:0)

根据CommonsWare的建议,我设法做到了这样:

ext {
    oneAppId = ""
}

android {

   productFlavors {
            //DIMENSION - APP
            slid {
                dimension "app"
                applicationId "com.slid"
                versionCode 1
                versionName "1.0.0"

                ext.oneAppId = '"273e0-8567-558da"'
                manifestPlaceholders = [one_app_id : ext.oneAppId] //Used by the third party library
                buildConfigField "String", "ONE_APPID", ext.oneAppId //I'll use this in java
            }
    }

}