Skip to content

Commit

Permalink
Use prefab JNI in Hermes
Browse files Browse the repository at this point in the history
Summary:
Instead of including JNI source code in our repo and statically
linking in parts of JNI, use the prebuilt shared library available
from Maven.

While working on fixing the `Intl.NumberFormat` crash in the GC, I
got multiple weird exceptions with stack traces that didn't line up
with `hermesLog` statements I had added to the code. I eventually
suspected something was wrong with having multiple copies of JNI, and
switching to the shared library from maven resolved the crashes.

Reviewed By: tmikov

Differential Revision: D28791954

fbshipit-source-id: 992bc04428795cc3154a229211c1a6f24add32d6
  • Loading branch information
neildhar authored and facebook-github-bot committed Jun 8, 2021
1 parent 1336444 commit 103f1d3
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 92 deletions.
6 changes: 0 additions & 6 deletions API/hermes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ set(api_sources
file(GLOB api_headers ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
file(GLOB api_public_headers ${PROJECT_SOURCE_DIR}/public/hermes/Public/*.h)

if(HERMES_IS_ANDROID)
list(APPEND api_sources
JNI_OnLoad.cpp
)
endif()

add_hermes_library(hermesapi
${api_sources}
LINK_LIBS jsi hermesVMRuntime)
Expand Down
12 changes: 0 additions & 12 deletions API/hermes/JNI_OnLoad.cpp

This file was deleted.

15 changes: 1 addition & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -587,20 +587,7 @@ include_directories(BEFORE
)

if(HERMES_IS_ANDROID)
if(EXISTS ${HERMES_SOURCE_DIR}/first-party/fbjni/cxx)
set(FBJNI_PATH ${HERMES_SOURCE_DIR}/first-party/fbjni)
elseif(EXISTS ${FBSOURCE_DIR}/fbandroid/libraries/fbjni/cxx)
set(FBJNI_PATH ${FBSOURCE_DIR}/fbandroid/libraries/fbjni)
elseif(EXISTS ${HERMES_SOURCE_DIR}/../../fbandroid/libraries/fbjni/cxx)
set(FBJNI_PATH ${HERMES_SOURCE_DIR}/../../fbandroid/libraries/fbjni)
else()
message(FATAL_ERROR "Unable to find fbjni.")
endif()
include_directories("${FBJNI_PATH}/cxx/")
add_subdirectory(first-party/fbjni)

# JNI requires that JNI_OnLoad is (re-)exported for initialization.
set(OPTIONAL_JNI_ONLOAD "-Wl,--undefined=JNI_OnLoad")
find_package(fbjni REQUIRED CONFIG)
endif()

set(CMAKE_CXX_STANDARD 14)
Expand Down
8 changes: 7 additions & 1 deletion android/hermes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,21 @@ android {
}
}

// Allow using prefab so that we can import libfbjni.so.
buildFeatures {
prefab true
}

dependencies {
intlImplementation 'com.facebook.fbjni:fbjni:0.0.2'
implementation 'com.facebook.fbjni:fbjni:0.2.2'
intlImplementation 'com.facebook.soloader:soloader:0.9.0'
intlImplementation 'com.facebook.yoga:proguard-annotations:1.14.1'
intlImplementation "androidx.annotation:annotation:1.1.0"
}

packagingOptions {
exclude "**/libc++_shared.so"
exclude "**/libfbjni.so"
}

afterEvaluate {
Expand Down
14 changes: 13 additions & 1 deletion android/intltest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,33 @@ android {

useLibrary 'android.test.base'

// Allow using prefab so that we can import libfbjni.so.
buildFeatures {
prefab true
}

dependencies {
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'org.easytesting:fest-assert-core:2.0M10'
androidTestImplementation 'com.facebook.fbjni:fbjni:0.0.2'
androidTestImplementation 'com.facebook.soloader:soloader:0.9.0'
androidTestImplementation 'com.facebook.yoga:proguard-annotations:1.14.1'
}

dependencies {
implementation 'com.facebook.fbjni:fbjni:0.2.2'
implementation "androidx.annotation:annotation:1.1.0"
implementation "androidx.annotation:annotation-experimental:1.0.0"
}

// TODO: Revisit this if there is a better solution for deduplicating native
// libraries.
packagingOptions {
pickFirst "**/libfbjni.so"
pickFirst "**/libc++_shared.so"
}

sourceSets {
main {
java {
Expand Down
4 changes: 2 additions & 2 deletions android/intltest/java/com/facebook/hermes/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if(HERMES_IS_ANDROID)
libhermes
hermesapi
compileJS
hermesfbjni
fbjni::fbjni
jsi
${CORE_FOUNDATION}
)
Expand All @@ -43,7 +43,7 @@ if(HERMES_IS_ANDROID)
libhermes
hermesapi
compileJS
hermesfbjni
fbjni::fbjni
jsi
${CORE_FOUNDATION}
)
Expand Down
2 changes: 0 additions & 2 deletions first-party/README

This file was deleted.

52 changes: 0 additions & 52 deletions first-party/fbjni/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion lib/Platform/Intl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set(source_files
if(HERMES_IS_ANDROID)
add_hermes_library(hermesPlatformIntl STATIC ${source_files}
LINK_LIBS
hermesfbjni
fbjni::fbjni
${CORE_FOUNDATION}
)
set_source_files_properties(PlatformIntlAndroid.cpp PROPERTIES
Expand Down
2 changes: 1 addition & 1 deletion lib/Platform/Unicode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(source_files
if(HERMES_IS_ANDROID)
add_hermes_library(hermesPlatformUnicode STATIC ${source_files}
LINK_LIBS
hermesfbjni
fbjni::fbjni
${CORE_FOUNDATION}
)
set_source_files_properties(PlatformUnicodeJava.cpp PROPERTIES
Expand Down

0 comments on commit 103f1d3

Please sign in to comment.