Skip to content

Commit

Permalink
fix(android): bump Gradle wrapper version for 0.76 (#2216)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 authored Sep 10, 2024
1 parent 2a3154c commit e5cc42e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
12 changes: 10 additions & 2 deletions android/gradle-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,26 @@ const {
v,
} = require("../scripts/helpers");

// Maximum value of a 32-bit integer (to ensure compatibility across language
// boundaries)
const INT_MAX = 2 ** 31 - 1;

/**
* Keep this in sync with the Groovy version in `android/test-app-util.gradle`!
* This table is also used by `android/test-app-util.gradle`!
*
* We have two implementations because there are currently two ways to build the
* Android app. If built via `@react-native-community/cli`, this script will be
* run and we can change Gradle version before it is executed. If it's built
* with Gradle directly, it's already too late and the best we can do is to warn
* the user.
*
* Gradle version can be found in the template:
* https://github.com/react-native-community/template/blob/main/template/android/gradle/wrapper/gradle-wrapper.properties
*
* @type {[number, [number, string], [number, string]][]}
*/
const GRADLE_VERSIONS = [
[v(0, 76, 0), [v(8, 9, 0), "8.9"], [Number.MAX_SAFE_INTEGER, ""]], // 0.76: [8.9, *)
[v(0, 76, 0), [v(8, 10, 1), "8.10.1"], [INT_MAX, ""]], // 0.76: [8.10.1, *)
[v(0, 75, 0), [v(8, 8, 0), "8.8"], [v(8, 9, 0), "8.8"]], // 0.75: [8.8, 8.9)
[v(0, 74, 0), [v(8, 6, 0), "8.6"], [v(8, 9, 0), "8.8"]], // 0.74: [8.6, 8.9)
[v(0, 73, 0), [v(8, 3, 0), "8.3"], [v(8, 9, 0), "8.8"]], // 0.73: [8.3, 8.9)
Expand Down Expand Up @@ -99,4 +106,5 @@ function configureGradleWrapper(sourceDir, fs = nodefs) {
}
}

exports.GRADLE_VERSIONS = GRADLE_VERSIONS;
exports.configureGradleWrapper = configureGradleWrapper;
24 changes: 11 additions & 13 deletions android/test-app-util.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ ext.autolinkingInfo = { buildDir ->
return new JsonSlurper().parseText(autolinking.text)
}

ext.checkEnvironment = { rootDir ->
// Keep this in sync with the JS version in `android/gradle-wrapper.js`
//
ext.checkEnvironment = { rootDir, testAppDir ->
String[] args = ["node", "-p", "JSON.stringify(require('./android/gradle-wrapper.js').GRADLE_VERSIONS)"]
def stdout = new StringBuffer()
def stderr = new StringBuffer()
def node = Runtime.runtime.exec(args, null, file(testAppDir))
node.waitForProcessOutput(stdout, stderr)
if (node.exitValue() != 0) {
throw new RuntimeException("Failed to load 'android/gradle-wrapper.js':\n${stderr}")
}

// We have two implementations because there are currently two ways to build
// the Android app. If built via `@react-native-community/cli`, the JS
// script will be run and we can change Gradle version before it is
// executed. If it's built with Gradle directly, it's already too late and
// the best we can do is to warn the user.
def gradleVersions = [
[v(0, 76, 0), [v(8, 9, 0), "8.9"], [Integer.MAX_VALUE, ""]], // 0.76: [8.9, *)
[v(0, 75, 0), [v(8, 8, 0), "8.8"], [v(8, 9, 0), "8.8"]], // 0.75: [8.8, 8.9)
[v(0, 74, 0), [v(8, 6, 0), "8.6"], [v(8, 9, 0), "8.8"]], // 0.74: [8.6, 8.9)
[v(0, 73, 0), [v(8, 3, 0), "8.3"], [v(8, 9, 0), "8.8"]], // 0.73: [8.3, 8.9)
[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)
[0, [v(7, 5, 1), "7.6.4"], [v(8, 0, 0), "7.6.4"]], // <0.72: [7.5.1, 8.0.0)
]
def gradleVersions = new JsonSlurper().parseText(stdout.toString())

def warnGradle = { gradleVersion, reactNativeVersion ->
def message = [
Expand All @@ -37,8 +37,6 @@ ext.checkEnvironment = { rootDir ->
logger.error(message, gradleVersion, reactNativeVersion, gradleVersion)
}

// Gradle version can be found in the template:
// https://github.com/facebook/react-native/blob/main/packages/react-native/template/android/gradle/wrapper/gradle-wrapper.properties
def gradleVersion = toVersionNumber(gradle.gradleVersion)

def reactNativeVersionString = getPackageVersion("react-native", rootDir)
Expand Down
8 changes: 4 additions & 4 deletions test-app.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ private static void applyConfigPlugins(String testAppDir, File rootDir) {

private static Object autolinkModules(File projectRoot, File output, String testAppDir) {
String[] autolink = ["node", "${testAppDir}/android/autolink.mjs", projectRoot.toString(), output.toString()]
def stdout = new StringBuffer()
def stderr = new StringBuffer()
def proc = Runtime.runtime.exec(autolink, null, projectRoot)
proc.waitForProcessOutput(null, stdout)
proc.waitForProcessOutput(null, stderr)
if (proc.exitValue() != 0) {
throw new RuntimeException("Failed to autolink:\n${stdout}")
throw new RuntimeException("Failed to autolink:\n${stderr}")
}

return new JsonSlurper().parseText(output.text)
Expand Down Expand Up @@ -58,7 +58,7 @@ private static boolean isMediaFile(File file) {
def testAppDir = buildscript.sourceFile.getParent()
apply(from: "${testAppDir}/android/test-app-util.gradle")

checkEnvironment(rootDir)
checkEnvironment(rootDir, testAppDir)

def reactNativeDir = file(findNodeModulesPath("react-native", rootDir))
def cliAndroidDir = findNodeModulesPath("@react-native-community/cli-platform-android", reactNativeDir)
Expand Down
4 changes: 2 additions & 2 deletions test/android/gradle-wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe("configureGradleWrapper()", () => {
process.argv.push("run-android");

const cases = [
["8.8", "0.76.0", "gradle-8.9-bin.zip"],
["8.9", "0.76.0", "gradle-8.10.1-bin.zip"],
["8.9", "0.75.0", "gradle-8.8-bin.zip"],
["8.7", "0.75.0", "gradle-8.8-bin.zip"],
["8.9", "0.74.0", "gradle-8.8-bin.zip"],
Expand Down Expand Up @@ -190,7 +190,7 @@ describe("configureGradleWrapper()", () => {
process.argv.push("run-android");

const cases = [
["8.9", "0.76.0"],
["8.10.1", "0.76.0"],
["8.8", "0.75.0"],
["8.8", "0.74.0"],
["8.8", "0.73.0"],
Expand Down

0 comments on commit e5cc42e

Please sign in to comment.