react native how to disable android dev mode
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
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/