Skip to content

Commit 9ad5e72

Browse files
passyfacebook-github-bot
authored andcommitted
Migrate to FBJNI (#27729)
Summary: This is an incomplete effort to migrate from libfb to libfbjni. This is needed to restore the compatibility with Flipper and other FB Android projects that make use of FBJNI. Effectively, the outcome is that `fbjni` no longer has a checked-in copy here, but instead relies on the public artifacts published at github.com/facebookincubator/fbjni that can be deduplicated at build-time. **A non-exhaustive list of tasks:** * [X] Gradle builds the SDK and RNTester for Android. * [X] Buck build for rntester works in OSS. * [ ] Move from `java-only` release to full `fbjni` release. This requires finding a solution for stripping out `.so` files that the old `Android.mk` insists on including in the final artifacts and will clash with the full distribution. * [ ] Import this and fix potential internal build issues. * [ ] Verify that the changes made to the Hermes integration don't have any unintended consequences. ## Changelog [Android] [Changed] - Migrated from libfb to libfbjni for JNI calls Pull Request resolved: #27729 Test Plan: - CI is already passing again for Gradle and Buck in OSS. - After applying the following patch, RNTester builds and works with the latest Flipper SDK: ``` diff --git a/RNTester/android/app/build.gradle b/RNTester/android/app/build.gradle index b8a6437d7..eac942104 100644 --- a/RNTester/android/app/build.gradle +++ b/RNTester/android/app/build.gradle @@ -170,10 +170,19 @@ dependencies { debugImplementation files(hermesPath + "hermes-debug.aar") releaseImplementation files(hermesPath + "hermes-release.aar") - debugImplementation("com.facebook.flipper:flipper:0.23.4") { + debugImplementation("com.facebook.flipper:flipper:+") { exclude group:'com.facebook.yoga' - exclude group:'com.facebook.flipper', module: 'fbjni' - exclude group:'com.facebook.litho', module: 'litho-annotations' + exclude group:'com.facebook.fbjni' + } + + debugImplementation("com.facebook.flipper:flipper-network-plugin:+") { + exclude group:'com.facebook.yoga' + exclude group:'com.facebook.fbjni' + } + + debugImplementation("com.facebook.flipper:flipper-fresco-plugin:+") { + exclude group:'com.facebook.yoga' + exclude group:'com.facebook.fbjni' } if (useIntlJsc) { ``` Reviewed By: mdvacca Differential Revision: D19345270 Pulled By: passy fbshipit-source-id: 33811e7f97f44f2ec5999e1c35339909dc4fd3b1
1 parent b9a9e8a commit 9ad5e72

File tree

152 files changed

+158
-8505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+158
-8505
lines changed

.buckconfig

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[maven_repositories]
99
central = https://repo1.maven.org/maven2
1010
google = https://maven.google.com/
11+
jcenter = https://jcenter.bintray.com/
1112

1213
[alias]
1314
rntester = //RNTester/android/app:app

RNTester/android/app/src/debug/java/com/facebook/react/uiapp/ReactNativeFlipper.java

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
7-
87
package com.facebook.react.uiapp;
98

109
import android.content.Context;

ReactAndroid/build.gradle

+41-2
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ def getNdkBuildFullPath() {
296296
}
297297

298298
def buildReactNdkLib = tasks.register("buildReactNdkLib", Exec) {
299-
dependsOn(prepareJSC, prepareHermes, prepareBoost, prepareDoubleConversion, prepareFolly, prepareGlog)
299+
dependsOn(prepareJSC, prepareHermes, prepareBoost, prepareDoubleConversion, prepareFolly, prepareGlog, extractAARHeaders, extractJNIFiles)
300+
300301
inputs.dir("$projectDir/../ReactCommon")
301302
inputs.dir("src/main/jni")
302303
inputs.dir("src/main/java/com/facebook/react/modules/blob")
@@ -344,6 +345,34 @@ def packageReactNdkLibsForBuck = tasks.register("packageReactNdkLibsForBuck", Co
344345
into("src/main/jni/prebuilt/lib")
345346
}
346347

348+
task extractAARHeaders {
349+
doLast {
350+
configurations.extractHeaders.files.each {
351+
def file = it.absoluteFile
352+
def packageName = file.name.tokenize('-')[0]
353+
copy {
354+
from zipTree(file)
355+
into "$projectDir/src/main/jni/first-party/$packageName/headers"
356+
include "**/*.h"
357+
}
358+
}
359+
}
360+
}
361+
362+
task extractJNIFiles {
363+
doLast {
364+
configurations.extractJNI.files.each {
365+
def file = it.absoluteFile
366+
def packageName = file.name.tokenize('-')[0]
367+
copy {
368+
from zipTree(file)
369+
into "$projectDir/src/main/jni/first-party/$packageName/"
370+
include "jni/**/*"
371+
}
372+
}
373+
}
374+
}
375+
347376
android {
348377
compileSdkVersion 28
349378

@@ -386,18 +415,25 @@ android {
386415
}
387416

388417
tasks.withType(JavaCompile) {
389-
compileTask -> compileTask.dependsOn(packageReactNdkLibs)
418+
compileTask ->
419+
compileTask.dependsOn(packageReactNdkLibs)
390420
}
391421

392422
clean.dependsOn(cleanReactNdkLib)
393423

394424
lintOptions {
395425
abortOnError(false)
396426
}
427+
397428
packagingOptions {
398429
exclude("META-INF/NOTICE")
399430
exclude("META-INF/LICENSE")
400431
}
432+
433+
configurations {
434+
extractHeaders
435+
extractJNI
436+
}
401437
}
402438

403439
dependencies {
@@ -412,6 +448,9 @@ dependencies {
412448
api("com.squareup.okhttp3:okhttp:${OKHTTP_VERSION}")
413449
api("com.squareup.okhttp3:okhttp-urlconnection:${OKHTTP_VERSION}")
414450
api("com.squareup.okio:okio:1.15.0")
451+
api("com.facebook.fbjni:fbjni-java-only:0.0.3")
452+
extractHeaders("com.facebook.fbjni:fbjni:0.0.2:headers")
453+
extractJNI("com.facebook.fbjni:fbjni:0.0.2")
415454

416455
testImplementation("junit:junit:${JUNIT_VERSION}")
417456
testImplementation("org.powermock:powermock-api-mockito:${POWERMOCK_VERSION}")

ReactAndroid/src/main/java/com/facebook/BUCK

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ rn_android_library(
55
srcs = glob(["yoga/*.java"]),
66
visibility = ["PUBLIC"],
77
deps = [
8-
react_native_dep("java/com/facebook/jni:jni"),
8+
react_native_dep("libraries/fbjni:java"),
99
react_native_dep("java/com/facebook/proguard/annotations:annotations"),
1010
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),
1111
react_native_dep("third-party/java/infer-annotations:infer-annotations"),

ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/Android.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(call find-no
1919
LOCAL_CPP_FEATURES := exceptions
2020

2121
LOCAL_STATIC_LIBRARIES := libjsireact libjsi
22-
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libreactnativejni libhermes
22+
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni libhermes
2323

2424
include $(BUILD_SHARED_LIBRARY)
2525

ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/BUCK

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ rn_android_library(
1515
deps = [
1616
react_native_dep("java/com/facebook/proguard/annotations:annotations"),
1717
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),
18-
react_native_dep("java/com/facebook/jni:jni"),
18+
react_native_dep("libraries/fbjni:java"),
1919
":jni_hermes_samplingprofiler",
2020
],
2121
)

ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#include <fb/fbjni.h>
8+
#include <fbjni/fbjni.h>
99
#include <string>
1010

1111
namespace facebook {

ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesSamplingProfiler.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#ifndef HERMESSAMPLINGPROFILER_H_
99
#define HERMESSAMPLINGPROFILER_H_
1010

11-
#include <fb/fbjni.h>
12-
#include <jni/Registration.h>
11+
#include <fbjni/fbjni.h>
1312
#include <jsi/jsi.h>
1413

1514
namespace facebook {

ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/Android.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(call find-no
1818
LOCAL_CPP_FEATURES := exceptions
1919

2020
LOCAL_STATIC_LIBRARIES := libjsireact libjsi
21-
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libreactnativejni libhermes
21+
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni libhermes
2222

2323
include $(BUILD_SHARED_LIBRARY)
2424

@@ -35,6 +35,6 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(call find-no
3535
LOCAL_CPP_FEATURES := exceptions
3636

3737
LOCAL_STATIC_LIBRARIES := libjsireact libjsi libhermes-inspector
38-
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libreactnativejni libhermes
38+
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni libhermes
3939

4040
include $(BUILD_SHARED_LIBRARY)

ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/OnLoad.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <../instrumentation/HermesMemoryDumper.h>
99
#include <HermesExecutorFactory.h>
10-
#include <fb/fbjni.h>
10+
#include <fbjni/fbjni.h>
1111
#include <hermes/Public/GCConfig.h>
1212
#include <hermes/Public/RuntimeConfig.h>
1313
#include <jni.h>

ReactAndroid/src/main/java/com/facebook/jni/BUCK

-16
This file was deleted.

ReactAndroid/src/main/java/com/facebook/jni/Countable.java

-39
This file was deleted.

ReactAndroid/src/main/java/com/facebook/jni/CpuCapabilitiesJni.java

-29
This file was deleted.

ReactAndroid/src/main/java/com/facebook/jni/DestructorThread.java

-139
This file was deleted.

0 commit comments

Comments
 (0)