0

I have a MacBook Air, and while it can perfectly compile and run ReactNative projects on Android device, I noticed that the MBA will become so hot in no time if the Metro server is run. If it's hot, even the IDE (Visual Studio Code) is lagging like 2-5s when I'm trying to type anything.

Is it possible for me to compile, run ReactNative project, and also debug it from Mac's browser, without running Metro server on my Mac? (like, for example, actually bundle the server into the app like when we release production APK -- but still enabling me to get console output on browser?)

EDIT: currently I have already added bundleInDebug: true, save, and then retry npx react-native run-android, but it still does the "Starting JS server..." thing. Closing the server terminal window makes the app crash, so I guess the app still depends on the Metro server on the computer. It's almost like the bundleInDebug option gets ignored.

Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124

1 Answers1

0

Yes, you can. Just edit android/app/build/gradle. Search for these lines

project.ext.react = [
    enableHermes: false,  // clean and rebuild if changing
]

And add bundleInDebug: true after enableHermes line.

If you have custom build variant, the configuration property can be in the following formats:

  • bundleIn${productFlavor}${buildType}
  • bundleIn${buildType}.

For example bundleInFreeDebug: true, bundleInPaidRelease: true, bundleInBeta: true

EDIT: JS debugger works only with Metro server

Vadim Goroshevsky
  • 1,486
  • 10
  • 19
  • Oh... yea, there's a large commented section on the `build.gradle` that explain just about that, but I never knew that that's the meaning. Now I have added it, and doing `npx react-native run-android`. But it still doing that "Starting js server..." operation. If I close the terminal window of the server, the app stop. Is there anything I missed? I've done further search and tried to do things listed here, but still no luck either. https://stackoverflow.com/a/39995118/3003927 – Chen Li Yong Aug 13 '20 at 11:14
  • Try to run the app from Android studio – Vadim Goroshevsky Aug 13 '20 at 11:24
  • Can I use command line? Because Android Studio is somewhat heavy weight to run and I use Visual Studio Code for my IDE. – Chen Li Yong Aug 13 '20 at 11:47
  • 1
    Call `./gradlew installDebug` from `android` folder – Vadim Goroshevsky Aug 13 '20 at 11:50
  • Oh, yea, that works. So it's the `npx react-native run-android` that's causing the server to be initiated. Now I've got the app running on my device. But now it can't connect to the debugger on the browser of my computer. The browser debugger also report "Disconnected from server. Is node server running?" How can I fix this? I've tried to find some info first about this but can't find any. I tried to close the browser, close the app, and rerun it. Open the reactnative menu, and select debug. It shows error "Failed to connect to debugger! Unexpected end of stream on http://localhost:8081/..." – Chen Li Yong Aug 13 '20 at 12:08
  • Usually when the the app is running connected to the metro server, when I select Debug option from react native app's menu, the browser in my Mac is automatically launched, even though it originally closed before. – Chen Li Yong Aug 13 '20 at 12:10
  • You are right, JS debugger will not work with bundled code – Vadim Goroshevsky Aug 13 '20 at 12:23
  • :( ok thanks or the information. At least I learn something new. – Chen Li Yong Aug 14 '20 at 01:38