Skip to content

Commit

Permalink
Set a resolution strategy for com.facebook.react:react-native when on…
Browse files Browse the repository at this point in the history
… New Architecture. (#33134)

Summary:
Pull Request resolved: #33134

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

Reviewed By: ShikaSD

Differential Revision: D34303267

fbshipit-source-id: 492fec59175c5887571e1b09ca8e233584b45dd1
  • Loading branch information
cortinico authored and Andrei Shikov committed Feb 24, 2022
1 parent f5d371a commit bca4cf0
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions template/android/app/build.gradle
Expand Up @@ -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"

Expand All @@ -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) {
Expand Down

0 comments on commit bca4cf0

Please sign in to comment.