android / ndk

The Android Native Development Kit
1.99k stars 257 forks source link

[FR] provides liblog.a in official Android NDK #1879

Open leleliu008 opened 1 year ago

leleliu008 commented 1 year ago

Description

some command-line tools can not be built as fully statically linked executable due to lack of liblog.a.

as a workaround, can I build it from AOSP?

enh-google commented 1 year ago

https://man7.org/linux/man-pages/man3/syslog.3.html would be the portable way to log from libc (and ends up in the same place).

DanAlbert commented 1 year ago

The only downsides to syslog is that iirc you can only have one log tag per process, and that it'll only work (i.e. end up in logcat) for... M+? It's been a long time, but I think in the absolute oldest devices we support it won't work.

For the use case of static executables those don't actually sound like a problem. There may not be any point in providing liblog.a.

leleliu008 commented 1 year ago

Android L reimplement the loging system, the new implemention doesn't adapt to the old android devices, that's why they do not provide liblog.a

It seems that I have to implement it by myself.

leleliu008 commented 1 year ago

I find golang implement it's android log system client.

https://cs.android.com/android/platform/superproject/+/master:system/logging/liblog/README.protocol.md

https://go.dev/src/runtime/write_err_android.go

enh-google commented 1 year ago

if you're worried about pre-L like that golang code, note that the next release of the NDK won't support pre-L anyway...

enh-google commented 1 year ago

The only downsides to syslog is that iirc you can only have one log tag per process

(for the record, that's not strictly correct --- syslog() will use whatever tag the latest openlog() used. but of course if you have multiple threads trying to use multiple tags, you'll need to add some synchronization there, which may or may not be worth it.)