React native 不使用metro的React本机自定义buildType
我需要为不同的ApplicationID构建相同的应用程序,这样我就可以在Play Store/app Store上发布它,作为我公司一些客户的私有应用程序 我决定使用React native 不使用metro的React本机自定义buildType,react-native,metro-bundler,react-native-config,React Native,Metro Bundler,React Native Config,我需要为不同的ApplicationID构建相同的应用程序,这样我就可以在Play Store/app Store上发布它,作为我公司一些客户的私有应用程序 我决定使用react native config,因为它应该允许我轻松地更改applicationId和一些env变量 我创建了一些.env.${variant}文件,即在以下示例中,.env.customer1 我已将所需的构建类型设置如下: ... buildTypes { debug { ... } cu
react native config
,因为它应该允许我轻松地更改applicationId
和一些env
变量
我创建了一些.env.${variant}
文件,即在以下示例中,.env.customer1
我已将所需的构建类型设置如下:
...
buildTypes {
debug {
...
}
customer1 {
initWith debug
applicationIdSuffix "customer1"
}
}
我强迫react.gradle在使用这些变体构建时不要绑定
project.ext.react [
bundleInCustomer1: false,
devDisabledInCustomer1: false
]
然后我使用这个命令行在我的物理设备上运行
copy .env.customer .env && react-native run-android --variant=customer1 --appIdSuffix 'customer1'
结果是该应用程序是在我的设备上构建和启动的,但我看到的是该应用程序的旧版本(可能是几周前我使用assembleRelease构建的最后一个版本),metro正在启动,但在我尝试强制重新加载时会告诉我这一点,否则什么也不会告诉我
warn No apps connected. Sending "reload" ...
我试过了,但没有成功
gradlew clean
npm start --cache-reload
npm cache clean --forced
npm i
构建没有任何变体的应用程序(因此使用默认调试)可以正常工作。多亏了,我成功地解决了我的问题
我现在使用的不是buildTypes
,而是flavors
所以
通过
react native run android--variant=customer1Debug--appIdSuffix'customer1'
android {
...
flavorDimensions "standard"
defaultConfig {
applicationId "com.stackoverflow"
...
productFlavors {
customer1 {
applicationId "com.stackoverflow.customer1"
dimension "standard"
}
}
}