Skip to content

Commit

Permalink
Move JNI_OnLoad to separate file which registers both fbjni and jni m…
Browse files Browse the repository at this point in the history
…ethods

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
  • Loading branch information
SidharthGuglani-zz authored and facebook-github-bot committed Oct 10, 2019
1 parent aa2610c commit 2e321fc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions java/jni/YGJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "YGJTypes.h"
#include "YGJNIVanilla.h"
#include "YGJNI.h"
#include "yogajni.h"

using namespace facebook::jni;
using namespace std;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -717,6 +718,5 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour),
});
});
YGJNIVanilla::registerNatives(Environment::current());
return ret;
}
22 changes: 22 additions & 0 deletions java/jni/yogajni.cpp
Original file line number Diff line number Diff line change
@@ -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 <fbjni/fbjni.h>
#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;
}
11 changes: 11 additions & 0 deletions java/jni/yogajni.h
Original file line number Diff line number Diff line change
@@ -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 <fbjni/fbjni.h>

namespace YGJNI {
jint registerNativeMethods(JavaVM* vm);
};

0 comments on commit 2e321fc

Please sign in to comment.