@@ -9,22 +9,22 @@ ext.autolinkingInfo = { buildDir ->
9
9
return new JsonSlurper (). parseText(autolinking. text)
10
10
}
11
11
12
- ext. checkEnvironment = { rootDir ->
13
- // Keep this in sync with the JS version in `android/gradle-wrapper.js`
14
- //
12
+ ext. checkEnvironment = { rootDir , testAppDir ->
13
+ String [] args = [" node" , " -p" , " JSON.stringify(require('./android/gradle-wrapper.js').GRADLE_VERSIONS)" ]
14
+ def stdout = new StringBuffer ()
15
+ def stderr = new StringBuffer ()
16
+ def node = Runtime . runtime. exec(args, null , file(testAppDir))
17
+ node. waitForProcessOutput(stdout, stderr)
18
+ if (node. exitValue() != 0 ) {
19
+ throw new RuntimeException (" Failed to load 'android/gradle-wrapper.js':\n ${ stderr} " )
20
+ }
21
+
15
22
// We have two implementations because there are currently two ways to build
16
23
// the Android app. If built via `@react-native-community/cli`, the JS
17
24
// script will be run and we can change Gradle version before it is
18
25
// executed. If it's built with Gradle directly, it's already too late and
19
26
// the best we can do is to warn the user.
20
- def gradleVersions = [
21
- [v(0 , 76 , 0 ), [v(8 , 9 , 0 ), " 8.9" ], [Integer . MAX_VALUE , " " ]], // 0.76: [8.9, *)
22
- [v(0 , 75 , 0 ), [v(8 , 8 , 0 ), " 8.8" ], [v(8 , 9 , 0 ), " 8.8" ]], // 0.75: [8.8, 8.9)
23
- [v(0 , 74 , 0 ), [v(8 , 6 , 0 ), " 8.6" ], [v(8 , 9 , 0 ), " 8.8" ]], // 0.74: [8.6, 8.9)
24
- [v(0 , 73 , 0 ), [v(8 , 3 , 0 ), " 8.3" ], [v(8 , 9 , 0 ), " 8.8" ]], // 0.73: [8.3, 8.9)
25
- [v(0 , 72 , 0 ), [v(8 , 1 , 1 ), " 8.1.1" ], [v(8 , 3 , 0 ), " 8.2.1" ]], // 0.72: [8.1.1, 8.3)
26
- [0 , [v(7 , 5 , 1 ), " 7.6.4" ], [v(8 , 0 , 0 ), " 7.6.4" ]], // <0.72: [7.5.1, 8.0.0)
27
- ]
27
+ def gradleVersions = new JsonSlurper (). parseText(stdout. toString())
28
28
29
29
def warnGradle = { gradleVersion , reactNativeVersion ->
30
30
def message = [
@@ -37,8 +37,6 @@ ext.checkEnvironment = { rootDir ->
37
37
logger. error(message, gradleVersion, reactNativeVersion, gradleVersion)
38
38
}
39
39
40
- // Gradle version can be found in the template:
41
- // https://github.com/facebook/react-native/blob/main/packages/react-native/template/android/gradle/wrapper/gradle-wrapper.properties
42
40
def gradleVersion = toVersionNumber(gradle. gradleVersion)
43
41
44
42
def reactNativeVersionString = getPackageVersion(" react-native" , rootDir)
0 commit comments