Skip to content

Commit 9b8a2cf

Browse files
giolaqclaude
andcommitted
fix(android): resolve JVM target mismatch for JDK 22 users
Add Expo config plugin to set consistent Java 17 / Kotlin JVM targets in the react-settings-plugin, preventing the "Inconsistent JVM-target compatibility" error when building with JDK 22. Also pin kotlinVersion and SDK versions in expo-build-properties for reproducibility. Closes #56 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8eab9b3 commit 9b8a2cf

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

apps/expo-multi-tv/app.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"expo": {
33
"plugins": [
4+
"./plugins/withKotlinJvmTarget",
45
"@bam.tech/react-native-keyevent-expo-config-plugin",
56
[
67
"@react-native-tvos/config-tv",
@@ -24,7 +25,11 @@
2425
"newArchEnabled": false
2526
},
2627
"android": {
27-
"newArchEnabled": false
28+
"newArchEnabled": false,
29+
"kotlinVersion": "1.9.24",
30+
"compileSdkVersion": 34,
31+
"targetSdkVersion": 34,
32+
"minSdkVersion": 23
2833
}
2934
}
3035
],
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const { withDangerousMod } = require("expo/config-plugins");
2+
const fs = require("fs");
3+
const path = require("path");
4+
5+
function withKotlinJvmTarget(config) {
6+
return withDangerousMod(config, [
7+
"android",
8+
async (config) => {
9+
const buildGradlePath = path.join(
10+
config.modRequest.platformProjectRoot,
11+
"react-settings-plugin",
12+
"build.gradle.kts"
13+
);
14+
15+
if (fs.existsSync(buildGradlePath)) {
16+
let contents = fs.readFileSync(buildGradlePath, "utf-8");
17+
18+
if (!contents.includes("sourceCompatibility")) {
19+
const jvmConfig = `
20+
java {
21+
sourceCompatibility = JavaVersion.VERSION_17
22+
targetCompatibility = JavaVersion.VERSION_17
23+
}
24+
25+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
26+
kotlinOptions {
27+
jvmTarget = "17"
28+
}
29+
}
30+
`;
31+
contents = contents.replace(
32+
/repositories\s*\{\s*mavenCentral\(\)\s*\}/,
33+
(match) => match + "\n" + jvmConfig
34+
);
35+
fs.writeFileSync(buildGradlePath, contents);
36+
}
37+
}
38+
39+
return config;
40+
},
41+
]);
42+
}
43+
44+
module.exports = withKotlinJvmTarget;

0 commit comments

Comments
 (0)