Chore: Fixed Android release script

This commit is contained in:
Laurent Cozic
2026-02-04 14:43:56 +00:00
parent a9049111e4
commit b2c9dd40dc
3 changed files with 58 additions and 3 deletions
+48 -2
View File
@@ -3,13 +3,59 @@
const fs = require('fs');
function deleteMatchingDirs(rootDir, predicate) {
let entries;
try {
entries = fs.readdirSync(rootDir, { withFileTypes: true });
} catch {
return;
}
for (const entry of entries) {
if (!entry.isDirectory()) continue;
const fullPath = `${rootDir}/${entry.name}`;
if (predicate(fullPath)) {
fs.rmSync(fullPath, { recursive: true, force: true });
} else {
deleteMatchingDirs(fullPath, predicate);
}
}
}
function main() {
const mobileDir = `${__dirname}/..`;
// Standard Android / iOS build artefacts
fs.rmSync(`${mobileDir}/android/.gradle`, { recursive: true, force: true });
fs.rmSync(`${mobileDir}/android/app/build`, { recursive: true, force: true });
fs.rmSync(`${mobileDir}/android/build`, { recursive: true, force: true });
fs.rmSync(`${mobileDir}/android/app/build`, { recursive: true, force: true });
fs.rmSync(`${mobileDir}/android/.cxx`, { recursive: true, force: true });
fs.rmSync(`${mobileDir}/android/app/.cxx`, { recursive: true, force: true });
// React Native generated files that frequently break CMake/autolinking
fs.rmSync(`${mobileDir}/android/app/build/generated/autolinking`, { recursive: true, force: true });
fs.rmSync(`${mobileDir}/android/app/build/generated/source/codegen`, { recursive: true, force: true });
// iOS
fs.rmSync(`${mobileDir}/ios/Pods`, { recursive: true, force: true });
console.info('To clean the Android build, in some rare cases you might also need to clear the cache in ~/.android and ~/.gradle');
// Delete all native module Android build artefacts
// Equivalent to:
// find . -path "*/node_modules/*/android/build" -type d -exec rm -rf {} + || true
// find . -path "*/node_modules/*/android/.cxx" -type d -exec rm -rf {} + || true
deleteMatchingDirs(mobileDir, p =>
p.includes('/node_modules/') && (
p.endsWith('/android/build') ||
p.endsWith('/android/.cxx')
),
);
console.info(
'Mobile app build artefacts cleaned.\n' +
'If you still see build issues, you may also need to clear ~/.gradle/caches and ~/.android.',
);
}
try {
+1
View File
@@ -247,3 +247,4 @@ youtu
nocookie
fgag
mrjo
codegen
+9 -1
View File
@@ -148,7 +148,15 @@ async function createRelease(projectName: string, releaseConfig: ReleaseConfig,
} else {
process.chdir(`${rnDir}/android`);
apkBuildCmd = './gradlew';
apkCleanBuild = `./gradlew clean -PbuildDir=${buildDirName}`;
// Note: We intentionally do NOT run `./gradlew clean`. On React Native 0.8x+, `clean` is
// broken because it triggers CMake regeneration via externalNativeBuild, which re-evaluates
// autolinking and codegen and fails if generated JNI/CMake directories are missing (and for
// some reason they usually are). Manually deleting build artefacts is safer and
// deterministic.
// apkCleanBuild = `./gradlew clean -PbuildDir=${buildDirName}`;
apkCleanBuild = 'yarn clean';
restoreDir = rootDir;
}