Bug: 379335354

Clone this repo:
  1. 7998955 Add janitors to the OWNERS file by Sadaf Ebrahimi · 5 weeks ago main
  2. c8aa242 Change fbjni to static library by Qiao Li · 6 weeks ago
  3. b5aa70b Merge remote-tracking branch 'origin/upstream' am: d7c1b84a31 by Inna Palant · 7 weeks ago
  4. d7c1b84 Merge remote-tracking branch 'origin/upstream' by Inna Palant · 7 weeks ago
  5. 440a427 Include platform/external/fbjni by Emily Fu · 8 weeks ago upstream

fbjni

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;
  }
};

Documentation

License

fbjni is Apache-2 licensed, as found in the LICENSE file.