Skip to content

Commit 32fd283

Browse files
committed
fix(expo): add Kotlin metadata version skip to app.plugin.js
The previous commit only updated src/plugin/withClerkExpo.ts, but Expo uses app.plugin.js (the hand-written CommonJS file) at runtime. This adds the -Xskip-metadata-version-check flag to the actual plugin file that gets shipped and executed during prebuild.
1 parent b438280 commit 32fd283

1 file changed

Lines changed: 41 additions & 15 deletions

File tree

packages/expo/app.plugin.js

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -483,29 +483,55 @@ const withClerkAndroid = config => {
483483
return withAppBuildGradle(config, modConfig => {
484484
let buildGradle = modConfig.modResults.contents;
485485

486-
// Check if exclusion already exists
487-
if (buildGradle.includes('META-INF/versions/9/OSGI-INF/MANIFEST.MF')) {
488-
console.log('✅ Clerk Android packaging exclusions already configured');
489-
return modConfig;
490-
}
491-
492-
// Find the existing packagingOptions block and add resources.excludes
493-
const packagingOptionsMatch = buildGradle.match(/packagingOptions\s*\{/);
494-
if (packagingOptionsMatch) {
495-
// Add resources block inside packagingOptions
496-
const resourcesExclude = `packagingOptions {
486+
// --- META-INF exclusion ---
487+
if (!buildGradle.includes('META-INF/versions/9/OSGI-INF/MANIFEST.MF')) {
488+
// AGP 8+ uses `packaging` DSL, older versions use `packagingOptions`
489+
const packagingMatch = buildGradle.match(/packaging\s*\{/) || buildGradle.match(/packagingOptions\s*\{/);
490+
if (packagingMatch) {
491+
const blockName = packagingMatch[0].trim().replace(/\s*\{$/, '');
492+
const resourcesExclude = `${blockName} {
497493
// Clerk Android SDK: exclude duplicate META-INF files
498494
resources {
499495
excludes += ['META-INF/versions/9/OSGI-INF/MANIFEST.MF']
500496
}`;
501497

502-
buildGradle = buildGradle.replace(/packagingOptions\s*\{/, resourcesExclude);
503-
modConfig.modResults.contents = buildGradle;
498+
buildGradle = buildGradle.replace(new RegExp(`${blockName}\\s*\\{`), resourcesExclude);
499+
} else {
500+
// No packaging block found; append one at the end of the android block
501+
const androidBlockEnd = buildGradle.lastIndexOf('}');
502+
if (androidBlockEnd !== -1) {
503+
const packagingBlock = `\n packaging {\n resources {\n excludes += ['META-INF/versions/9/OSGI-INF/MANIFEST.MF']\n }\n }\n`;
504+
buildGradle = buildGradle.slice(0, androidBlockEnd) + packagingBlock + buildGradle.slice(androidBlockEnd);
505+
}
506+
}
504507
console.log('✅ Clerk Android packaging exclusions added');
505-
} else {
506-
console.warn('⚠️ Could not find packagingOptions block in build.gradle');
507508
}
508509

510+
// --- Kotlin metadata version check skip ---
511+
// clerk-android is compiled with a newer Kotlin than Expo/RN ships.
512+
// Without this flag, the app module fails to compile with:
513+
// "Module was compiled with an incompatible version of Kotlin"
514+
if (!buildGradle.includes('-Xskip-metadata-version-check')) {
515+
const kotlinOptionsMatch = buildGradle.match(/kotlinOptions\s*\{/);
516+
if (kotlinOptionsMatch) {
517+
buildGradle = buildGradle.replace(
518+
/kotlinOptions\s*\{/,
519+
`kotlinOptions {\n // Clerk: allow reading metadata from newer Kotlin versions\n freeCompilerArgs += ['-Xskip-metadata-version-check']`,
520+
);
521+
} else {
522+
// No kotlinOptions block; add one inside the android block
523+
const androidMatch = buildGradle.match(/android\s*\{/);
524+
if (androidMatch) {
525+
buildGradle = buildGradle.replace(
526+
/android\s*\{/,
527+
`android {\n kotlinOptions {\n // Clerk: allow reading metadata from newer Kotlin versions\n freeCompilerArgs += ['-Xskip-metadata-version-check']\n }`,
528+
);
529+
}
530+
}
531+
console.log('✅ Clerk Android Kotlin metadata version check skip added');
532+
}
533+
534+
modConfig.modResults.contents = buildGradle;
509535
return modConfig;
510536
});
511537
};

0 commit comments

Comments
 (0)