diff --git a/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp b/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp index 4e23e0a861d..9a0068a4b8e 100644 --- a/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +++ b/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp @@ -45,19 +45,9 @@ class HermesExecutorRuntimeAdapter : public RuntimeAdapter { thread_->quitSynchronous(); } -#if REACT_NATIVE_MINOR_VERSION >= 71 facebook::hermes::HermesRuntime &getRuntime() override { return hermesRuntime_; } -#else - facebook::jsi::Runtime &getRuntime() override { - return hermesRuntime_; - } - - facebook::hermes::debugger::Debugger &getDebugger() override { - return hermesRuntime_.getDebugger(); - } -#endif // REACT_NATIVE_MINOR_VERSION // This is not empty in the original implementation, but we decided to tickle // the runtime by running a small piece of code on every frame as using this @@ -83,11 +73,7 @@ ReanimatedHermesRuntime::ReanimatedHermesRuntime( #if HERMES_ENABLE_DEBUGGER auto adapter = std::make_unique(*runtime_, jsQueue); -#if REACT_NATIVE_MINOR_VERSION >= 71 debugToken_ = chrome::enableDebugging(std::move(adapter), name); -#else - chrome::enableDebugging(std::move(adapter), name); -#endif // REACT_NATIVE_MINOR_VERSION #else // This is required by iOS, because there is an assertion in the destructor // that the thread was indeed `quit` before @@ -127,11 +113,7 @@ ReanimatedHermesRuntime::ReanimatedHermesRuntime( ReanimatedHermesRuntime::~ReanimatedHermesRuntime() { #if HERMES_ENABLE_DEBUGGER // We have to disable debugging before the runtime is destroyed. -#if REACT_NATIVE_MINOR_VERSION >= 71 chrome::disableDebugging(debugToken_); -#else - chrome::disableDebugging(*runtime_); -#endif // REACT_NATIVE_MINOR_VERSION #endif // HERMES_ENABLE_DEBUGGER } diff --git a/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h b/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h index 3b9b7cb463f..4a7df1b7d64 100644 --- a/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +++ b/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h @@ -138,9 +138,7 @@ class ReanimatedHermesRuntime std::unique_ptr runtime_; ReanimatedReentrancyCheck reentrancyCheck_; #if HERMES_ENABLE_DEBUGGER -#if REACT_NATIVE_MINOR_VERSION >= 71 chrome::DebugSessionToken debugToken_; -#endif // REACT_NATIVE_MINOR_VERSION >= 71 #endif // HERMES_ENABLE_DEBUGGER }; diff --git a/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp b/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp index ee3a6caf8a5..6db5bb804a3 100644 --- a/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp +++ b/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp @@ -11,11 +11,7 @@ #elif JS_RUNTIME_V8 #include #else -#if REACT_NATIVE_MINOR_VERSION >= 71 #include -#else -#include -#endif // REACT_NATIVE_MINOR_VERSION #endif // JS_RUNTIME namespace reanimated { diff --git a/Common/cpp/SharedItems/Shareables.cpp b/Common/cpp/SharedItems/Shareables.cpp index a0e002b036f..1d542933e80 100644 --- a/Common/cpp/SharedItems/Shareables.cpp +++ b/Common/cpp/SharedItems/Shareables.cpp @@ -94,10 +94,8 @@ jsi::Value makeShareableClone( shareable = std::make_shared(value.getBool()); } else if (value.isNumber()) { shareable = std::make_shared(value.getNumber()); -#if REACT_NATIVE_MINOR_VERSION >= 71 } else if (value.isBigInt()) { shareable = std::make_shared(rt, value.getBigInt(rt)); -#endif } else if (value.isSymbol()) { // TODO: this is only a placeholder implementation, here we replace symbols // with strings in order to make certain objects to be captured. There isn't @@ -200,11 +198,9 @@ ShareableObject::ShareableObject(jsi::Runtime &rt, const jsi::Object &object) auto value = extractShareableOrThrow(rt, object.getProperty(rt, key)); data_.emplace_back(key.utf8(rt), value); } -#if REACT_NATIVE_MINOR_VERSION >= 71 if (object.hasNativeState(rt)) { nativeState_ = object.getNativeState(rt); } -#endif } ShareableObject::ShareableObject( @@ -212,12 +208,10 @@ ShareableObject::ShareableObject( const jsi::Object &object, const jsi::Value &nativeStateSource) : ShareableObject(rt, object) { -#if REACT_NATIVE_MINOR_VERSION >= 71 if (nativeStateSource.isObject() && nativeStateSource.asObject(rt).hasNativeState(rt)) { nativeState_ = nativeStateSource.asObject(rt).getNativeState(rt); } -#endif } jsi::Value ShareableObject::toJSValue(jsi::Runtime &rt) { @@ -226,11 +220,9 @@ jsi::Value ShareableObject::toJSValue(jsi::Runtime &rt) { obj.setProperty( rt, data_[i].first.c_str(), data_[i].second->getJSValue(rt)); } -#if REACT_NATIVE_MINOR_VERSION >= 71 if (nativeState_ != nullptr) { obj.setNativeState(rt, nativeState_); } -#endif return obj; } @@ -297,13 +289,11 @@ jsi::Value ShareableString::toJSValue(jsi::Runtime &rt) { return jsi::String::createFromUtf8(rt, data_); } -#if REACT_NATIVE_MINOR_VERSION >= 71 jsi::Value ShareableBigInt::toJSValue(jsi::Runtime &rt) { return rt.global() .getPropertyAsFunction(rt, "BigInt") .call(rt, jsi::String::createFromUtf8(rt, string_)); } -#endif jsi::Value ShareableScalar::toJSValue(jsi::Runtime &) { switch (valueType_) { diff --git a/Common/cpp/SharedItems/Shareables.h b/Common/cpp/SharedItems/Shareables.h index e61bc580a49..46b06720f0e 100644 --- a/Common/cpp/SharedItems/Shareables.h +++ b/Common/cpp/SharedItems/Shareables.h @@ -192,9 +192,7 @@ class ShareableObject : public Shareable { protected: std::vector>> data_; -#if REACT_NATIVE_MINOR_VERSION >= 71 std::shared_ptr nativeState_; -#endif }; class ShareableHostObject : public Shareable { @@ -322,7 +320,6 @@ class ShareableString : public Shareable { const std::string data_; }; -#if REACT_NATIVE_MINOR_VERSION >= 71 class ShareableBigInt : public Shareable { public: explicit ShareableBigInt(jsi::Runtime &rt, const jsi::BigInt &bigint) @@ -333,7 +330,6 @@ class ShareableBigInt : public Shareable { protected: const std::string string_; }; -#endif class ShareableScalar : public Shareable { public: diff --git a/Common/cpp/Tools/JSISerializer.cpp b/Common/cpp/Tools/JSISerializer.cpp index 44d1b9077b7..fd9f7cf6703 100644 --- a/Common/cpp/Tools/JSISerializer.cpp +++ b/Common/cpp/Tools/JSISerializer.cpp @@ -275,11 +275,9 @@ std::string JSISerializer::stringifyJSIValueRecursively( if (value.isSymbol()) { return value.getSymbol(rt_).toString(rt_); } -#if REACT_NATIVE_MINOR_VERSION >= 71 if (value.isBigInt()) { return value.getBigInt(rt_).toString(rt_).utf8(rt_) + 'n'; } -#endif if (value.isUndefined()) { return "undefined"; } diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index 8ba41221e81..42a058b411d 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -10,13 +10,8 @@ endif() # default CMAKE_CXX_FLAGS: "-g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-protector-all" -if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 71) - include("${REACT_NATIVE_DIR}/ReactAndroid/cmake-utils/folly-flags.cmake") - add_compile_options(${folly_FLAGS}) -else() - set(folly_FLAGS "-DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DFOLLY_HAVE_RECVMMSG=1 -DFOLLY_HAVE_PTHREAD=1") - string(APPEND CMAKE_CXX_FLAGS " ${folly_FLAGS}") -endif() +include("${REACT_NATIVE_DIR}/ReactAndroid/cmake-utils/folly-flags.cmake") +add_compile_options(${folly_FLAGS}) string(APPEND CMAKE_CXX_FLAGS " -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION} -DREANIMATED_VERSION=${REANIMATED_VERSION} -DHERMES_ENABLE_DEBUGGER=${HERMES_ENABLE_DEBUGGER}") @@ -45,22 +40,11 @@ set (COMMON_SRC_DIR "${CMAKE_SOURCE_DIR}/../Common") file(GLOB_RECURSE SOURCES_COMMON CONFIGURE_DEPENDS "${COMMON_SRC_DIR}/cpp/**.cpp") file(GLOB_RECURSE SOURCES_ANDROID CONFIGURE_DEPENDS "${SRC_DIR}/main/cpp/**.cpp") -if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 71) - # Consume shared libraries and headers from prefabs - find_package(fbjni REQUIRED CONFIG) - find_package(ReactAndroid REQUIRED CONFIG) - if(${JS_RUNTIME} STREQUAL "hermes") - find_package(hermes-engine REQUIRED CONFIG) - endif() -else() - # Consume shared libraries from found .so files - if(${IS_NEW_ARCHITECTURE_ENABLED}) - message(FATAL_ERROR "not supported") - else() - set (RN_SO_DIR "${REACT_NATIVE_DIR}/ReactAndroid/src/main/jni/first-party/react/jni") - set (FBJNI_HEADERS_DIR "${REACT_NATIVE_DIR}/ReactAndroid/src/main/jni/first-party/fbjni/headers") - endif() - file (GLOB LIBRN_DIR "${RN_SO_DIR}/${ANDROID_ABI}") +# Consume shared libraries and headers from prefabs +find_package(fbjni REQUIRED CONFIG) +find_package(ReactAndroid REQUIRED CONFIG) +if(${JS_RUNTIME} STREQUAL "hermes") + find_package(hermes-engine REQUIRED CONFIG) endif() add_library( @@ -89,43 +73,16 @@ target_include_directories( "${SRC_DIR}/main/cpp" ) -if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 71) - target_include_directories( - ${PACKAGE_NAME} - PRIVATE - "${REACT_NATIVE_DIR}/ReactAndroid/src/main/jni/react/turbomodule" - "${REACT_NATIVE_DIR}/ReactCommon" - "${REACT_NATIVE_DIR}/ReactCommon/callinvoker" - "${REACT_NATIVE_DIR}/ReactCommon/react/renderer/graphics/platform/cxx" - "${REACT_NATIVE_DIR}/ReactCommon/runtimeexecutor" - "${REACT_NATIVE_DIR}/ReactCommon/yoga" - ) -else() - file(GLOB LIBFBJNI_INCLUDE_DIR ${FBJNI_HEADERS_DIR}) - target_include_directories( - ${PACKAGE_NAME} - PRIVATE - "${LIBFBJNI_INCLUDE_DIR}" - "${BUILD_DIR}/third-party-ndk/boost/boost_${BOOST_VERSION}" - "${BUILD_DIR}/third-party-ndk/double-conversion" - "${BUILD_DIR}/third-party-ndk/folly" - "${BUILD_DIR}/third-party-ndk/glog/exported" - "${REACT_NATIVE_DIR}/React" - "${REACT_NATIVE_DIR}/React/Base" - "${REACT_NATIVE_DIR}/ReactAndroid/src/main/jni" - "${REACT_NATIVE_DIR}/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni" - "${REACT_NATIVE_DIR}/ReactAndroid/src/main/java/com/facebook/react/fabric/jni" - "${REACT_NATIVE_DIR}/ReactCommon" - "${REACT_NATIVE_DIR}/ReactCommon/callinvoker" - "${REACT_NATIVE_DIR}/ReactCommon/jsi" - "${REACT_NATIVE_DIR}/ReactCommon/hermes" - "${REACT_NATIVE_DIR}/ReactCommon/react/renderer/graphics/platform/cxx" - "${REACT_NATIVE_DIR}/ReactCommon/runtimeexecutor" - "${REACT_NATIVE_DIR}/ReactCommon/turbomodule/core" - "${REACT_NATIVE_DIR}/ReactCommon/turbomodule" - "${REACT_NATIVE_DIR}/ReactCommon/yoga" - ) -endif() +target_include_directories( + ${PACKAGE_NAME} + PRIVATE + "${REACT_NATIVE_DIR}/ReactAndroid/src/main/jni/react/turbomodule" + "${REACT_NATIVE_DIR}/ReactCommon" + "${REACT_NATIVE_DIR}/ReactCommon/callinvoker" + "${REACT_NATIVE_DIR}/ReactCommon/react/renderer/graphics/platform/cxx" + "${REACT_NATIVE_DIR}/ReactCommon/runtimeexecutor" + "${REACT_NATIVE_DIR}/ReactCommon/yoga" +) # build shared lib @@ -137,127 +94,25 @@ target_link_libraries( android ) -if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 71) - target_link_libraries( - ${PACKAGE_NAME} - ReactAndroid::folly_runtime - ReactAndroid::glog - ReactAndroid::jsi - ReactAndroid::reactnativejni - fbjni::fbjni - ) -else() - find_library( - JSI_LIB - jsi - PATHS ${LIBRN_DIR} - NO_DEFAULT_PATH - NO_CMAKE_FIND_ROOT_PATH - ) - find_library( - GLOG_LIB - glog - PATHS ${LIBRN_DIR} - NO_DEFAULT_PATH - NO_CMAKE_FIND_ROOT_PATH - ) - - find_library( - FBJNI_LIB - fbjni - PATHS ${LIBRN_DIR} - NO_DEFAULT_PATH - NO_CMAKE_FIND_ROOT_PATH - ) - - if(${REACT_NATIVE_MINOR_VERSION} LESS 69) - find_library( - FOLLY_LIB - folly_json - PATHS ${LIBRN_DIR} - NO_DEFAULT_PATH - NO_CMAKE_FIND_ROOT_PATH - ) - else() - find_library( - FOLLY_LIB - folly_runtime - PATHS ${LIBRN_DIR} - NO_DEFAULT_PATH - NO_CMAKE_FIND_ROOT_PATH - ) - endif() - - find_library( - REACTNATIVEJNI_LIB - reactnativejni - PATHS ${LIBRN_DIR} - NO_DEFAULT_PATH - NO_CMAKE_FIND_ROOT_PATH - ) - - target_link_libraries( - ${PACKAGE_NAME} - ${JSI_LIB} - ${GLOG_LIB} - ${FBJNI_LIB} - ${FOLLY_LIB} - ${REACTNATIVEJNI_LIB} - ) -endif() +target_link_libraries( + ${PACKAGE_NAME} + ReactAndroid::folly_runtime + ReactAndroid::glog + ReactAndroid::jsi + ReactAndroid::reactnativejni + fbjni::fbjni +) if(${JS_RUNTIME} STREQUAL "hermes") string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_HERMES=1") - if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 71) - # From prefab from module `com.facebook.react:hermes-android` - set(HERMES_LIB hermes-engine::libhermes) - elseif(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 69) - # Bundled Hermes from module `com.facebook.react:hermes-engine` or project `:ReactAndroid:hermes-engine` - target_include_directories( - ${PACKAGE_NAME} - PRIVATE - "${JS_RUNTIME_DIR}/API" - "${JS_RUNTIME_DIR}/public" - ) - set(HERMES_LIB "${BUILD_DIR}/third-party-ndk/hermes/jni/${ANDROID_ABI}/libhermes.so") - else() - # From `hermes-engine` npm package - target_include_directories( - ${PACKAGE_NAME} - PRIVATE - "${JS_RUNTIME_DIR}/android/include" - ) - set(HERMES_LIB "${BUILD_DIR}/third-party-ndk/hermes/jni/${ANDROID_ABI}/libhermes.so") - endif() + # From prefab from module `com.facebook.react:hermes-android` + set(HERMES_LIB hermes-engine::libhermes) target_link_libraries( ${PACKAGE_NAME} ${HERMES_LIB} ) if (${HERMES_ENABLE_DEBUGGER}) - if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 71) - set(HERMES_EXECUTOR_LIB ReactAndroid::hermes_executor) - else() - find_library( - HERMES_EXECUTOR_LIB - hermes-executor-debug - PATHS ${LIBRN_DIR} - NO_DEFAULT_PATH - NO_CMAKE_FIND_ROOT_PATH - ) - endif() - if(${REACT_NATIVE_MINOR_VERSION} LESS_EQUAL 67) - find_library( - HERMES_INSPECTOR_LIB - hermes-inspector - PATHS ${LIBRN_DIR} - NO_DEFAULT_PATH - NO_CMAKE_FIND_ROOT_PATH - ) - target_link_libraries( - ${PACKAGE_NAME} - ${HERMES_INSPECTOR_LIB} - ) - endif() + set(HERMES_EXECUTOR_LIB ReactAndroid::hermes_executor) target_link_libraries( ${PACKAGE_NAME} ${HERMES_EXECUTOR_LIB} @@ -284,17 +139,7 @@ elseif(${JS_RUNTIME} STREQUAL "v8") ) elseif(${JS_RUNTIME} STREQUAL "jsc") string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_JSC=1") - if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 71) - set(JSEXECUTOR_LIB ReactAndroid::jscexecutor) - else() - find_library( - JSEXECUTOR_LIB - jscexecutor - PATHS ${LIBRN_DIR} - NO_DEFAULT_PATH - NO_CMAKE_FIND_ROOT_PATH - ) - endif() + set(JSEXECUTOR_LIB ReactAndroid::jscexecutor) target_link_libraries(${PACKAGE_NAME} ${JSEXECUTOR_LIB}) else() message(FATAL_ERROR "Unknown JS runtime ${JS_RUNTIME}.") @@ -316,4 +161,3 @@ endif() # Resolves "CMake Warning: Manually-specified variables were not used by the project" # when any of the following variables is not used in some build configuration. set (ignoreMe "${JS_RUNTIME_DIR}") -set (ignoreMe "${BOOST_VERSION}") diff --git a/android/build.gradle b/android/build.gradle index b9aab4871d1..e0714155676 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -145,13 +145,6 @@ def REANIMATED_VERSION = getReanimatedVersion() def REANIMATED_MAJOR_VERSION = getReanimatedMajorVersion() def IS_NEW_ARCHITECTURE_ENABLED = isNewArchitectureEnabled() -// for React Native <= 0.70 -def BOOST_VERSION = reactProperties.getProperty("BOOST_VERSION") -def DOUBLE_CONVERSION_VERSION = reactProperties.getProperty("DOUBLE_CONVERSION_VERSION") -def FOLLY_VERSION = reactProperties.getProperty("FOLLY_VERSION") -def GLOG_VERSION = reactProperties.getProperty("GLOG_VERSION") -def FBJNI_VERSION = "0.3.0" - // We download various C++ open-source dependencies into downloads. // We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk. // After that we build native code from src/main/jni with module path pointing at third-party-ndk. @@ -179,7 +172,7 @@ def JS_RUNTIME = { // Check if Hermes is enabled in app setup def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') } - if ((REACT_NATIVE_MINOR_VERSION >= 71 && appProject?.hermesEnabled?.toBoolean()) || appProject?.ext?.react?.enableHermes?.toBoolean()) { + if (appProject?.hermesEnabled?.toBoolean() || appProject?.ext?.react?.enableHermes?.toBoolean()) { return "hermes" } @@ -189,11 +182,7 @@ def JS_RUNTIME = { def jsRuntimeDir = { if (JS_RUNTIME == "hermes") { - if (REACT_NATIVE_MINOR_VERSION >= 69) { - return Paths.get(reactNativeRootDir.path, "sdks", "hermes") - } else { - return Paths.get(reactNativeRootDir.path, "..", "hermes-engine") - } + return Paths.get(reactNativeRootDir.path, "sdks", "hermes") } else if (JS_RUNTIME == "v8") { return findProject(":react-native-v8").getProjectDir().getParent() } else { @@ -245,11 +234,9 @@ android { } buildFeatures { - if (REACT_NATIVE_MINOR_VERSION > 68) { - prefab true - prefabPublishing true - buildConfig true - } + prefab true + prefabPublishing true + buildConfig true } prefab { @@ -270,7 +257,6 @@ android { arguments "-DANDROID_STL=c++_shared", "-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}", "-DANDROID_TOOLCHAIN=clang", - REACT_NATIVE_MINOR_VERSION < 71 ? "-DBOOST_VERSION=${BOOST_VERSION}" : "-DBOOST_VERSION=", "-DREACT_NATIVE_DIR=${toPlatformFileString(reactNativeRootDir.path)}", "-DJS_RUNTIME=${JS_RUNTIME}", "-DJS_RUNTIME_DIR=${jsRuntimeDir}", @@ -403,20 +389,20 @@ android { } def assertLatestReactNativeWithNewArchitecture = task assertLatestReactNativeWithNewArchitectureTask { - onlyIf { IS_NEW_ARCHITECTURE_ENABLED && REANIMATED_MAJOR_VERSION == 3 && REACT_NATIVE_MINOR_VERSION < 72 } + onlyIf { IS_NEW_ARCHITECTURE_ENABLED && REANIMATED_MAJOR_VERSION == 3 && REACT_NATIVE_MINOR_VERSION < 74 } doFirst { // If you change the minimal React Native version remember to update Compatibility Table in docs throw new GradleException( - "[Reanimated] Outdated version of React Native for New Architecture. Reanimated " + REANIMATED_VERSION + " supports the New Architecture on React Native 0.72.0+. See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#outdated-version-of-react-native-for-new-architecture for more information." + "[Reanimated] Outdated version of React Native for New Architecture. Reanimated " + REANIMATED_VERSION + " supports the New Architecture on React Native 0.74.0+. See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#outdated-version-of-react-native-for-new-architecture for more information." ) } } def assertMinimalReactNativeVersion = task assertMinimalReactNativeVersionTask { - onlyIf { REACT_NATIVE_MINOR_VERSION < 66 } + onlyIf { REACT_NATIVE_MINOR_VERSION < 71 } doFirst { // If you change the minimal React Native version remember to update Compatibility Table in docs - throw new GradleException("[Reanimated] Unsupported React Native version. Please use 0.66 or newer.") + throw new GradleException("[Reanimated] Unsupported React Native version. Please use 0.71 or newer.") } } @@ -478,354 +464,6 @@ def resolveTaskFactory(String taskName, String artifactLocalName, File reactNati } } -/* -Reanimated includes "hermes/hermes.h" header file in `NativeProxy.cpp`. -Previously, we used header files from `hermes-engine` package in `node_modules`. -In React Native 0.69 and 0.70, Hermes is no longer distributed as package on NPM. -On the new architecture, Hermes is downloaded from GitHub and then compiled from sources. -However, on the old architecture, we need to download Hermes header files on our own -as well as unzip Hermes AAR in order to obtain `libhermes.so` shared library. -For more details, see https://reactnative.dev/architecture/bundled-hermes -or https://github.com/reactwg/react-native-new-architecture/discussions/4 -*/ -if (REACT_NATIVE_MINOR_VERSION in [69, 70] && !IS_NEW_ARCHITECTURE_ENABLED) { - // copied from `react-native/ReactAndroid/hermes-engine/build.gradle` - - def downloadDir = customDownloadsDir ? new File(customDownloadsDir) : new File(reactNativeRootDir, "sdks/download") - - // By default we are going to download and unzip hermes inside the /sdks/hermes folder - // but you can provide an override for where the hermes source code is located. - def hermesDir = System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR") ?: new File(reactNativeRootDir, "sdks/hermes") - - def hermesVersion = "main" - def hermesVersionFile = new File(reactNativeRootDir, "sdks/.hermesversion") - if (hermesVersionFile.exists()) { - hermesVersion = hermesVersionFile.text - } - - task downloadHermes(type: Download) { - src("https://github.com/facebook/hermes/tarball/${hermesVersion}") - onlyIfNewer(true) - overwrite(false) - dest(new File(downloadDir, "hermes.tar.gz")) - } - - task unzipHermes(dependsOn: downloadHermes, type: Copy) { - from(tarTree(downloadHermes.dest)) { - eachFile { file -> - // We flatten the unzip as the tarball contains a `facebook-hermes-` - // folder at the top level. - if (file.relativePath.segments.size() > 1) { - file.relativePath = new RelativePath(!file.isDirectory(), file.relativePath.segments.drop(1)) - } - } - } - into(hermesDir) - } -} - -if (REACT_NATIVE_MINOR_VERSION < 71) { - // You need to have following folders in this directory: - // - boost_1_63_0 - // - double-conversion-1.1.6 - // - folly-deprecate-dynamic-initializer - // - glog-0.3.5 - def dependenciesPath = System.getenv("REACT_NATIVE_DEPENDENCIES") - - // The Boost library is a very large download (>100MB). - // If Boost is already present on your system, define the REACT_NATIVE_BOOST_PATH env variable - // and the build will use that. - def boostPath = dependenciesPath ?: System.getenv("REACT_NATIVE_BOOST_PATH") - - def follyReplaceContent = ''' - ssize_t r; - do { - r = open(name, flags, mode); - } while (r == -1 && errno == EINTR); - return r; - ''' - - Task resolveBoost = resolveTaskFactory("resolveBoost", "boost_${BOOST_VERSION}.tar.gz", reactNativeAndroidDownloadDir, downloadsDir) - Task resolveDoubleConversion = resolveTaskFactory( - "resolveDoubleConversion", - "double-conversion-${DOUBLE_CONVERSION_VERSION}.tar.gz", - reactNativeAndroidDownloadDir, - downloadsDir - ) - Task resolveFolly = resolveTaskFactory("resolveFolly", "folly-${FOLLY_VERSION}.tar.gz", reactNativeAndroidDownloadDir, downloadsDir) - Task resolveGlog = resolveTaskFactory("resolveGlog", "glog-${GLOG_VERSION}.tar.gz", reactNativeAndroidDownloadDir, downloadsDir) - - if (IS_NEW_ARCHITECTURE_ENABLED) { - def reactNativeAndroidProject = findProject(":ReactAndroid") - if (reactNativeAndroidProject != null) { - reactNativeAndroidProject.afterEvaluate { - def resolveTasks = [resolveBoost, resolveGlog, resolveDoubleConversion, resolveFolly] - resolveTasks.forEach({ task -> - String reactAndroidDownloadTaskName = "download" + task.name.replace("resolve", "") - def reactAndroidDownloadTask = reactNativeAndroidProject.getTasks().findByName(reactAndroidDownloadTaskName) - if (reactAndroidDownloadTask != null) { - task.dependsOn(reactAndroidDownloadTask) - } else { - logger.warn("[Reanimated] Failed to find task named `$reactAndroidDownloadTaskName` in `:ReactAndroid` project." + - " Explicit dependency between it and $task.name task can not be set.") - } - }) - } - } else { - throw new GradleException("[Reanimated] Failed to find `:ReactAndroid` project. Explicit dependency between download tasks can not be set.") - } - } - - task downloadBoost(dependsOn: resolveBoost, type: Download) { - def transformedVersion = BOOST_VERSION.replace("_", ".") - def artifactLocalName = "boost_${BOOST_VERSION}.tar.gz" - def srcUrl = "https://archives.boost.io/release/${transformedVersion}/source/${artifactLocalName}" - if (REACT_NATIVE_MINOR_VERSION < 69) { - srcUrl = "https://github.com/react-native-community/boost-for-react-native/releases/download/v${transformedVersion}-0/${artifactLocalName}" - } - src(srcUrl) - onlyIfNewer(true) - overwrite(false) - dest(new File(downloadsDir, artifactLocalName)) - } - - task prepareBoost(dependsOn: boostPath ? [] : [downloadBoost], type: Copy) { - from(boostPath ?: tarTree(resources.gzip(downloadBoost.dest))) - from("$reactNativeThirdParty/boost/Android.mk") - include("Android.mk", "boost_${BOOST_VERSION}/boost/**/*.hpp", "boost/boost/**/*.hpp") - includeEmptyDirs = false - into("$thirdPartyNdkDir/boost") - doLast { - file("$thirdPartyNdkDir/boost/boost").renameTo("$thirdPartyNdkDir/boost/boost_${BOOST_VERSION}") - } - } - - task downloadDoubleConversion(dependsOn: resolveDoubleConversion, type: Download) { - src("https://github.com/google/double-conversion/archive/v${DOUBLE_CONVERSION_VERSION}.tar.gz") - onlyIfNewer(true) - overwrite(false) - dest(new File(downloadsDir, "double-conversion-${DOUBLE_CONVERSION_VERSION}.tar.gz")) - } - - task prepareDoubleConversion(dependsOn: dependenciesPath ? [] : [downloadDoubleConversion], type: Copy) { - from(dependenciesPath ?: tarTree(downloadDoubleConversion.dest)) - from("$reactNativeThirdParty/double-conversion/Android.mk") - include("double-conversion-${DOUBLE_CONVERSION_VERSION}/src/**/*", "Android.mk") - filesMatching("*/src/**/*", { fname -> fname.path = "double-conversion/${fname.name}" }) - includeEmptyDirs = false - into("$thirdPartyNdkDir/double-conversion") - } - - task downloadFolly(dependsOn: resolveFolly, type: Download) { - src("https://github.com/facebook/folly/archive/v${FOLLY_VERSION}.tar.gz") - onlyIfNewer(true) - overwrite(false) - dest(new File(downloadsDir, "folly-${FOLLY_VERSION}.tar.gz")) - } - - task prepareFolly(dependsOn: dependenciesPath ? [] : [downloadFolly], type: Copy) { - from(dependenciesPath ?: tarTree(downloadFolly.dest)) - from("$reactNativeThirdParty/folly/Android.mk") - include("folly-${FOLLY_VERSION}/folly/**/*", "Android.mk") - eachFile { fname -> fname.path = (fname.path - "folly-${FOLLY_VERSION}/") } - // Fixes problem with Folly failing to build on certain systems. See - // https://github.com/software-mansion/react-native-reanimated/issues/1024 - filter { line -> line.replaceAll("return int\\(wrapNoInt\\(open, name, flags, mode\\)\\);", follyReplaceContent) } - includeEmptyDirs = false - into("$thirdPartyNdkDir/folly") - } - - task downloadGlog(dependsOn: resolveGlog, type: Download) { - src("https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz") - onlyIfNewer(true) - overwrite(false) - dest(new File(downloadsDir, "glog-${GLOG_VERSION}.tar.gz")) - } - - // Prepare glog sources to be compiled, this task will perform steps that normally should've been - // executed by automake. This way we can avoid dependencies on make/automake - task prepareGlog(dependsOn: dependenciesPath ? [] : [downloadGlog], type: Copy) { - duplicatesStrategy = "include" - from(dependenciesPath ?: tarTree(downloadGlog.dest)) - from("$reactNativeThirdParty/glog/") - include("glog-${GLOG_VERSION}/src/**/*", "Android.mk", "config.h") - includeEmptyDirs = false - filesMatching("**/*.h.in") { - filter(ReplaceTokens, tokens: [ - ac_cv_have_unistd_h : "1", - ac_cv_have_stdint_h : "1", - ac_cv_have_systypes_h : "1", - ac_cv_have_inttypes_h : "1", - ac_cv_have_libgflags : "0", - ac_google_start_namespace : "namespace google {", - ac_cv_have_uint16_t : "1", - ac_cv_have_u_int16_t : "1", - ac_cv_have___uint16 : "0", - ac_google_end_namespace : "}", - ac_cv_have___builtin_expect : "1", - ac_google_namespace : "google", - ac_cv___attribute___noinline : "__attribute__ ((noinline))", - ac_cv___attribute___noreturn : "__attribute__ ((noreturn))", - ac_cv___attribute___printf_4_5: "__attribute__((__format__ (__printf__, 4, 5)))" - ]) - it.path = (it.name - ".in") - } - into("$thirdPartyNdkDir/glog") - - doLast { - copy { - from(fileTree(dir: "$thirdPartyNdkDir/glog", includes: ["stl_logging.h", "logging.h", "raw_logging.h", "vlog_is_on.h", "**/src/glog/log_severity.h"]).files) - includeEmptyDirs = false - into("$thirdPartyNdkDir/glog/exported/glog") - } - } - } - - task prepareHermes { - if (REACT_NATIVE_MINOR_VERSION >= 69) { - if (!IS_NEW_ARCHITECTURE_ENABLED) { - dependsOn(unzipHermes) - } - - doLast { - // e.g. hermes-engine-0.70.0-rc.1-debug.aar - def hermesAAR = file( - "$reactNativeRootDir/android/com/facebook/react/hermes-engine/" + - "${REACT_NATIVE_VERSION}/hermes-engine-${REACT_NATIVE_VERSION}-" + - "${resolveBuildType()}.aar" - ) - if (!hermesAAR.exists()) { - throw new GradleException("[Reanimated] Could not find hermes-engine AAR.", null) - } - - def soFiles = zipTree(hermesAAR).matching({ it.include "**/*.so" }) - - copy { - from soFiles - from "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/hermes/Android.mk" - into "$thirdPartyNdkDir/hermes" - } - } - } else { - doLast { - def hermesPackagePath = findNodeModulePath(projectDir, "hermes-engine") - if (!hermesPackagePath) { - throw new GradleException("[Reanimated] Could not find the hermes-engine npm package.", null) - } - - def hermesAAR = file("$hermesPackagePath/android/hermes-${resolveBuildType()}.aar") // e.g. hermes-debug.aar - if (!hermesAAR.exists()) { - throw new GradleException("[Reanimated] The hermes-engine npm package is missing \"android/hermes-${resolveBuildType()}.aar\".", null) - } - - def soFiles = zipTree(hermesAAR).matching({ it.include "**/*.so" }) - - copy { - from soFiles - from "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/hermes/Android.mk" - into "$thirdPartyNdkDir/hermes" - } - } - } - } - - task prepareJSC { - if (REACT_NATIVE_MINOR_VERSION >= 71) { - // do nothing - } else { - doLast { - def jscPackagePath = findNodeModulePath(projectDir, "jsc-android") - if (!jscPackagePath) { - throw new GradleException("[Reanimated] Could not find the jsc-android npm package.", null) - } - - def jscDist = file("$jscPackagePath/dist") - if (!jscDist.exists()) { - throw new GradleException("[Reanimated] The jsc-android npm package is missing its \"dist\" directory.", null) - } - - def jscAAR = fileTree(jscDist).matching({ it.include "**/android-jsc/**/*.aar" }).singleFile - def soFiles = zipTree(jscAAR).matching({ it.include "**/*.so" }) - - def headerFiles = fileTree(jscDist).matching({ it.include "**/include/*.h" }) - - copy { - from(soFiles) - from(headerFiles) - from("$reactNativeRootDir/ReactAndroid/src/main/jni/third-party/jsc/Android.mk") - - filesMatching("**/*.h", { it.path = "JavaScriptCore/${it.name}" }) - - includeEmptyDirs(false) - into("$thirdPartyNdkDir/jsc") - } - } - } - } - - task extractAARHeaders { - doLast { - configurations.extractHeaders.files.each { - def file = it.absoluteFile - def packageName = file.name.tokenize('-')[0] - copy { - from zipTree(file) - into "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/$packageName/headers" - include "**/*.h" - } - } - } - } - - task extractSOFiles { - doLast { - configurations.extractSO.files.each { - def file = it.absoluteFile - def packageName = file.name.tokenize('-')[0] - copy { - from zipTree(file) - into "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/$packageName/" - include "jni/**/*.so" - } - } - } - } - - task unpackReactNativeAAR { - def buildType = resolveBuildType() - def rnAarMatcher = "**/react-native/**/*${buildType}.aar" - if (REACT_NATIVE_MINOR_VERSION < 69) { - rnAarMatcher = "**/**/*.aar" - } - def rnAAR = fileTree("$reactNativeRootDir/android").matching({ it.include rnAarMatcher }).singleFile - def file = rnAAR.absoluteFile - def packageName = file.name.tokenize('-')[0] - copy { - from zipTree(file) - into "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/$packageName/" - include "jni/**/*.so" - } - } - - task downloadNdkBuildDependencies { - if (!boostPath) { - dependsOn(downloadBoost) - } - dependsOn(downloadDoubleConversion) - dependsOn(downloadFolly) - dependsOn(downloadGlog) - } - - task prepareThirdPartyNdkHeaders(dependsOn:[ - downloadNdkBuildDependencies, - prepareBoost, - prepareDoubleConversion, - prepareFolly, - prepareGlog, - unpackReactNativeAAR] - ) {} -} - task packageNdkLibs(type: Copy) { from("$buildDir/reanimated-ndk/all") include("**/libreanimated.so") @@ -851,21 +489,9 @@ dependencies { implementation "androidx.transition:transition:1.1.0" implementation "androidx.core:core:1.6.0" - if (REACT_NATIVE_MINOR_VERSION >= 71) { - implementation "com.facebook.react:react-android" // version substituted by RNGP - if (JS_RUNTIME == "hermes") { - implementation "com.facebook.react:hermes-android" // version substituted by RNGP - } - } else { - // noinspection GradleDynamicVersion - implementation "com.facebook.react:react-native:+" // From node_modules - implementation "com.facebook.fbjni:fbjni-java-only:" + FBJNI_VERSION - - extractHeaders("com.facebook.fbjni:fbjni:" + FBJNI_VERSION + ":headers") - extractSO("com.facebook.fbjni:fbjni:" + FBJNI_VERSION) - - def jscAAR = fileTree("$reactNativeRootDir/../jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile - extractSO(files(jscAAR)) + implementation "com.facebook.react:react-android" // version substituted by RNGP + if (JS_RUNTIME == "hermes") { + implementation "com.facebook.react:hermes-android" // version substituted by RNGP } } @@ -881,15 +507,6 @@ def nativeBuildDependsOn(dependsOnTask) { } afterEvaluate { - if (REACT_NATIVE_MINOR_VERSION < 71) { - extractAARHeaders.dependsOn(prepareThirdPartyNdkHeaders) - extractSOFiles.dependsOn(prepareThirdPartyNdkHeaders) - - nativeBuildDependsOn(prepareThirdPartyNdkHeaders) - nativeBuildDependsOn(extractAARHeaders) - nativeBuildDependsOn(extractSOFiles) - } - preBuild.dependsOn(prepareHeadersForPrefab) tasks.forEach({ task -> @@ -899,10 +516,7 @@ afterEvaluate { }) if (JS_RUNTIME == "hermes") { - if (REACT_NATIVE_MINOR_VERSION < 71) { - extractAARHeaders.dependsOn(prepareHermes) - extractSOFiles.dependsOn(prepareHermes) - } + // Do nothing } else if (JS_RUNTIME == "v8") { def buildTasks = tasks.findAll({ task -> !task.name.contains("Clean") && (task.name.contains("externalNative") || task.name.contains("CMake") || task.name.startsWith("generateJsonModel")) }) @@ -911,10 +525,7 @@ afterEvaluate { task.dependsOn(":react-native-v8:copy${buildType}JniLibsProjectOnly") } } else if (JS_RUNTIME == "jsc") { - if (REACT_NATIVE_MINOR_VERSION < 71) { - extractAARHeaders.dependsOn(prepareJSC) - extractSOFiles.dependsOn(prepareJSC) - } + // Do nothing } else { throw GradleScriptException("[Reanimated] Unknown JS runtime ${JS_RUNTIME}.") } diff --git a/docs/docs/guides/compatibility.mdx b/docs/docs/guides/compatibility.mdx index f5a0ebce676..8c7398cf86e 100644 --- a/docs/docs/guides/compatibility.mdx +++ b/docs/docs/guides/compatibility.mdx @@ -11,7 +11,7 @@ sidebar_label: Compatibility | | 0.63 | 0.64 | 0.65 | 0.66 | 0.67 | 0.68 | 0.69 | 0.70 | 0.71 | 0.72 | 0.73 | 0.74 | | ------------------------------------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | -| | | | | | | | | | | | | | +| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | diff --git a/scripts/reanimated_utils.rb b/scripts/reanimated_utils.rb index ae4da55610a..ac721050d3e 100644 --- a/scripts/reanimated_utils.rb +++ b/scripts/reanimated_utils.rb @@ -53,15 +53,15 @@ def assert_latest_react_native_with_new_architecture(config, reanimated_package_ reanimated_major_version = reanimated_version.split('.')[0].to_i react_native_minor_version = config[:react_native_minor_version] fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1' - if fabric_enabled && reanimated_major_version == 3 && react_native_minor_version < 72 + if fabric_enabled && reanimated_major_version == 3 && react_native_minor_version < 74 # If you change the minimal React Native version remember to update Compatibility Table in docs - raise "[Reanimated] Outdated version of React Native for New Architecture. Reanimated " + reanimated_version + " supports the New Architecture on React Native 0.72.0+. See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#outdated-version-of-react-native-for-new-architecture for more information." + raise "[Reanimated] Outdated version of React Native for New Architecture. Reanimated " + reanimated_version + " supports the New Architecture on React Native 0.74.0+. See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#outdated-version-of-react-native-for-new-architecture for more information." end end def assert_minimal_react_native_version(config) - if config[:react_native_minor_version] < 66 + if config[:react_native_minor_version] < 71 # If you change the minimal React Native version remember to update Compatibility Table in docs - raise "[Reanimated] Unsupported React Native version. Please use 0.66 or newer." + raise "[Reanimated] Unsupported React Native version. Please use 0.71 or newer." end end