简体   繁体   中英

How to include unmodifiable native C++ in Android with JNI?

We're exploring including some existing C++ library in an Android project and was recommended to use JNI. Most references I've seen suggest something like this: https://medium.com/@ssaurel/create-your-first-jni-application-on-android-with-the-ndk-5f149508fb12 where you generate the native headers and code to interface with the Java.

Assuming you can't modify the native libraries, is this still the best way? In that case, would you create an additional native shim layer that calls out to the existing native libs and just defines the interfaces?

Yes. If you can't modify the library, you're going to have to create a wrapper layer. Especially if its C++, since you'd need the JNI layer to be extern "C" to avoid name mangling.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM