嗨,我按照以下链接创建产品口味 在此处输入链接描述
我在风味中设置了一个变量,但无法在代码中访问它。
构建.gradle。
productFlavors {
production {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'com.xxx.production'
targetSdkVersion rootProject.ext.targetSdkVersion
resValue "string", "build_config_package", "com.myapp"
buildConfigField "boolean", "MOCK_VERSION", "false"
resValue "string", "MOCK_VERSION_ABCD", "false"
}
staging {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'com.xxx.staging'
targetSdkVersion rootProject.ext.targetSdkVersion
resValue "string", "build_config_package", "com.myapp"
buildConfigField "boolean", "MOCK_VERSION", "false"
resValue "string", "MOCK_VERSION_ABCD", "false"
}
t3st {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'com.xxx.test'
targetSdkVersion rootProject.ext.targetSdkVersion
resValue "string", "build_config_package", "com.myapp"
buildConfigField "boolean", "MOCK_VERSION", "true"
resValue "string", "MOCK_VERSION_ABCD", "true"
}
}
我试图在我的 Login.js 文件中访问它
import { BuildCofig } from 'react-native';
loginEndpointDecider = () => {
if(BuildCofig.MOCK_VERSION){
alert('MOCK_VERSION - true');
}else{
alert('MOCK_VERSION - false');
}
}
运行应用程序
react-native run-android --variant=stagingDebug
我正在尝试访问buildConfigField
MOCK_VERSION
.
您能否建议如何使其正常工作。
谢谢R