Config plugin: pin local JDK 17/21 for Gradle when present

RN's CMake tooling fails on JDK 24+ (restricted native access), so
prebuild injects org.gradle.java.home pointing at ~/.jdks/jdk-21* when
one exists.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-07 16:54:22 -07:00
parent d6de6dedf1
commit 0d63a720f6

View File

@@ -2,7 +2,10 @@
Keystore: $HEALTH_KEYSTORE or ~/.android-keys/health-app-release.jks Keystore: $HEALTH_KEYSTORE or ~/.android-keys/health-app-release.jks
Password: $KEYSTORE_PASSWORD or ~/.android-keys/health-app-release.password Password: $KEYSTORE_PASSWORD or ~/.android-keys/health-app-release.password
Falls back to the debug keystore when neither exists. */ Falls back to the debug keystore when neither exists. */
const { withAppBuildGradle } = require('expo/config-plugins'); const { withAppBuildGradle, withGradleProperties } = require('expo/config-plugins');
const fs = require('fs');
const os = require('os');
const path = require('path');
const SIGNING = ` release { const SIGNING = ` release {
// keystore lives outside the repo; password from env or ~/.android-keys // keystore lives outside the repo; password from env or ~/.android-keys
@@ -18,7 +21,27 @@ const SIGNING = ` release {
} }
}`; }`;
/* RN's CMake tooling breaks on JDK 24+ (native-access restrictions); pin a
local JDK 1721 for Gradle when one is present under ~/.jdks. */
function findJdk21() {
const dir = path.join(os.homedir(), '.jdks');
if (!fs.existsSync(dir)) return null;
const hit = fs
.readdirSync(dir)
.filter((d) => /^jdk-(17|21)/.test(d))
.sort()
.pop();
return hit ? path.join(dir, hit) : null;
}
module.exports = function withReleaseSigning(config) { module.exports = function withReleaseSigning(config) {
config = withGradleProperties(config, (cfg) => {
const jdk = findJdk21();
if (jdk && !cfg.modResults.some((p) => p.key === 'org.gradle.java.home')) {
cfg.modResults.push({ type: 'property', key: 'org.gradle.java.home', value: jdk });
}
return cfg;
});
return withAppBuildGradle(config, (cfg) => { return withAppBuildGradle(config, (cfg) => {
let g = cfg.modResults.contents; let g = cfg.modResults.contents;
if (!g.includes('def ksPath')) { if (!g.includes('def ksPath')) {