Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Add native logs #734

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

maciekstosio
Copy link
Contributor

@maciekstosio maciekstosio commented Nov 15, 2024

The motivation of this PR is to pass native logs to Radon IDE. Currently, if the app crashes on the native side developer needs to open Android Studio anyway.

How it's done?

  • we create a new output channel called Radon IDE (Android Native Logs)
  • firstly we run adb logcat (without any params) in the subprocess to get the app PID (we don't pass the logs to IDE at this point)
  • once we get the PID, we run adb logcat for the given PID with the history (-T param), to get all logs since the process started, and pass them to IDE

Why like this?
We don't want to pass all adb logcat logs, as those are enormous. I didn't find a way to filter logs by packageId (except filtering them with regex), so the most reliable way seems to be to filter them by PID.
Now, suppose the app crashes at the very beginning (for example, during MainApplication.onCreate()). In that case, we have no way of getting PID before (because the process is not created yet) and after (the process is already killed). To solve this case, for a short period of time, we go through all logs with regex to look for app start

2024-11-15 14:51:24.154 574-606 ActivityManager system_server I Start proc 4474:com.reactnative76/u0a198 for next-top-activity {com.reactnative76/com.reactnative76.MainActivity}

and extract pid. Then we kill this process and spawn one that is properly filtered (with history, so the logs that came up during app start are there too).

Remarks:

How Has This Been Tested:

Normal

  • run react-native-76 and look for Radon IDE (Android Native Logs) output to see the logs

Crash on startup

  • add throw IllegalStateException("This line should not be reached") to MainApplication.onCreate()
  • run react-native-76
  • make sure the logs from crash are visible in Radon IDE (Android Native Logs) output

Demo:

Screen.Recording.2024-11-15.at.21.21.16.mov

Copy link

vercel bot commented Nov 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
radon-ide ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 15, 2024 8:40pm

@@ -49,7 +51,9 @@ interface EmulatorProcessInfo {
export class AndroidEmulatorDevice extends DeviceBase {
private emulatorProcess: ChildProcess | undefined;
private serial: string | undefined;

private nativeLogsOutputChannel: OutputChannel | undefined;
private nativeLogsProcess: ChildProcess | undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we could move it to the abstract class once iOS part is ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant