Debug native java code in react-native - android

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!

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

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.

The way I could debug java code is the following:
shell: npm run android
Android Studio: "Attach debugger to Android Process" ->
Voila!

Related

Problem initializing project in ReactNative CLI

My name is fernando and I'm studying mobile development via React Native
I'm having trouble using the React Native CLI, as I couldn't solve this problem I decided to do all the steps from the recommended https://reactnative.dev/docs/environment-setup again to run the code.
I uninstalled Java, node, Android Studio, JDK and gradle.
I installed Java, Node and Java using Chocolatey as recommended by the documentation, I strictly performed all the steps requested but I cannot install the application on the simulator or on the cell phone via USB
Starts NPM START normally without errors.
But when starting NPM RUN ANDROID it gives me the following error
enter image description here
OBS:
The project in question in the image, has no code, it was only opened using npx react-native init AwesomeProject
Another observation that I can run and program using React native EXPO GO
It works without errors and I can run both in the simulator and in USB
Thank you and I would appreciate it if someone could help me

React Native without Android Studio?

Is there any way to develop a React Native app for Android without installing Android Studio ?
On Ubuntu 18.04 the apt command proposes a lot of android packages: android-sdk, android-sdk-platform-tools etc...
What do I need exactly to get React Native working properly ?
Please don't use expo or another SDKs of react native. React Native CLI is recommended everywhere because its performance is not comparable to expo and it is much more lightweight! Android Studio is just an IDE! If you setup your android development environment correctly there is no need to install Android Studio IDE (This is for experts!) but it is recommended to install for amateur users.
If you don't want to use the Android studio, you can take advantage of the Expo. Expo is the best way to assist React-native. You can run the app without the Android studio, and when you refresh, you can see the modified code right away.
Look at this official document and follow it slowly.
you don't need Android Studio at all, if you are using react native cli you can install it on your phone and run it there.
An attempt of solution to use react native without android studio and without expo is to build directly in your device.
you must install adb first by following this link install-adb-fastboot-on-ubuntu 18.04
and then you should follow this link react-native running-on-device
It will help you.
I'm using usb cable to install debug apk in my phone (react-native run-android). I put my phone in the same network (WIFI) with my machine (server) and configure the server address and port to debug remotely in the phone. After that i remove the usb cable.
In short everything is explained on the link above

How to debug NativeScript java code in Android Studio?

I'm quite new to NativeScript. Currently, one of my projects is using NativeScript to develop cross-platform app. It has a 3rd-party lib which is written in java. But the result is not as good as I expected. I was struggling to find the problem since the console didn't log valuable info regarding to native code.
Instead, I import the project to Android Studio which is under the folder of platform/android. But it logs error when I hit the "run" button.
I want to know:
Is it possible to debug native code directly with VS Code. At least print out java native error or cat log.
How can I debug native code in Android Studio? How to solve the problem I ran into?
I'd be very appreciated, if anyone can answer my questions. Thanks!
Let me start off by saying there's no official integration with Android Studio. All I can provide is a workaround that will make it possible.
Note: The steps provided below are tested with NativeScript CLI 3.1.1 and will probably work also with 3.2.0.
The first problem is you don't have "node" set in your global path so first of all, you need to add it to PATH. Node required for NativeScript to run. You can look at how to set it up here
If you want to be able to run the project with Android Studio you can follow these steps:
After you've done that you need to change the <app_name>/platforms/android/build.gradle file as described here
The above change will enable you to open <app_name>/platforms/android in Android Studio
Run <app_name>:clean task from gradle
Run the task default for Android Studio, that will prompt you for emulator or device on which to run:

Unable to debug React Native in Android Studio

I am trying to work on react native for android application development. I am using android studio for that, but I am unable to debug the .js files developed for react native. Whenever there is any problem with code its giving me error, Unexpected Token, I am unable to know that how to debug or get proper error. Is there any framework available to work on React native for Android app development. I have already figured out a lot but unable to get any solution to debug android app based on React Native.
You can debug JavaScript code, console.log etc in Chrome. You have to select "Debug in Chrome" from the developer menu on device first and that will open a new tab on Chrome at localhost:8081/debugger-ui. However, to debug in Chrome, keep in mind you have to install React Developer Tools on Chrome https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi
You need to debug in Chrome. There are good docs on the RN site about debugging:
https://facebook.github.io/react-native/docs/debugging.html#content
However, if you have syntax errors the debugger won't help you, but Chrome Dev tools might give you a better idea of where the error is.

Using Microsoft debugger with Xamarin Android

There's an option in the Android project settings in the Android Options section on the Packaging tab that lets you choose between the Xamarin debugger or the Microsoft debugger. The Xamarin debugger works, but not as good as the Microsoft one might. Unfortunately I get an error message when trying to use the Microsoft debugger and deploy on one of the Visual Studio Android Emulators.
Unable to start debugging. Non-debuggable application installed on the target device. Required file '/data/data/My.Application/lib/gdbserver' could not be found on the device. Please install a debuggable version.
Is there any way to get the Microsoft debugger to work?
The Xamarin debugger can only debug managed (i.e. C#) code. Breakpoints only work with the Xamarin debugger if the project being debugged is a managed project. They don't work if the project is a native app or native library.
The Microsoft debugger can only debug native (i.e. C/C++) code. Breakpoints only work with the Microsoft debugger if the project being debugged is a native app or native library, or if it is attached to an already-running Android process.
To get gdbserver into the app package, you either have to reference a native code library from your managed app, or include it (with build action set to AndroidNativeLibrary). I found you can also add a link to gdbserver (again, with build action set to AndroidNativeLibrary) from a project and make use of path sniffing to select the gdbserver from the matching ABI. Snippet of project file:
<ItemGroup>
<AndroidNativeLibrary Include="$(ANDROID_NDK_ROOT)\prebuilt\android-arm\gdbserver\gdbserver">
<Link>lib\armeabi-v7a\gdbserver</Link>
</AndroidNativeLibrary>
</ItemGroup>
Also please see my answer to a similar question.

Categories

Resources