Android 如何在build.gradle中使用最终解析的applicationId
假设我有下面的版本Android 如何在build.gradle中使用最终解析的applicationId,android,gradle,android-gradle-plugin,android-resources,android-flavors,Android,Gradle,Android Gradle Plugin,Android Resources,Android Flavors,假设我有下面的版本 android{ defaultConfig{ applicationId "com.example.base" } buildTypes{ release{ minifyEnabled true } debug{ applicationIdSuffix ".dev" minifyEnabled false
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
因此,我可以在preferences xml中定义的intentstargetPackage
中使用该值
但值的变化取决于我将该行放入的块:
- defaultConfig->“com.example.base”(始终是基Id,无用)
- productFlavours.free->“com.example.free”(问题是,对于调试版本,不会更改为“com.example.free.dev”)
- productFlavours->错误,不生成
- buildTypes.debug->错误,不生成
freeDebug
build中,这将添加到app/intermediates/res/merged/free/debug/values/values.xml中:
<string name="app_package" translatable="false">com.example.free.dev</string>
<string name="app_package" translatable="false">com.example.free.dev</string>
<string name="app_package" translatable="false">com.example.paid.dev</string>