[英]Retrieve the applicationId of a different flavor?
I would like to get the full name of the applicationId for the flavor pro dynamically in my java code, which I compile with the free or pro environment. 我想在我的Java代码中动态获取flavour pro的applicationId的全名,该代码是使用free或pro环境编译的。 Do you know if it's possible without making a new variable manually?
您知道不手动创建新变量是否有可能?
Actually my build.gradle file: 实际上我的build.gradle文件:
defaultConfig {
applicationId "com.test.example"
buildConfigField "String", "PRO_APPLICATION_ID", "\"com.test.example.pro\""
...
}
flavorDimensions "tier"
productFlavors {
free {
applicationIdSuffix = ".free"
versionNameSuffix "-free"
}
pro {
applicationIdSuffix = ".pro"
versionNameSuffix "-pro"
}
}
Try context.getPackageName()
to get the whole application Id from an instance of Context for the compiled variant. 尝试使用
context.getPackageName()
从Context实例获取已编译变体的整个应用程序ID。
For accessing applicationId of pro flavor while running a free-variant there isn't a way except for adding a BuildConfig field during compile-time 要在运行自由变量时访问具有专业性的applicationId,除了在编译时添加BuildConfig字段外,没有其他方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.