From 5469a1d6124e60b1e5eab162198d6f157733d16b Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Wed, 9 Nov 2022 15:19:20 +0100 Subject: [PATCH] feat: add support for react-native 0.71 When upgrading to this version, please update your `build.gradle` to using `getReactNativeDependencies()`. This will reduce breakages when moving to 0.71 and beyond: ```diff diff --git a/example/android/build.gradle b/example/android/build.gradle index 984a681..29ef8ce 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,7 +1,6 @@ buildscript { def androidTestAppDir = "../node_modules/react-native-test-app/android" apply(from: "${androidTestAppDir}/dependencies.gradle") - apply(from: "${androidTestAppDir}/test-app-util.gradle") repositories { mavenCentral() @@ -9,12 +8,8 @@ buildscript { } dependencies { - classpath("com.android.tools.build:gradle:${androidPluginVersion}") - - def isNightly = getPackageVersionNumber("react-native", rootDir) == 0 - if (isNightly || isNewArchitectureEnabled(project)) { - classpath("com.facebook.react:react-native-gradle-plugin") - classpath("de.undercouch:gradle-download-task:5.3.0") + getReactNativeDependencies().each { dependency -> + classpath(dependency) } } } ``` --- CONTRIBUTING.md | 27 +++ android/app/build.gradle | 173 ++++++++++-------- android/app/src/main/AndroidManifest.xml | 16 +- android/app/src/main/jni/CMakeLists.txt | 32 ++-- .../app/src/main/jni/ComponentsRegistry.cpp | 7 +- android/app/src/main/jni/ComponentsRegistry.h | 8 +- android/dependencies.gradle | 19 +- example/android/build.gradle | 9 +- example/package.json | 8 +- ios/pod_helpers.rb | 4 +- package.json | 2 +- scripts/configure.js | 8 +- scripts/pack.mjs | 4 +- scripts/test-matrix.sh | 8 +- test-app.gradle | 7 +- test/android-test-app/test-app-util.test.js | 5 +- .../__snapshots__/gatherConfig.test.js.snap | 24 +-- yarn.lock | 4 +- 18 files changed, 208 insertions(+), 157 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f9df34b3d..9c0034b24 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -191,3 +191,30 @@ To avoid issues, remember to clear out `node_modules` folders before you run yarn clean yarn ``` + +## Adding Support For New React Native Versions + +First, create a new issue using the "New `react-native` version" template, +update the title, and fill out all the required fields. + +When opening a PR, link to the issue that was created, and use the table below +to paste in screenshots as you test the different configurations: + +```markdown +| Configuration | Android | iOS | macOS | Windows | +| :-------------- | :-----: | :--: | :---: | :-----: | +| JSC | TODO | TODO | TODO | TODO | +| Hermes | TODO | TODO | TODO | TODO | +| Fabric | TODO | TODO | TODO | TODO | +| Fabric + Hermes | TODO | TODO | TODO | TODO | +``` + +You can use the test script to both test and capture screenshots. For instance, +to test 0.71, run: + +```sh +scripts/test-matrix.sh 0.71 +``` + +At the minimum, we should be testing the lowest supported version (0.64 at the +time of writing) in addition to the new version. diff --git a/android/app/build.gradle b/android/app/build.gradle index 718b58515..9229e9575 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -10,17 +10,22 @@ plugins { id("org.jetbrains.kotlin.kapt") version "${kotlinVersion}" } -def enableNewArchitecture = isNewArchitectureEnabled(project) -def reactNativeVersion = getPackageVersionNumber("react-native", rootDir) def reactNativePath = file(findNodeModulesPath("react-native", rootDir)) -if (reactNativeVersion == 0 || enableNewArchitecture) { +if (autodetectReactNativeVersion || enableNewArchitecture) { apply(plugin: "com.facebook.react") - if (enableNewArchitecture) { - react { - codegenDir = file(findNodeModulesPath("react-native-codegen", reactNativePath)) - reactNativeDir = reactNativePath + react { + reactNativeDir = reactNativePath + codegenDir = file(findNodeModulesPath("react-native-codegen", reactNativePath)) + } + + // We don't want the React plugin to bundle. + tasks.whenTaskAdded { task -> + // The task name can be found in `react-native-gradle-plugin`: + // https://github.com/facebook/react-native/blob/0.71-stable/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt#L54 + if (task.name.startsWith("createBundle") && task.name.endsWith("JsAndAssets")) { + task.enabled = false } } } @@ -67,6 +72,7 @@ project.ext.react = [ appName : getAppName(), applicationId : getApplicationId(), architectures : getArchitectures(), + bundleInRelease : false, enableCamera : !getSingleAppMode(), enableFabric : isFabricEnabled(project), enableFlipper : getFlipperVersion(rootDir), @@ -85,6 +91,12 @@ android { ndkVersion project.ext.ndkVersion } + if (usePrefabs) { + buildFeatures { + prefab true + } + } + // TODO: Remove this block when minSdkVersion >= 24. See // https://stackoverflow.com/q/53402639 for details. if (reactNativeVersion > 0 && reactNativeVersion < 6900) { @@ -128,7 +140,7 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - if (project.ext.react.enableNewArchitecture) { + if (enableNewArchitecture) { externalNativeBuild { if (reactNativeVersion > 0 && reactNativeVersion < 7000) { ndkBuild { @@ -171,7 +183,7 @@ android { } } - if (project.ext.react.enableNewArchitecture) { + if (enableNewArchitecture) { externalNativeBuild { if (reactNativeVersion > 0 && reactNativeVersion < 7000) { ndkBuild { @@ -184,50 +196,52 @@ android { } } - def reactAndroidProjectDir = project(":ReactAndroid").projectDir - def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) { - dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck") - from("${reactAndroidProjectDir}/src/main/jni/prebuilt/lib") - into("${buildDir}/react-ndk/exported") - } - def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) { - dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck") - from("${reactAndroidProjectDir}/src/main/jni/prebuilt/lib") - into("${buildDir}/react-ndk/exported") - } - - afterEvaluate { - preDebugBuild.dependsOn(packageReactNdkDebugLibs) - preReleaseBuild.dependsOn(packageReactNdkReleaseLibs) + if (!usePrefabs) { + def reactAndroidProjectDir = project(":ReactAndroid").projectDir + def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) { + dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck") + from("${reactAndroidProjectDir}/src/main/jni/prebuilt/lib") + into("${buildDir}/react-ndk/exported") + } + def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) { + dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck") + from("${reactAndroidProjectDir}/src/main/jni/prebuilt/lib") + into("${buildDir}/react-ndk/exported") + } - if (reactNativeVersion > 0 && reactNativeVersion < 7000) { - // Due to a bug in AGP, we have to explicitly set a dependency - // between configureNdkBuild* tasks and the preBuild tasks. This can - // be removed once this issue is resolved: - // https://issuetracker.google.com/issues/207403732 - configureNdkBuildRelease.dependsOn(preReleaseBuild) - configureNdkBuildDebug.dependsOn(preDebugBuild) - project.ext.react.architectures.each { architecture -> - tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure { - dependsOn("preDebugBuild") - } - tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure { - dependsOn("preReleaseBuild") - } - } - } else if (reactNativeVersion > 0 && reactNativeVersion < 7100) { - // Due to a bug in AGP, we have to explicitly set a dependency - // between configureCMakeDebug* tasks and the preBuild tasks. This can - // be removed once this issue is resolved: - // https://issuetracker.google.com/issues/207403732 - configureCMakeDebug.dependsOn(preDebugBuild) - configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild) - project.ext.react.architectures.each { architecture -> - tasks.findByName("configureCMakeDebug[${architecture}]")?.configure { - dependsOn("preDebugBuild") + afterEvaluate { + preDebugBuild.dependsOn(packageReactNdkDebugLibs) + preReleaseBuild.dependsOn(packageReactNdkReleaseLibs) + + if (reactNativeVersion < 7000) { + // Due to a bug in AGP, we have to explicitly set a dependency + // between configureNdkBuild* tasks and the preBuild tasks. This can + // be removed once this issue is resolved: + // https://issuetracker.google.com/issues/207403732 + configureNdkBuildRelease.dependsOn(preReleaseBuild) + configureNdkBuildDebug.dependsOn(preDebugBuild) + project.ext.react.architectures.each { architecture -> + tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure { + dependsOn("preDebugBuild") + } + tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure { + dependsOn("preReleaseBuild") + } } - tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure { - dependsOn("preReleaseBuild") + } else { + // Due to a bug in AGP, we have to explicitly set a dependency + // between configureCMakeDebug* tasks and the preBuild tasks. This can + // be removed once this issue is resolved: + // https://issuetracker.google.com/issues/207403732 + configureCMakeDebug.dependsOn(preDebugBuild) + configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild) + project.ext.react.architectures.each { architecture -> + tasks.findByName("configureCMakeDebug[${architecture}]")?.configure { + dependsOn("preDebugBuild") + } + tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure { + dependsOn("preReleaseBuild") + } } } } @@ -239,12 +253,7 @@ android { } } - // Nightlies are downloaded from Sonatype and cannot be found under - // `node_modules`. Instead, they can be found in Gradle's cache folder, - // `.gradle/caches/modules-2/files-2.1/com.facebook.react/react-native`. - // For now, we will simply disable this step as we only need to verify - // that things build. - if (reactNativeVersion > 0 && reactNativeVersion < 7100) { + if (!usePrefabs) { def version = getPackageVersion("react-native", rootDir) def allAar = file("${reactNativePath}/android/com/facebook/react/react-native/${version}/react-native-${version}.aar") @@ -320,7 +329,7 @@ android { } // TODO: Remove this block when we drop support for 0.65. - if (project.ext.react.enableNewArchitecture) { + if (enableNewArchitecture) { main.java.srcDirs += "src/turbomodule/java" } else { main.java.srcDirs += "src/no-turbomodule/java" @@ -349,8 +358,8 @@ dependencies { implementation project(":support") if (project.ext.react.enableHermes) { - if (reactNativeVersion == 0) { - implementation("com.facebook.react:hermes-engine") + if (autodetectReactNativeVersion) { + implementation("com.facebook.react:hermes-android") } else if (reactNativeVersion >= 6900) { implementation("com.facebook.react:hermes-engine:+") { exclude(group: "com.facebook.fbjni") @@ -370,10 +379,12 @@ dependencies { } } - if (project.ext.react.enableNewArchitecture) { + if (autodetectReactNativeVersion) { + implementation("com.facebook.react:react-android") + } else if (enableNewArchitecture) { + // This is only valid for 0.68 - 0.70. From 0.71 and on, we should be + // using prefabs. implementation project(":ReactAndroid") - } else if (reactNativeVersion == 0 || reactNativeVersion >= 7100) { - implementation("com.facebook.react:react-native") } else { def version = getPackageVersion("react-native", rootDir) implementation("com.facebook.react:react-native:${version}") @@ -425,25 +436,25 @@ dependencies { } } -if (project.ext.react.enableNewArchitecture) { - configurations.all { - resolutionStrategy.dependencySubstitution { - substitute(module("com.facebook.react:react-native")) - .using(project(":ReactAndroid")) - .because("On New Architecture, we are building React Native from source") - substitute(module("com.facebook.react:hermes-engine")) - .using(project(":ReactAndroid:hermes-engine")) - .because("On New Architecture, we are building Hermes from source") - } - } -} else if (reactNativeVersion > 0 && reactNativeVersion < 7100) { +if (!usePrefabs) { configurations.all { - resolutionStrategy { - // Force version here otherwise Gradle will pick up a newer version: - // https://github.com/facebook/react-native/issues/35210 - def version = getPackageVersion("react-native", rootDir) - force("com.facebook.react:react-native:${version}") - force("com.facebook.react:hermes-engine:${version}") + if (enableNewArchitecture) { + resolutionStrategy.dependencySubstitution { + substitute(module("com.facebook.react:react-native")) + .using(project(":ReactAndroid")) + .because("On New Architecture, we are building React Native from source") + substitute(module("com.facebook.react:hermes-engine")) + .using(project(":ReactAndroid:hermes-engine")) + .because("On New Architecture, we are building Hermes from source") + } + } else { + resolutionStrategy { + // Force version here otherwise Gradle will pick up a newer version: + // https://github.com/facebook/react-native/issues/35210 + def version = getPackageVersion("react-native", rootDir) + force("com.facebook.react:react-native:${version}") + force("com.facebook.react:hermes-engine:${version}") + } } } } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 586a45f48..444ed05c8 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,8 +1,9 @@ - - + package="com.microsoft.reacttestapp" +> @@ -18,13 +19,11 @@ android:supportsRtl="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true" - tools:targetApi="m"> - + tools:targetApi="m" + > - + @@ -33,5 +32,4 @@ - diff --git a/android/app/src/main/jni/CMakeLists.txt b/android/app/src/main/jni/CMakeLists.txt index 5e8a7bc4c..4d2caf9aa 100644 --- a/android/app/src/main/jni/CMakeLists.txt +++ b/android/app/src/main/jni/CMakeLists.txt @@ -12,23 +12,31 @@ set(REACTTESTAPP_SOURCE_FILES AppRegistry.h ) +# Suppress 'Manually-specified variables were not used by the project' warning +set(UNUSED_VARIABLES ${REACT_COMMON_DIR} ${REACT_JNILIBS_DIR}) + if(DEFINED REACT_ANDROID_DIR) + # New architecture include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake) target_sources(${THIS_LIBRARY} PRIVATE ${REACTTESTAPP_SOURCE_FILES}) else() - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(BUILD_VARIANT debug) - else() - set(BUILD_VARIANT release) - endif() - set(JSI_LIBRARY ${REACT_JNILIBS_DIR}/${BUILD_VARIANT}/jni/${ANDROID_ABI}/libjsi.so) - - if(EXISTS ${JSI_LIBRARY}) - add_library(${THIS_LIBRARY} SHARED ${REACTTESTAPP_SOURCE_FILES}) - target_include_directories(${THIS_LIBRARY} PRIVATE ${REACT_COMMON_DIR}/jsi) - target_link_libraries(${THIS_LIBRARY} ${JSI_LIBRARY}) + # On old architecture, use prefabs if they can be found. Otherwise, look for + # the `libjsi.so` we extracted from the `.aar`. + add_library(${THIS_LIBRARY} SHARED ${REACTTESTAPP_SOURCE_FILES}) + find_package(ReactAndroid CONFIG) + if(ReactAndroid_FOUND) + target_link_libraries(${THIS_LIBRARY} ReactAndroid::jsi) else() - add_library(${THIS_LIBRARY} SHARED ${REACTTESTAPP_SOURCE_FILES}) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(BUILD_VARIANT debug) + else() + set(BUILD_VARIANT release) + endif() + set(JSI_LIBRARY ${REACT_JNILIBS_DIR}/${BUILD_VARIANT}/jni/${ANDROID_ABI}/libjsi.so) + if(EXISTS ${JSI_LIBRARY}) + target_include_directories(${THIS_LIBRARY} PRIVATE ${REACT_COMMON_DIR}/jsi) + target_link_libraries(${THIS_LIBRARY} ${JSI_LIBRARY}) + endif() endif() endif() diff --git a/android/app/src/main/jni/ComponentsRegistry.cpp b/android/app/src/main/jni/ComponentsRegistry.cpp index 40ceba656..43e714c02 100644 --- a/android/app/src/main/jni/ComponentsRegistry.cpp +++ b/android/app/src/main/jni/ComponentsRegistry.cpp @@ -1,9 +1,12 @@ #include "ComponentsRegistry.h" -#include #include -#include +#if __has_include() // >= 0.71 +#include +#else // < 0.71 +#include +#endif #include #include diff --git a/android/app/src/main/jni/ComponentsRegistry.h b/android/app/src/main/jni/ComponentsRegistry.h index 6ecf99a5d..a694be1ce 100644 --- a/android/app/src/main/jni/ComponentsRegistry.h +++ b/android/app/src/main/jni/ComponentsRegistry.h @@ -1,10 +1,14 @@ #ifndef REACTTESTAPP_JNI_COMPONENTSREGISTRY_H_ #define REACTTESTAPP_JNI_COMPONENTSREGISTRY_H_ -#include - #include +#if __has_include() // >= 0.71 +#include +#else // < 0.71 +#include +#endif + namespace ReactTestApp { class ComponentsRegistry : public facebook::jni::HybridClass diff --git a/android/dependencies.gradle b/android/dependencies.gradle index 9e8537ea7..748509191 100644 --- a/android/dependencies.gradle +++ b/android/dependencies.gradle @@ -9,7 +9,11 @@ ext { minSdkVersion = 23 targetSdkVersion = 29 - def reactNativeVersion = getPackageVersionNumber("react-native", rootDir) + reactNativeVersion = getPackageVersionNumber("react-native", rootDir) + autodetectReactNativeVersion = reactNativeVersion == 0 || reactNativeVersion >= 7100 + enableNewArchitecture = isNewArchitectureEnabled(project) + usePrefabs = reactNativeVersion == 0 || reactNativeVersion >= 7100 + def useAndroidPlugin_7_2 = reactNativeVersion > 0 && reactNativeVersion < 7100 // We need only set `ndkVersion` when building react-native from source. @@ -27,7 +31,7 @@ ext { androidPluginVersion = useAndroidPlugin_7_2 ? "7.2.2" - : "7.3.0" + : "7.3.1" kotlinVersion = rootProject.hasProperty("KOTLIN_VERSION") ? rootProject.properties["KOTLIN_VERSION"] : "1.7.10" @@ -59,4 +63,15 @@ ext { moshiKotlin : "com.squareup.moshi:moshi-kotlin:1.14.0", moshiKotlinCodegen : "com.squareup.moshi:moshi-kotlin-codegen:1.14.0", ] + + getReactNativeDependencies = { + def dependencies = ["com.android.tools.build:gradle:${androidPluginVersion}"] + + if (autodetectReactNativeVersion || enableNewArchitecture) { + dependencies << "com.facebook.react:react-native-gradle-plugin" + dependencies << "de.undercouch:gradle-download-task:5.3.0" + } + + return dependencies + } } diff --git a/example/android/build.gradle b/example/android/build.gradle index 984a6816f..29ef8ce36 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,7 +1,6 @@ buildscript { def androidTestAppDir = "../node_modules/react-native-test-app/android" apply(from: "${androidTestAppDir}/dependencies.gradle") - apply(from: "${androidTestAppDir}/test-app-util.gradle") repositories { mavenCentral() @@ -9,12 +8,8 @@ buildscript { } dependencies { - classpath("com.android.tools.build:gradle:${androidPluginVersion}") - - def isNightly = getPackageVersionNumber("react-native", rootDir) == 0 - if (isNightly || isNewArchitectureEnabled(project)) { - classpath("com.facebook.react:react-native-gradle-plugin") - classpath("de.undercouch:gradle-download-task:5.3.0") + getReactNativeDependencies().each { dependency -> + classpath(dependency) } } } diff --git a/example/package.json b/example/package.json index a51d4cfb6..fed9b92ae 100644 --- a/example/package.json +++ b/example/package.json @@ -3,22 +3,22 @@ "version": "0.0.1", "private": true, "scripts": { - "android": "react-native run-android", + "android": "react-native run-android --no-packager", "build:android": "mkdirp dist/res && react-native bundle --entry-file index.js --platform android --dev true --bundle-output dist/main.android.jsbundle --assets-dest dist/res", "build:ios": "mkdirp dist && react-native bundle --entry-file index.js --platform ios --dev true --bundle-output dist/main.ios.jsbundle --assets-dest dist", "build:macos": "mkdirp dist && react-native bundle --entry-file index.js --platform macos --dev true --bundle-output dist/main.macos.jsbundle --assets-dest dist", "build:windows": "mkdirp dist && react-native bundle --entry-file index.js --platform windows --dev true --bundle-output dist/main.windows.bundle --assets-dest dist", "ci:windows": "react-native run-windows --logging --no-packager --no-launch --no-deploy --no-telemetry", "clean": "yarn workspace react-native-test-app clean", - "ios": "react-native run-ios", - "macos": "react-native run-macos --scheme Example", + "ios": "react-native run-ios --no-packager", + "macos": "react-native run-macos --no-packager --scheme Example", "set-react-version": "yarn workspace react-native-test-app set-react-version", "start": "react-native start", "windows": "react-native run-windows --no-packager" }, "peerDependencies": { "react": "~17.0.1 || ~18.0.0 || ~18.1.0", - "react-native": "^0.0.0-0 || 0.64 - 0.70 || 1000.0.0", + "react-native": "^0.0.0-0 || 0.64 - 0.71 || 1000.0.0", "react-native-macos": "^0.0.0-0 || 0.64 || 0.66 || 0.68", "react-native-windows": "^0.0.0-0 || 0.64 - 0.70" }, diff --git a/ios/pod_helpers.rb b/ios/pod_helpers.rb index d515cfb36..232c9b516 100644 --- a/ios/pod_helpers.rb +++ b/ios/pod_helpers.rb @@ -39,7 +39,7 @@ def use_new_architecture!(options) Pod::UI.warn( 'As of writing, Fabric is still experimental and subject to change. ' \ 'For more information, please see ' \ - 'https://reactnative.dev/docs/next/new-architecture-app-renderer-ios.' + 'https://reactnative.dev/docs/next/new-architecture-intro.' ) ENV['RCT_NEW_ARCH_ENABLED'] = '1' end @@ -49,7 +49,7 @@ def use_new_architecture!(options) Pod::UI.warn( 'As of writing, TurboModule is still experimental and subject to change. ' \ 'For more information, please see ' \ - 'https://reactnative.dev/docs/next/new-architecture-app-modules-ios.' + 'https://reactnative.dev/docs/next/new-architecture-intro.' ) # At the moment, Fabric and TurboModule code are intertwined. We need to diff --git a/package.json b/package.json index 45206e9d1..07f2e7b86 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "@react-native-community/cli-platform-ios": ">=5.0", "mustache": "^4.0.0", "react": "~17.0.1 || ~18.0.0 || ~18.1.0", - "react-native": "^0.0.0-0 || 0.64 - 0.70 || 1000.0.0", + "react-native": "^0.0.0-0 || 0.64 - 0.71 || 1000.0.0", "react-native-macos": "^0.0.0-0 || 0.64 || 0.66 || 0.68", "react-native-windows": "^0.0.0-0 || 0.64 - 0.70" }, diff --git a/scripts/configure.js b/scripts/configure.js index 14cb3216f..4f87bcf10 100755 --- a/scripts/configure.js +++ b/scripts/configure.js @@ -481,7 +481,6 @@ const getConfig = (() => { "buildscript {", ` def androidTestAppDir = "${testAppRelPath}/android"`, ' apply(from: "${androidTestAppDir}/dependencies.gradle")', - ' apply(from: "${androidTestAppDir}/test-app-util.gradle")', "", " repositories {", " mavenCentral()", @@ -489,11 +488,8 @@ const getConfig = (() => { " }", "", " dependencies {", - ' classpath("com.android.tools.build:gradle:${androidPluginVersion}")', - "", - " if (isNewArchitectureEnabled(project)) {", - ' classpath("com.facebook.react:react-native-gradle-plugin")', - ' classpath("de.undercouch:gradle-download-task:5.3.0")', + " getReactNativeDependencies().each { dependency ->", + " classpath(dependency)", " }", " }", "}", diff --git a/scripts/pack.mjs b/scripts/pack.mjs index f092fbf67..590cce94c 100644 --- a/scripts/pack.mjs +++ b/scripts/pack.mjs @@ -1,6 +1,6 @@ // @ts-check -import * as fs from "fs"; -import * as path from "path"; +import * as fs from "node:fs"; +import * as path from "node:path"; const files = ["example/.gitignore", "example/windows/.gitignore"]; diff --git a/scripts/test-matrix.sh b/scripts/test-matrix.sh index 25a700026..87794c28b 100755 --- a/scripts/test-matrix.sh +++ b/scripts/test-matrix.sh @@ -5,7 +5,7 @@ PACKAGE_MANAGER=yarn VERSION=${1} function pod_install { - rm -fr $1/Podfile.lock $1/Pods + rm -fr $1/Podfile.lock $1/Pods $1/build pod install --project-directory=$1 } @@ -25,7 +25,7 @@ function start_dev_server { } function terminate_dev_server { - [[ -z "$(jobs -p)" ]] || kill $(jobs -p) + [[ -z "$(jobs -p)" ]] || kill $(jobs -p) || true } function wait_for_user { @@ -91,6 +91,8 @@ echo popd 1> /dev/null prepare +# `react-native-safe-area-context` doesn't support latest New Arch changes +sed -i '' 's/"react-native-safe-area-context": ".[.0-9]*",//' package.json echo echo "┌─────────────────────────────┐" @@ -100,8 +102,6 @@ echo sed -i '' 's/#newArchEnabled=true/newArchEnabled=true/' android/gradle.properties pushd android 1> /dev/null -# Due to a bug in Gradle, we need to run this task separately -./gradlew packageReactNdkDebugLibs popd 1> /dev/null npm run android -- --no-packager wait_for_user "Android app with Fabric is ready for testing" diff --git a/test-app.gradle b/test-app.gradle index 8801d3a9d..8a9e87bb3 100644 --- a/test-app.gradle +++ b/test-app.gradle @@ -50,7 +50,12 @@ ext.applyTestAppSettings = { DefaultSettings settings -> settings.includeBuild(reactNativeGradlePlugin) } - if (isNewArchitectureEnabled(settings)) { + // This logic is copied from `android/dependencies.gradle`. Importing it + // currently causes build failure because `project` is not yet defined. + def reactNativeVersion = getPackageVersionNumber("react-native", rootDir) + def usePrefabs = reactNativeVersion == 0 || reactNativeVersion >= 7100 + + if (isNewArchitectureEnabled(settings) && !usePrefabs) { def reactNativeDir = findNodeModulesPath("react-native", settings.rootDir) settings.include(":ReactAndroid") diff --git a/test/android-test-app/test-app-util.test.js b/test/android-test-app/test-app-util.test.js index 2a550aedd..8f0bdc2bb 100644 --- a/test/android-test-app/test-app-util.test.js +++ b/test/android-test-app/test-app-util.test.js @@ -16,8 +16,9 @@ describe("test-app-util", () => { " }", "", " dependencies {", - ' classpath("com.android.tools.build:gradle:${androidPluginVersion}")', - ' classpath("de.undercouch:gradle-download-task:5.2.1")', + " getReactNativeDependencies().each { dependency ->", + " classpath(dependency)", + " }", " }", "}", "", diff --git a/test/configure/__snapshots__/gatherConfig.test.js.snap b/test/configure/__snapshots__/gatherConfig.test.js.snap index d185a91d7..2657b0598 100644 --- a/test/configure/__snapshots__/gatherConfig.test.js.snap +++ b/test/configure/__snapshots__/gatherConfig.test.js.snap @@ -72,7 +72,6 @@ Object { "android/build.gradle": "buildscript { def androidTestAppDir = \\"../../android\\" apply(from: \\"\${androidTestAppDir}/dependencies.gradle\\") - apply(from: \\"\${androidTestAppDir}/test-app-util.gradle\\") repositories { mavenCentral() @@ -80,11 +79,8 @@ Object { } dependencies { - classpath(\\"com.android.tools.build:gradle:\${androidPluginVersion}\\") - - if (isNewArchitectureEnabled(project)) { - classpath(\\"com.facebook.react:react-native-gradle-plugin\\") - classpath(\\"de.undercouch:gradle-download-task:5.3.0\\") + getReactNativeDependencies().each { dependency -> + classpath(dependency) } } } @@ -374,7 +370,6 @@ Object { "android/build.gradle": "buildscript { def androidTestAppDir = \\"../../android\\" apply(from: \\"\${androidTestAppDir}/dependencies.gradle\\") - apply(from: \\"\${androidTestAppDir}/test-app-util.gradle\\") repositories { mavenCentral() @@ -382,11 +377,8 @@ Object { } dependencies { - classpath(\\"com.android.tools.build:gradle:\${androidPluginVersion}\\") - - if (isNewArchitectureEnabled(project)) { - classpath(\\"com.facebook.react:react-native-gradle-plugin\\") - classpath(\\"de.undercouch:gradle-download-task:5.3.0\\") + getReactNativeDependencies().each { dependency -> + classpath(dependency) } } } @@ -525,7 +517,6 @@ Object { "android/build.gradle": "buildscript { def androidTestAppDir = \\"../../android\\" apply(from: \\"\${androidTestAppDir}/dependencies.gradle\\") - apply(from: \\"\${androidTestAppDir}/test-app-util.gradle\\") repositories { mavenCentral() @@ -533,11 +524,8 @@ Object { } dependencies { - classpath(\\"com.android.tools.build:gradle:\${androidPluginVersion}\\") - - if (isNewArchitectureEnabled(project)) { - classpath(\\"com.facebook.react:react-native-gradle-plugin\\") - classpath(\\"de.undercouch:gradle-download-task:5.3.0\\") + getReactNativeDependencies().each { dependency -> + classpath(dependency) } } } diff --git a/yarn.lock b/yarn.lock index ff4caf219..29fc91b9a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5647,7 +5647,7 @@ __metadata: react-native-windows: ^0.68.8 peerDependencies: react: ~17.0.1 || ~18.0.0 || ~18.1.0 - react-native: ^0.0.0-0 || 0.64 - 0.70 || 1000.0.0 + react-native: ^0.0.0-0 || 0.64 - 0.71 || 1000.0.0 react-native-macos: ^0.0.0-0 || 0.64 || 0.66 || 0.68 react-native-windows: ^0.0.0-0 || 0.64 - 0.70 languageName: unknown @@ -10922,7 +10922,7 @@ fsevents@^2.3.2: "@react-native-community/cli-platform-ios": ">=5.0" mustache: ^4.0.0 react: ~17.0.1 || ~18.0.0 || ~18.1.0 - react-native: ^0.0.0-0 || 0.64 - 0.70 || 1000.0.0 + react-native: ^0.0.0-0 || 0.64 - 0.71 || 1000.0.0 react-native-macos: ^0.0.0-0 || 0.64 || 0.66 || 0.68 react-native-windows: ^0.0.0-0 || 0.64 - 0.70 peerDependenciesMeta: