Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you set mode with 'react-native start'? #2359

Closed
jpetersen23 opened this issue Apr 17, 2024 · 3 comments
Closed

How do you set mode with 'react-native start'? #2359

jpetersen23 opened this issue Apr 17, 2024 · 3 comments
Labels
question Further information is requested

Comments

@jpetersen23
Copy link

I'm trying to get Android flavors to work with the latest react-native and I can get it correctly reading mode when I run

react-native run-android --mode=productionrelease

But for the life of me, I cant figure out how to set the mode for

react-native start

as a result, when I try to open android I get an error:

Cannot locate tasks that match 'app:installDebug' as task 'installDebug' is ambiguous in project ':app'. Candidates are: 'installDevelopmentDebug', 'installDevelopmentDebugAndroidTest', 'installProductionDebug', 'installProductionDebugAndroidTest', 'installStagingDebug', 'installStagingDebugAndroidTest'.

I think its because gradle cant correctly figure out what mode I want it to run in, but reading the documentation, I cant find a way to make it work.

Older stackoverflow options had suggested hacking the cli to force it to use a custom install command, but I cant find in the CLI where that is even happening now.

https://stackoverflow.com/a/50704977

I've also found older versions of react-native that seem to have handled sending down variant, but that seems to have broken when it was switched to mode?

Here is a working example relying on variant: https://github.com/sdavid501/multiplatform

I believe I've also confirmed its not a problem with https://github.com/lugg/react-native-config by not integrating it and just doing the work of adding flavors breaks the command.

I've also made a very simple version running the following commands:
npx react-native@latest init ReactNativeConfigTestAppLatest

and then applying this patch to react flavors:

added_flavors.patch

Anyway I'm not sure where to take it at this point beyond figuring out how to hack the tool, which I'm hoping to avoid.

Thanks.

@szymonrybczak
Copy link
Collaborator

szymonrybczak commented Apr 17, 2024

hey @jpetersen23 if you want to specify --mode when running Android app from watch mode (while running yarn start) → you need to provide watchModeCommandParams inside your react-native.config.js, so you need to compose something like this:

module.exports = {
  project: {
    android: {
      watchModeCommandParams: ['--mode', 'whateverYouWant'],
    },
  },
}

@jpetersen23
Copy link
Author

Thanks @szymonrybczak that worked to get me passed the build error!

For future people who may look at my specific patch, the body of my react-native.config.js also required adding --appId to launch the right apk (if you use just a suffixId in your gradle which I didnt in my example, you can use --appIdSuffix):

module.exports = {
  project: {
    ios: {},
    android: {
      // https://github.com/react-native-community/cli/issues/2359#issuecomment-2061289989
      watchModeCommandParams: [
        '--mode',
        'developmentrelease',
        '--appId',
        'com.reactnativeconfigtestapplatest.development',
      ],
    },
  },
};

@jpetersen23
Copy link
Author

jpetersen23 commented Apr 17, 2024

Turns out I spoke too soon, I seem to have broken live reloading of tsx changes. Additionally when I hit r in watch mode (yarn start) I see:

warn No apps connected. Sending "reload" to all React Native apps failed. Make sure your app is running in the simulator or on a phone connected via USB.
info Reloading connected app(s)...

And nothing updates.

I confirmed the same is true if I run the commands directly as

react-native run-android --mode developmentrelease --appId com.reactnativeconfigtestapplatest.development

I also confirmed its not a debug mode thing by trying

react-native run-android --mode developmentdebug --appId com.reactnativeconfigtestapplatest.development

And that also doesnt cause it to live update again (or reload with R in the console or in the app itself).

UPDATE:

I needed to add things to the debuggable variants list.

/* Variants */
//   The list of variants to that are debuggable. For those we're going to
//   skip the bundling of the JS bundle and the assets. By default is just 'debug'.
//   If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
debuggableVariants = ["developmentdebug", "developmentrelease"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants