Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react native how to disable android dev mode

Tags:

I've read that disabling the dev mode in Android can help speed up some of the issues with the Android emulator as it keeps not responding at the moment. How do I disable dev mode? I can't find any bool value or anything anywhere in the react native files.

like image 554
Jonathan Lockley Avatar asked Nov 12 '15 21:11

Jonathan Lockley


People also ask

How do I disable developer mode in react native?

You can also try running npm start , then press d to switch the current mode, then stop npm by ctr+c and then run again exp start you will find the enhancement feature became On and the mode became production.

How do I disable remote debugging in react native?

Go to your android settings and clear app data and cache and reload the app remote debugging will be turned off.

How do I run react native apps in debug mode?

In App Developer MenuOn Android emulator, you need to press command + M. Debug JS Remotely − Used for activating debugging inside browser developer console. Enable Live Reload − Used for enabling live reloading whenever your code is saved. The debugger will open at localhost:8081/debugger-ui.


2 Answers

If you open the menu in react-native apps (F2 or rage shake) and choose dev options, there is option to switch off dev mode along with other options like live reload

like image 76
Nishanth Shankar Avatar answered Sep 20 '22 12:09

Nishanth Shankar


I preferred the way to build apk with a simple gradle command line. I need to build a app-preprod.apk with bundle react native JS and turn off its dev mode to set some different api hostname settings from release build.

After looks over google and stackoverflow, I ended up to find PROJECT_PATH/android/app/react.gradle, and it turns out react will only turn off the dev mode when android build variants name contains "release".

// Set up dev mode
def devEnabled = !targetName.toLowerCase().contains("release")
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
    commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}",
            "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
} else {
    commandLine "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}",
            "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
}

So I just refactor the devEnabled follow my custom setting devInXxx

def devEnabled = config."devIn${targetName}" == false ? false : !targetName.toLowerCase().contains("release")

And set build type variants dev mode to false in PROJECT_PATH/android/build.gradle

project.ext.react = [
bundleInPreprod: true,
devInPreprod: false]

To clean the build, remove all files under "PROJECT_PATH/android/app/build" and run gradle assemble the build variant only by

PROJECT_PATH/android$ ./gradlew assemblePreprod

which will build the app-preprod.apk, which bundled js and turn dev mode off. Normally under the folder PROJECT_PATH/android/app/build/output/apk/

like image 30
Ricotta.Zhang Avatar answered Sep 22 '22 12:09

Ricotta.Zhang