简体   繁体   English

检索不同口味的applicationId?

[英]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 proapplicationId的全名,该代码是使用freepro环境编译的。 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.

相关问题 使用风味维度时设置 Android applicationId 的正确方法是什么? - What is the correct way to set Android applicationId when using flavor dimensions? 导致NPE的新(但不同)的Facebook ApplicationId - New (but different) Facebook ApplicationId causing NPE 相同类别的两种不同的产品风味 - This same class for two different product flavor Android批注处理-为不同的构建风格生成不同的代码 - Android annotation processing - generate different code for different build flavor 从kotlin引用时,Java文件的未解析引用具有不同的风格 - Unresolved reference for Java file in a different flavor when referencing from kotlin 无法解析不同风味android studio的方法'getAllUserGroupByName()' - Cannot resolve method 'getAllUserGroupByName()' of different flavor android studio 如何使用Gradle中的不同资源文件夹为每个flavor创建两个应用程序? - How to create two applications for each flavor with different assets folders in Gradle? 如何在 android 多风味项目中使用相同的 class 但不同的实现 - How to use same class but different implementation in android multi flavor project Android中的产品风味 - Product flavor inside flavor in Android 无法找到方法applicationId()作为参数? - Could not find method applicationId() for arguments?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM