@@ -29,6 +29,43 @@ def getVersionOrDefault(String flagName, String defaultVersion) {
29
29
rootProject. hasProperty(flagName) ? rootProject. properties[flagName] : defaultVersion
30
30
}
31
31
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
+
32
69
def isNewArchitectureEnabled () {
33
70
// To opt-in for the New Architecture, you can either:
34
71
// - Set `newArchEnabled` to true inside the `gradle.properties` file
@@ -128,6 +165,10 @@ android {
128
165
} else {
129
166
srcDirs + = ' src/javaPackage/java'
130
167
}
168
+
169
+ if (! isNewArchitectureEnabled()) {
170
+ srcDirs + = ' src/paper/java'
171
+ }
131
172
}
132
173
}
133
174
}
@@ -174,5 +215,9 @@ dependencies {
174
215
}
175
216
176
217
// 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
+ }
178
223
}
0 commit comments