@@ -29,6 +29,43 @@ def getVersionOrDefault(String flagName, String defaultVersion) {
2929 rootProject. hasProperty(flagName) ? rootProject. properties[flagName] : defaultVersion
3030}
3131
32+ def resolveReactNativeDirectory () {
33+ def reactNativeLocation = safeExtGet(" REACT_NATIVE_NODE_MODULES_DIR" , null )
34+ if (reactNativeLocation != null ) {
35+ return file(reactNativeLocation)
36+ }
37+
38+ // monorepo workaround
39+ // react-native can be hoisted or in project's own node_modules
40+ def reactNativeFromProjectNodeModules = file(" ${ rootProject.projectDir} /../node_modules/react-native" )
41+ if (reactNativeFromProjectNodeModules. exists()) {
42+ return reactNativeFromProjectNodeModules
43+ }
44+
45+ def reactNativeFromNodeModulesWithReanimated = file(" ${ projectDir} /../../react-native" )
46+ if (reactNativeFromNodeModulesWithReanimated. exists()) {
47+ return reactNativeFromNodeModulesWithReanimated
48+ }
49+
50+ throw new Exception (
51+ " [react-native-async-storage] Unable to resolve react-native location in " +
52+ " node_modules. You should add project extension property (in app/build.gradle) " +
53+ " `REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
54+ )
55+ }
56+
57+ def getReactNativeMinorVersion () {
58+ def REACT_NATIVE_DIR = resolveReactNativeDirectory()
59+
60+ def reactProperties = new Properties ()
61+ file(" $REACT_NATIVE_DIR /ReactAndroid/gradle.properties" ). withInputStream { reactProperties. load(it) }
62+
63+ def REACT_NATIVE_VERSION = reactProperties. getProperty(" VERSION_NAME" )
64+ def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION . startsWith(" 0.0.0-" ) ? 1000 : REACT_NATIVE_VERSION . split(" \\ ." )[1 ]. toInteger()
65+
66+ return REACT_NATIVE_MINOR_VERSION
67+ }
68+
3269def isNewArchitectureEnabled () {
3370 // To opt-in for the New Architecture, you can either:
3471 // - Set `newArchEnabled` to true inside the `gradle.properties` file
@@ -128,6 +165,10 @@ android {
128165 } else {
129166 srcDirs + = ' src/javaPackage/java'
130167 }
168+
169+ if (! isNewArchitectureEnabled()) {
170+ srcDirs + = ' src/paper/java'
171+ }
131172 }
132173 }
133174}
@@ -174,5 +215,9 @@ dependencies {
174215 }
175216
176217 // noinspection GradleDynamicVersion
177- implementation ' com.facebook.react:react-native:+' // From node_modules
218+ if (isNewArchitectureEnabled() && getReactNativeMinorVersion() < 71 ) {
219+ implementation project(" :ReactAndroid" )
220+ } else {
221+ implementation ' com.facebook.react:react-native:+' // from node_modules
222+ }
178223}
0 commit comments