0

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.

balsick
  • 1,099
  • 1
  • 10
  • 23

1 Answers1

1

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'

balsick
  • 1,099
  • 1
  • 10
  • 23
  • 1
    But it's not an answer to your question. You simply run "customer1" flavor in "debug" build type. But no other build type works with metro :) The question remains open - how to make custom build type work with metro. – Ross Sep 07 '22 at 13:05
  • @RossIvantsiv you may be right, depending on the actual question. This answer answers to the final goal, though it does not to the question "how to make custom build type work with metro" – balsick Sep 08 '22 at 14:21