ndk icon indicating copy to clipboard operation
ndk copied to clipboard

High level C++ bindings for JNI calls

Open pjmlp opened this issue 5 years ago • 12 comments

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.

pjmlp avatar Jul 11 '20 17:07 pjmlp

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.

DanAlbert avatar Jul 11 '20 19:07 DanAlbert

@pjmlp could you share the Reddit?

alexcohn avatar Jul 13 '20 16:07 alexcohn

From the AMA last week: https://www.reddit.com/r/androiddev/comments/hk3hrq/_/fxkkk6l

DanAlbert avatar Jul 13 '20 18:07 DanAlbert

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 avatar Dec 08 '20 06:12 mgood7123

@mgood7123 what is destroyJvm ?

alexcohn avatar Dec 08 '20 09:12 alexcohn

@mgood7123 what is destroyJvm ?

ummm just ignore that

mgood7123 avatar Dec 14 '20 20:12 mgood7123

https://github.com/wang-bin/JMI

I use it in my projects. The api is simple to use.

wang-bin avatar Mar 20 '21 04:03 wang-bin

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?)

cpsauer avatar Nov 18 '22 02:11 cpsauer

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.

DanAlbert avatar Nov 18 '22 17:11 DanAlbert

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!)

cpsauer avatar Nov 23 '22 10:11 cpsauer

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.)

cpsauer avatar Nov 23 '22 10:11 cpsauer

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.

DanAlbert avatar Nov 28 '22 21:11 DanAlbert