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
Changed during review:
the initial logcat process is filtered by the same regex to limit the processed output
helper that's getting PID has setTimeout to avoid hanging on the promise if something goes wrong
both processes are added to cancelToken to make sure everything is cleaned properly
we don't use -T param as it apperas it's not needed
add -T param to first adb logcat (searching for pid) so we limit the logs to current run
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).
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?
Radon IDE (Android Native Logs)
adb logcat
(without any params)in the subprocess to get the app PID (we don't pass the logs to IDE at this point)adb logcat
for the given PIDwith the history (-T
param), to get all logs since the process started, and pass them to IDEChanged during review:
-T
param as it apperas it's not needed-T
param to first adb logcat (searching for pid) so we limit the logs to current runWhy 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 start2024-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:
channel.clear()
this seems to be VSCode issue: https://github.com/microsoft/vscode/issues/204946How Has This Been Tested:
Normal
Radon IDE (Android Native Logs)
output to see the logsCrash on startup
throw IllegalStateException("This line should not be reached")
to MainApplication.onCreate()Radon IDE (Android Native Logs)
outputDemo: