@@ -21,12 +21,32 @@ def getExtOrDefault(name, defaultValue) {
2121 return rootProject. ext. has(name) ? rootProject. ext. get(name) : defaultValue
2222}
2323
24+ static def findNodeModules (baseDir ) {
25+ def basePath = baseDir. toPath(). normalize()
26+ // Node's module resolution algorithm searches up to the root directory,
27+ // after which the base path will be null
28+ while (basePath) {
29+ def nodeModulesPath = Paths . get(basePath. toString(), " node_modules" )
30+ def reactNativePath = Paths . get(nodeModulesPath. toString(), " react-native" )
31+ if (nodeModulesPath. toFile(). exists() && reactNativePath. toFile(). exists()) {
32+ return nodeModulesPath. toString()
33+ }
34+ basePath = basePath. getParent()
35+ }
36+ throw new GradleException (" MMKV: Failed to find node_modules/ path!" )
37+ }
38+
2439def found = false
2540def basePath = projectDir. toPath(). normalize()
2641
2742// Find node_modules inside the example project
2843def nodeModulesDir = Paths . get(basePath. getParent(). toString(), " example/node_modules" )
2944def reactNativeDir = Paths . get(nodeModulesDir. toString(), " react-native/android" )
45+ def nodeModules = findNodeModules(projectDir)
46+ def reactProperties = new Properties ()
47+ file(" $nodeModules /react-native/ReactAndroid/gradle.properties" ). withInputStream { reactProperties. load(it) }
48+ def REACT_NATIVE_VERSION = reactProperties. getProperty(" VERSION_NAME" ). split(" \\ ." )[1 ]. toInteger()
49+
3050if (nodeModulesDir. toFile(). exists() && reactNativeDir. toFile(). exists()) {
3151 found = true
3252}
@@ -110,8 +130,17 @@ repositories {
110130dependencies {
111131 // noinspection GradleDynamicVersion
112132 implementation ' com.facebook.react:react-native:+'
113-
114- def rnAAR = fileTree(reactNativePath). matching({ it. include " **/**/*.aar" }). singleFile
133+ def buildType = " debug"
134+ tasks. all({ task ->
135+ if (task. name == " buildCMakeRelease" ) {
136+ buildType = " release"
137+ }
138+ })
139+ def rnAarMatcher = " **/react-native/**/*${ buildType} .aar"
140+ if (REACT_NATIVE_VERSION < 69 ) {
141+ rnAarMatcher = " **/**/*.aar"
142+ }
143+ def rnAAR = fileTree(reactNativePath). matching({ it. include rnAarMatcher }). singleFile
115144 extractJNI(files(rnAAR))
116145}
117146
0 commit comments