commit | d52535bb5bc38d52a96b1f0b59e6a33baf12fac4 | [log] [tgz] |
---|---|---|
author | Shreyas Basarge <shreyas@fb.com> | Thu May 28 00:34:04 2020 -0700 |
committer | Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com> | Thu May 28 00:37:36 2020 -0700 |
tree | bb0e385b5c6f48bc6efc4b67c3fca19ccb00611c | |
parent | 814bf29598aead2f378cec50569f7f44abd05382 [diff] |
Expose function to determine if a global JVM is available Summary: This is useful in pure C++ environments. Useful to write tests for cross platform code that uses libraries that conditionally use JNI. Differential Revision: D21758426 fbshipit-source-id: 8c252b9e90a456eba06e6634b437da4cbfc40965
The Facebook JNI helpers library is designed to simplify usage of the Java Native Interface. The helpers were implemented to ease the integration of cross-platform mobile code on Android, but there are no Android specifics in the design. It can be used with any Java VM that supports JNI.
struct JMyClass : JavaClass<JMyClass> { static constexpr auto kJavaDescriptor = "Lcom/example/MyClass;"; // Automatic inference of Java method descriptors. static std::string concatenate( alias_ref<JClass> clazz, // Automatic conversion to std::string. std::string prefix) { // Call methods easily. static const auto getSuffix = clazz->getStaticMethod<JString()>("getSuffix"); // Manage JNI references automatically. local_ref<JString> jstr = getSuffix(clazz); // Automatic exception translation between Java and C++ (both ways). // No need to check exception state after each call. result += jstr->toStdString(); // Automatic conversion from std::string. return result; } };
fbjni is Apache-2 licensed, as found in the LICENSE file.