-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ndk-build: Use
uid
to limit logcat
to the current application
This is a port of: rust-mobile/xbuild#131 rust-mobile/xbuild#135 Having never really understood how Android Studio does it, I just stumbled upon this very new [stackoverflow answer] that has a rather beatiful solution to the current problems with `pidof`, without drawbacks. Pidof has always been flaky as it relies on the app to be running, which may either take some time or never happen if the app crashed before `pidof` is first run. This results in silly workarounds such as loops that induce extra delay and need to have an upper bound. And this `pid` changes every time the app is restarted, making it a tedious process that also doesn't react to manual app restarts on the device. Retrieving the `uid` via `pm list packages -U` on the other hand, and passing that to `logcat --uid` has the following advantages: - Always available immediately after the app has been installed, no need to check it in a loop (no extra delay); - Doesn't change after the app is (re!)installed, unless the user fully deletes and installs the app again; - Is resilient against app crashes because of that, and allows the user to see any error/crash related messages straight away; - Still includes logs printed by other system components that run or are invoked within an app, as before. The only downside is that `pm list package` possibly returns multiple packages if there is a substring match; for this reason the code searches for an explicit match in the output. [stackoverflow answer]: https://stackoverflow.com/a/76551835
- Loading branch information
Showing
4 changed files
with
50 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters