【发布时间】:2017-07-18 22:38:54
【问题描述】:
假设我有以下 build.gradle
android{
defaultConfig{
applicationId "com.example.base"
}
buildTypes{
release{
minifyEnabled true
}
debug{
applicationIdSuffix ".dev"
minifyEnabled false
}
}
productFlavors{
free{
applicationId "com.example.free"
}
paid{
applicationId "com.example.paid"
}
}
}
我想将生成的应用程序 ID 添加到 strings.xml,如下所示:
resValue "string", "app_package", applicationId
然后我可以在首选项 xml 中定义的意图 targetPackage 中使用此值
但值会根据我将该行放入的块而变化:
- defaultConfig -> “com.example.base”(始终是基本 ID,无用)
- productFlavours.free -> "com.example.free"(问题是这个不会改变为调试版本的“com.example.free.dev”)
- productFlavors -> 错误,无法构建
- buildTypes.debug -> 错误,无法构建
通过使用 applicationIdSuffix,我需要 gradle 解析最终的 id 才能使用它。我该怎么做?
【问题讨论】:
标签: android gradle android-gradle-plugin android-resources android-flavors