From 5638f52cfa4a49e638dddcefa584c078c864def3 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 17 Feb 2022 07:03:50 -0800 Subject: [PATCH] Set a resolution strategy for com.facebook.react:react-native when on New Architecture. Summary: When a user is enabling New Architecture, we should make sure they don't accidentally mix imports of React Native from source vs prebuilts. With this resolution strategy, we'll make sure all the import of `com.facebook.react:react-native:+` will be resolved to the correct dependency. Changelog: [Android] [Fixed] - Set a resolution strategy for com.facebook.react:react-native when on New Architecture Differential Revision: D34303267 fbshipit-source-id: d59de872ec7700a5d060fe28dd5c5d1dbb8f453e --- template/android/app/build.gradle | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/template/android/app/build.gradle b/template/android/app/build.gradle index 506dca121113..bb24740f14a0 100644 --- a/template/android/app/build.gradle +++ b/template/android/app/build.gradle @@ -238,14 +238,8 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) - // If new architecture is enabled, we let you build RN from source - // Otherwise we fallback to a prebuilt .aar bundled in the NPM package. - if (isNewArchitectureEnabled()) { - implementation project(":ReactAndroid") - } else { - //noinspection GradleDynamicVersion - implementation "com.facebook.react:react-native:+" // From node_modules - } + //noinspection GradleDynamicVersion + implementation "com.facebook.react:react-native:+" // From node_modules implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" @@ -271,6 +265,18 @@ dependencies { } } +if (isNewArchitectureEnabled()) { + // If new architecture is enabled, we let you build RN from source + // Otherwise we fallback to a prebuilt .aar bundled in the NPM package. + // This will be applied to all the imported transtitive dependency. + configurations.all { + resolutionStrategy.dependencySubstitution { + substitute(module("com.facebook.react:react-native")) + .using(project(":ReactAndroid")).because("On New Architecture we're building React Native from source") + } + } +} + // Run this once to be able to run the application with BUCK // puts all compile dependencies into folder libs for BUCK to use task copyDownloadableDepsToLibs(type: Copy) {