React本地自定义buildType不使用metro



我需要为不同的应用程序ID构建相同的应用程序,以便将其作为我公司某些客户的私人应用程序发布在Play Store/app Store上。

我决定使用react-native-config,因为它可以让我轻松地更改applicationId和一些env变量。

我已经创建了一些.env.${variant}文件,也就是说,在下面的示例中,.env.customer1

我已将所需的buildTypes设置如下:

...
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'

结果是,该应用程序是在我的设备上构建和启动的,但我看到的是该应用程序的旧版本(可能是几周前我使用assemblyRelease构建的最后一个(,metro正在启动,但当我试图强制重新加载时会告诉我这一点,否则什么都不告诉我

warn No apps connected. Sending "reload" ...

我尝试了,但没有成功

gradlew clean
npm start --cache-reload
npm cache clean --forced
npm i

构建没有任何变体的应用程序(因此使用默认调试(可以正常工作。

多亏了这个答案,我成功地解决了我的问题。

现在我使用的不是buildTypes,而是flavors

所以,

android {
...
flavorDimensions "standard"
defaultConfig {
applicationId "com.stackoverflow"
...
productFlavors {
customer1 {
applicationId "com.stackoverflow.customer1"
dimension "standard"
}
}
}

通过发射

react-native run-android --variant=customer1Debug --appIdSuffix 'customer1'

最新更新