Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you debug react-native when it is running on device?

How do you debug react-native when it is running on device ?

like image 436
Mohit Bajoria Avatar asked Apr 14 '17 16:04

Mohit Bajoria


People also ask

How do you debug react native on physical device?

To enable USB debugging on your device, you will first need to enable the "Developer options" menu by going to Settings → About phone → Software information and then tapping the Build number row at the bottom seven times. You can then go back to Settings → Developer options to enable "USB debugging".

How do I debug an emulator in react native?

On 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.


3 Answers

Figured our React Native debugging for Android. Steps to for someone struggling with this -

  1. Launch your RN App
  2. Shake device
  3. Select "Dev Settings"
  4. Select "Debug server host & port for device" Put in your system's IP address.
  5. Shake device
  6. Select "Debug JS remotely"
  7. Chrome will open a new tab with the address "http://localhost:8081/debugger-ui"
  8. If this doesn't happen, check your port and open a new tab and enter the above address with your port number.
  9. Open #Chrome DevTools (Cmd+Alt+I on #MacOSX)
  10. Select the Console Tab
  11. Shake Device
  12. Select "Reload"

View all your console logs or use "debugger;" in your JS for breakpoint debugging.

like image 173
Darshan Pania Avatar answered Nov 14 '22 04:11

Darshan Pania


You have two options:

  1. Debug remotely

iOS: Cmd + ctrl + z to open menu and select "Debug remotely"

Android: Cmd + M to open menu and select "Debug remotely"

  1. Or run one of these commands:

    react-native log-ios
    react-native log-android
    
like image 42
Morten Stulen Avatar answered Nov 14 '22 06:11

Morten Stulen


There are little hack in here for IOS. In XCode open AppDelegate.m from project folder, comment the line with jsCodeLocation declaration and add near it something like this:

jsCodeLocation = [NSURL URLWithString:@"http://%YOUR_PC_IP%:8081/index.ios.bundle?platform=ios&dev=true"];

, where %YOUR_PC_IP% is IP of your dev machine on local net.

Then open project named RCTWebSocket wich located in Libraries folder and then open from this project file RCTWebSocketProjectExecutor.m. Next, comment the line with host declaration, then add near it something like that:

host = @"%YOUR_PC_IP%";

Almost done. Run app on your device with XCode and make sure that your IPhone can see your develop machin via internet.

After it launches make sure that node server is running (command "react-native -- --start" in root project folder) and open via chrome this page: http://localhost:8081/debugger-ui . Plus, option Debug JS Remotely must be enabled in your app on your IPhone. (Shake action, then tap in opened menu Debug JS Remotely, that is it.)

Now open dev console and have happy debugging.

like image 44
Alex Belets Avatar answered Nov 14 '22 06:11

Alex Belets