Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jzxchiang1/418832d01dcb8a4c01a01c16d8772365 to your computer and use it in GitHub Desktop.
Save jzxchiang1/418832d01dcb8a4c01a01c16d8772365 to your computer and use it in GitHub Desktop.
How to get react-native-vision-camera working with v8 reanimated
diff --git a/node_modules/react-native-vision-camera/android/CMakeLists.txt b/node_modules/react-native-vision-camera/android/CMakeLists.txt
index f87ef60..1781b5d 100644
--- a/node_modules/react-native-vision-camera/android/CMakeLists.txt
+++ b/node_modules/react-native-vision-camera/android/CMakeLists.txt
@@ -61,12 +61,14 @@ target_include_directories(
${INCLUDE_JSI_CPP} # only on older RN versions
${INCLUDE_JSIDYNAMIC_CPP} # only on older RN versions
# --- Reanimated ---
+ "${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/AnimatedSensor"
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/Tools"
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/SpecTools"
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/SharedItems"
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/Registries"
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/LayoutAnimations"
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/hidden_headers"
+ "${NODE_MODULES_DIR}/react-native-v8/src"
"src/main/cpp"
)
@@ -86,16 +88,16 @@ if(${FOR_HERMES})
# Use Reanimated Hermes
file (GLOB LIBREANIMATED_DIR "${BUILD_DIR}/react-native-reanimated-*-hermes.aar/jni/${ANDROID_ABI}")
else()
- file (GLOB LIBJSC_DIR "${BUILD_DIR}/android-jsc*.aar/jni/${ANDROID_ABI}")
- # Use JSC
+ file (GLOB LIBV8_DIR "${NODE_MODULES_DIR}/react-native-v8/android/build/intermediates/library_jni/*/jni/${ANDROID_ABI}")
+ # Use v8
find_library(
JS_ENGINE_LIB
- jscexecutor
- PATHS ${LIBRN_DIR}
+ v8executor
+ PATHS ${LIBV8_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
- # Use Reanimated JSC
- file (GLOB LIBREANIMATED_DIR "${BUILD_DIR}/react-native-reanimated-*-jsc.aar/jni/${ANDROID_ABI}")
+ # Use Reanimated v8
+ file (GLOB LIBREANIMATED_DIR "${NODE_MODULES_DIR}/react-native-reanimated/android/build/intermediates/library_jni/*/jni/${ANDROID_ABI}")
endif()
find_library(
@@ -149,7 +151,7 @@ target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB}
${JSI_LIB}
- ${JS_ENGINE_LIB} # <-- Hermes or JSC
+ ${JS_ENGINE_LIB} # <-- Hermes or v8
${REANIMATED_LIB}
${REACT_NATIVE_JNI_LIB}
${FBJNI_LIB}
diff --git a/node_modules/react-native-vision-camera/android/build.gradle b/node_modules/react-native-vision-camera/android/build.gradle
index cd90d7b..190c6ab 100644
--- a/node_modules/react-native-vision-camera/android/build.gradle
+++ b/node_modules/react-native-vision-camera/android/build.gradle
@@ -239,7 +239,8 @@ dependencies {
def jsEngine = FOR_HERMES ? "hermes" : "jsc"
def reaAAR = "${nodeModules}/react-native-reanimated/android/react-native-reanimated-${minor}-${jsEngine}.aar"
- extractJNI(files(rnAAR, jscAAR, reaAAR))
+ // extractJNI(files(rnAAR, jscAAR, reaAAR))
+ extractJNI(files(rnAAR, jscAAR))
}
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
diff --git a/node_modules/react-native-vision-camera/android/src/main/cpp/MakeJSIRuntime.h b/node_modules/react-native-vision-camera/android/src/main/cpp/MakeJSIRuntime.h
index 39045bd..aa642f9 100644
--- a/node_modules/react-native-vision-camera/android/src/main/cpp/MakeJSIRuntime.h
+++ b/node_modules/react-native-vision-camera/android/src/main/cpp/MakeJSIRuntime.h
@@ -11,8 +11,8 @@
// Hermes
#include <hermes/hermes.h>
#else
- // JSC
- #include <jsi/JSCRuntime.h>
+ // v8
+ #include <v8runtime/V8RuntimeFactory.h>
#endif
namespace vision {
@@ -23,7 +23,10 @@ static std::unique_ptr<jsi::Runtime> makeJSIRuntime() {
#if FOR_HERMES
return facebook::hermes::makeHermesRuntime();
#else
- return facebook::jsc::makeJSCRuntime();
+ rnv8::V8RuntimeConfig config;
+ config.enableInspector = false;
+ config.appName = "reanimated";
+ return rnv8::createV8Runtime(config);
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment