18

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!

3 Answers 3

19

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

Sign up to request clarification or add additional context in comments.

4 Comments

I didn't realize that Android Studio will automatically import the Android projects under node_modules directory and allow me to debug within them. Pretty cool and thanks for the quick response!
Yeah, just import the android pack from React Native project and run from Android Studio like other pure Android apps, the debug prints shows. Thanks for the clear and great answer!
What did you do? 1. Open the root of your project in Android Studio, 2. Set breakpoints in node_modules/<native_module>. What does 'launch packager' mean? react-native run-android? and what do you configure in Android Studio to debug the app?
Please can you tell the exact procedure because I also tried the same but couldn't be able to debug ?
4

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.

Comments

2

The way I could debug java code is the following:

  1. shell: npm run android
  2. Android Studio: "Attach debugger to Android Process" -> enter image description here

Voila!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.