Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ if (autodetectReactNativeVersion || enableNewArchitecture) {
react {
reactNativeDir = reactNativePath
codegenDir = file(
findNodeModulesPath("@react-native/codegen", reactNativePath) // >= 0.72
?: findNodeModulesPath("react-native-codegen", reactNativePath)) // < 0.72
reactNativeVersion >= v(0, 72, 0)
? findNodeModulesPath("@react-native/codegen", reactNativePath)
: findNodeModulesPath("react-native-codegen", reactNativePath)
)
}

// We don't want the React plugin to bundle.
Expand Down
74 changes: 73 additions & 1 deletion scripts/configure-projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
const nodefs = require("node:fs");
const path = require("node:path");
const tty = require("node:tty");
const {
findNearest,
getPackageVersion,
Expand Down Expand Up @@ -42,6 +43,76 @@ const cliPlatformIOSVersion = (() => {
};
})();

/**
* Configures Gradle wrapper as necessary before the Android app is built.
* @param {string} sourceDir
*/
function configureGradleWrapper(sourceDir, fs = nodefs) {
const androidCommands = ["build-android", "run-android"];
if (
process.env["RNTA_CONFIGURE_GRADLE_WRAPPER"] === "0" ||
!process.argv.some((arg) => androidCommands.includes(arg))
) {
return;
}

const gradleWrapperProperties = path.join(
sourceDir,
"gradle",
"wrapper",
"gradle-wrapper.properties"
);
if (!fs.existsSync(gradleWrapperProperties)) {
return;
}

const tag = tty.WriteStream.prototype.hasColors()
? "\u001B[33m\u001B[1mwarn\u001B[22m\u001B[39m"
: "warn";

try {
const props = readTextFile(gradleWrapperProperties);
const re = /gradle-([.0-9]*?)-.*?\.zip/;
const m = props.match(re);
if (!m) {
return;
}

const gradleVersion = (() => {
const gradleVersion = toVersionNumber(m[1]);
const version = toVersionNumber(
getPackageVersion("react-native", sourceDir, fs)
);
if (version === 0 || version >= v(0, 74, 0)) {
if (gradleVersion < v(8, 6, 0)) {
return "8.6";
}
} else if (version >= v(0, 73, 0)) {
if (gradleVersion < v(8, 3, 0)) {
return "8.3";
}
} else if (version >= v(0, 72, 0)) {
if (gradleVersion < v(8, 1, 1)) {
return "8.1.1";
}
} else if (gradleVersion < v(7, 5, 1) || gradleVersion >= v(8, 0, 0)) {
return "7.6.4";
}
return undefined;
})();

if (gradleVersion) {
console.warn(tag, `Setting Gradle version ${gradleVersion}`);
fs.writeFileSync(
gradleWrapperProperties,
props.replace(re, `gradle-${gradleVersion}-bin.zip`)
);
}
} catch (_) {
console.warn(tag, "Failed to determine Gradle version");
}
}

/**
* @param {string} sourceDir
* @returns {string}
Expand All @@ -50,7 +121,7 @@ function androidManifestPath(sourceDir) {
return path.relative(
sourceDir,
path.join(
path.dirname(require.resolve("../package.json")),
path.dirname(__dirname),
"android",
"app",
"src",
Expand Down Expand Up @@ -109,6 +180,7 @@ function configureProjects({ android, ios, windows }, fs = nodefs) {
path.resolve(projectRoot, android.sourceDir)
),
};
configureGradleWrapper(android.sourceDir, fs);
}

if (ios) {
Expand Down
18 changes: 0 additions & 18 deletions scripts/set-react-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -382,22 +382,6 @@ async function getProfile(v, coreOnly) {
}
}

/**
* Sets Gradle Wrapper to specified version.
* @param {string} version
*/
function setGradleVersion(version) {
const gradleWrapperProperties =
"example/android/gradle/wrapper/gradle-wrapper.properties";
fs.writeFileSync(
gradleWrapperProperties,
readTextFile(gradleWrapperProperties).replace(
/gradle-[.0-9]*-bin\.zip/,
`gradle-${version}-bin.zip`
)
);
}

/**
* Sets specified React Native version.
* @param {string} version
Expand Down Expand Up @@ -466,8 +450,6 @@ if (isMain(import.meta.url)) {
: toVersionNumber(version);
if (numVersion >= v(0, 74, 0)) {
disableJetifier();
} else if (numVersion < v(0, 73, 0)) {
setGradleVersion("7.6.3");
}

// `@react-native-webapis/web-storage` is not compatible with codegen 0.71
Expand Down