React native custom buildType not using metro

933 views Asked by At

I need to build the same app to different applicationIds so that I can publish it on the Play Store / App Store as private applications for some of the customers of my company.

I decided to use react-native-config, as it should allow me to change applicationId and some env variables easily.

I have created some .env.${variant} files, that is, in the following examples, .env.customer1.

I have set the needed buildTypes as follows:

...
buildTypes {
   debug {
      ...
   }
   customer1 {
      initWith debug
      applicationIdSuffix "customer1"
   }
}

I forced react.gradle not to bundle when building with these variants

project.ext.react [
   bundleInCustomer1: false,
   devDisabledInCustomer1: false
]

Then I use this command line to run on my physical device

copy .env.customer .env && react-native run-android --variant=customer1 --appIdSuffix 'customer1'

The result is that the app is built and launched on my device, but what I see is an old version of the app (probably the last one that I have built using assembleRelease, some weeks ago), metro getting launched but telling me this when I try to force a reload, otherwise telling me nothing

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

I tried without any success

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

Building the app without any variant (thus using default debug) correctly works.

1

There are 1 answers

2
balsick On BEST ANSWER

Thanks to this answer, I've succeeded in solving my issue.

Instead of using buildTypes now I'm using flavors.

So,

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

and launching via

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