Debug native java code in react-native

2020-07-09 03:09发布

问题:

Is there a way to debug native java code for Android app built using react-native. Specifically, I want to debug a third party Android package that I am using in my react-native app. There are may blog posts and stackoverflow questions on how to debug the js code but I didn't find any post describing how to debug native java code. I tried to just import the third party Android package into Android Studio and tried to run it in debugger but nothing really happened which I kind of expected.

Please let me know if and how it can be achieved. Thanks!

回答1:

You can open the project in Android Studio and debug any native code there (add breakpoints, debug step by step, etc).

Be sure to launch the React Native packager beforehand. And then launch your app from Android Studio in debug mode.

More info: https://developer.android.com/studio/debug/index.html



回答2:

Launch the React Native packager by running 'react-native start' in the root directory of your React Native Project.

Open the "android" directory of your React Native project in Android Studio.

Then you will be able run and debug your React Native application from Android Studio.