I need to call `__android_log_print()` in `androi...
# kotlin-native
e
I need to call
__android_log_print()
in
androidNativeMain
. The function signature is
Copy code
__android_log_print(prio: <http://kotlin.Int|kotlin.Int>, tag: kotlin.String?, fmt: kotlin.String?, vararg variadicArguments: kotlin.Any?): <http://kotlin.Int|kotlin.Int>
But I don't understand if
variadicArguments
expects a Kotlin type, like
String
, or if I should convert to the C representation with
cstr
a
You can use this in any way you like
Copy code
val num = 128736912873
println("println tes")
__android_log_print(ANDROID_LOG_ERROR.convert(), "Konan_main", "__android_log_print test $num")
e
Ah nice, so the template
%s
part isn't even needed after all.
Thanks for the test! I don't even have an Android test setup as I don't do Android development
Is
Konan_main
strictly necessary?
a
No, this is the name of the key that is used by default for println
✔️ 1
e
tags make it easier to filter in logcat, e.g.
Copy code
adb logcat -s MyApp:*
only shows messages logged with tag
MyApp
e
Perfect, thanks. I've tagged it with my own tag.
e
but yes to your original question, if you're calling a C function you need to pass along C types in the varargs
e
It's just confusing because the
tag
and
fmt
parameter accepts a String, not a C string.
e
it's possible to specify
noStringConversion
in the
.def
file, and then that doesn't happen automatically. but afaik it doesn't happen automatically for varargs, since they aren't typed
👍 1
to Andrey's point though, it'll be easier to do the formatting in Kotlin
e
Thank you!