React native - Override command "react-native run-android"

646 Views Asked by At

I'm looking to override the command react-native run-android and I can't find a solution.

I'm working with different variants and schemes for my apps, and by default, run-android launch installDebug whereas it doesn't exist in my project. (same issue for iOS)

Thanks, Best.

2

There are 2 best solutions below

0
On

You can add a command to the script-part in your package.json. Then you can run the command via npm run <command>.

"scripts": { //... "run_app": "react-native run-android" }

Entering npm run run_app would execute the given command.

0
On

If you have few flavors you can set it with --varint flag.

Say we have these:

    productFlavors {
        dev {
            minSdkVersion rootProject.ext.minSdkVersion
            applicationId 'com.xyz.dev'
            ...
        }
        beta {
            minSdkVersion rootProject.ext.minSdkVersion
            ...
        }
    }

You can run it using this command

--variant=<productFlavour><BuildType>

So to run the dev version in debug mode, we use

react-native run-android --variant=devDebug --appIdSuffix=dev

And to build the release version, use the command

assemble<ProductFlavour><BuildType>

Example for building a beta release

cd android && ./gradlew assembleBetaRelease

I found this medium post with a detailed explanation hope it helps. https://medium.com/@ywongcode/building-multiple-versions-of-a-react-native-app-4361252ddde5