1*65c59e02SInna Palant# fbjni 2*65c59e02SInna Palant 3*65c59e02SInna PalantThe Facebook JNI helpers library is designed to simplify usage of the 4*65c59e02SInna Palant[Java Native Interface](https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/jniTOC.html). 5*65c59e02SInna PalantThe helpers were implemented to ease the integration of cross-platform mobile 6*65c59e02SInna Palantcode on Android, but there are no Android specifics in the design. It can be 7*65c59e02SInna Palantused with any Java VM that supports JNI. 8*65c59e02SInna Palant 9*65c59e02SInna Palant```cpp 10*65c59e02SInna Palantstruct JMyClass : JavaClass<JMyClass> { 11*65c59e02SInna Palant static constexpr auto kJavaDescriptor = "Lcom/example/MyClass;"; 12*65c59e02SInna Palant 13*65c59e02SInna Palant // Automatic inference of Java method descriptors. 14*65c59e02SInna Palant static std::string concatenate( 15*65c59e02SInna Palant alias_ref<JClass> clazz, 16*65c59e02SInna Palant // Automatic conversion to std::string. 17*65c59e02SInna Palant std::string prefix) { 18*65c59e02SInna Palant // Call methods easily. 19*65c59e02SInna Palant static const auto getSuffix = clazz->getStaticMethod<JString()>("getSuffix"); 20*65c59e02SInna Palant // Manage JNI references automatically. 21*65c59e02SInna Palant local_ref<JString> jstr = getSuffix(clazz); 22*65c59e02SInna Palant // Automatic exception translation between Java and C++ (both ways). 23*65c59e02SInna Palant // No need to check exception state after each call. 24*65c59e02SInna Palant result += jstr->toStdString(); 25*65c59e02SInna Palant // Automatic conversion from std::string. 26*65c59e02SInna Palant return result; 27*65c59e02SInna Palant } 28*65c59e02SInna Palant}; 29*65c59e02SInna Palant``` 30*65c59e02SInna Palant 31*65c59e02SInna Palant## Documentation 32*65c59e02SInna Palant 33*65c59e02SInna Palant- [Why use a JNI wrapper?](docs/rationale.md) 34*65c59e02SInna Palant- [Set up your Android build with fbjni](docs/android_setup.md) 35*65c59e02SInna Palant- [Quick reference to most features (great for copy/pasting!)](docs/quickref.md) 36*65c59e02SInna Palant- [Internal documentation for maintainers](docs/maintainers.md) 37*65c59e02SInna Palant<!-- TODO: tutorial --> 38*65c59e02SInna Palant<!-- TODO: Comparison with other frameworks. --> 39*65c59e02SInna Palant 40*65c59e02SInna Palant## License 41*65c59e02SInna Palant 42*65c59e02SInna Palantfbjni is Apache-2 licensed, as found in the [LICENSE](/LICENSE) file. 43