From 2e321fc69f7ebb0e07b4421176619a96990ee2cc Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Thu, 10 Oct 2019 05:31:30 -0700 Subject: [PATCH] Move JNI_OnLoad to separate file which registers both fbjni and jni methods Summary: Move JNI_ONLoad to a separate file so that both fbjni native methods and vanillla jni native methods can be initialized correctly Reviewed By: amir-shalem Differential Revision: D17840166 fbshipit-source-id: 045df0df7a95bc331cbbefb3a118a349f3029465 --- java/jni/YGJNI.cpp | 4 ++-- java/jni/yogajni.cpp | 22 ++++++++++++++++++++++ java/jni/yogajni.h | 11 +++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 java/jni/yogajni.cpp create mode 100644 java/jni/yogajni.h diff --git a/java/jni/YGJNI.cpp b/java/jni/YGJNI.cpp index 9f976920..493e26b3 100644 --- a/java/jni/YGJNI.cpp +++ b/java/jni/YGJNI.cpp @@ -17,6 +17,7 @@ #include "YGJTypes.h" #include "YGJNIVanilla.h" #include "YGJNI.h" +#include "yogajni.h" using namespace facebook::jni; using namespace std; @@ -616,7 +617,7 @@ void jni_YGNodeStyleSetBorder(jlong nativePointer, jint edge, jfloat border) { #define YGMakeCriticalNativeMethod(name) \ makeCriticalNativeMethod_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(#name, name) -jint JNI_OnLoad(JavaVM* vm, void*) { +jint YGJNI::registerNativeMethods(JavaVM* vm) { jint ret = initialize(vm, [] { registerNatives( "com/facebook/yoga/YogaNative", @@ -717,6 +718,5 @@ jint JNI_OnLoad(JavaVM* vm, void*) { jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour), }); }); - YGJNIVanilla::registerNatives(Environment::current()); return ret; } diff --git a/java/jni/yogajni.cpp b/java/jni/yogajni.cpp new file mode 100644 index 00000000..75f84abc --- /dev/null +++ b/java/jni/yogajni.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + */ +#include "yogajni.h" +#include "YGJNIVanilla.h" +#include +#include "common.h" + +using namespace facebook::jni; +using namespace facebook::yoga; + +jint JNI_OnLoad(JavaVM* vm, void*) { + jint ret = YGJNI::registerNativeMethods(vm); + + JNIEnv* env; + vanillajni::ensureInitialized(&env, vm); + YGJNIVanilla::registerNatives(env); + return ret; +} diff --git a/java/jni/yogajni.h b/java/jni/yogajni.h new file mode 100644 index 00000000..23eba1fd --- /dev/null +++ b/java/jni/yogajni.h @@ -0,0 +1,11 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + */ +#include + +namespace YGJNI { +jint registerNativeMethods(JavaVM* vm); +};