High level C++ bindings for JNI calls
As discussed on Reddit, here is an improvement idea.
Either adopt one of the following C++ JNI libraries:
Or having a Google provided one that takes advantage of templates and compile time programming to wrap JNI calls into C++ type safe calls, without the low level strings, similar to the approaches taken by the libraries above.
https://android.googlesource.com/platform/libnativehelper/ is the one we use in AOSP, so most likely path is to use that. Will definitely have a look at the others to see what we're missing, if anything.
@pjmlp could you share the Reddit?
From the AMA last week: https://www.reddit.com/r/androiddev/comments/hk3hrq/_/fxkkk6l
if it helps, I have
https://github.com/mgood7123/AAudioTrack/blob/master/AAudioTrack2/src/main/cpp/other/JniHelpers.cpp
https://github.com/mgood7123/AAudioTrack/blob/master/AAudioTrack2/src/main/cpp/other/JniHelpers.h
@mgood7123 what is destroyJvm ?
@mgood7123 what is
destroyJvm?
ummm just ignore that
https://github.com/wang-bin/JMI
I use it in my projects. The api is simple to use.
If useful (and since not mentioned here), after reviewing the available options, we found fbjni to be quite good for the Android JNI use case, with helper code on both sides of the language boundary. It's already widely used and tested in, e.g. React Native and PyTorch.
That said (if this becomes and NDK priority), they could definitely use some help and NDK guidance, particularly around libc++. Could be a good partnership opportunity!
(It seemed like one barrier to libnativehelper was that it depended on some other private libraries?)
There's already a CL up that adds libnativehelper to androidx. It's blocked on some infrastructure problems that won't be resolved soon, but the work is largely done.
Oh, cool! Thanks for letting us know. Any chance there's a public link where we can follow the progress? (Maybe that's here.)
(I'm also curious what the infra blockers are!)
If it's still a goal to look at other efforts to see if there are any goodies to bring in, I'd be way curious what you Googlers think of fbjni! (Last I checked, it seemed like it might have some additional good ideas.)
Any chance there's a public link where we can follow the progress?
Not really. https://android-review.googlesource.com/c/platform/frameworks/support/+/2089324 is the CL, but there isn't any ongoing conversation anywhere, and I assume that's what you're looking for.
(I'm also curious what the infra blockers are!)
externalNativeBuild can't do remote caching.