Files
t3code/apps/mobile/plugins/withAndroidUnifiedNdk.cjs
T

37 lines
1.4 KiB
JavaScript

const { withProjectBuildGradle } = require("expo/config-plugins");
const BLOCK_START = "// @generated by withAndroidUnifiedNdk";
const BLOCK_END = "// @end withAndroidUnifiedNdk";
const BLOCK = `${BLOCK_START}
// Expo libraries that do not declare an NDK version otherwise fall back to
// Android Gradle Plugin's default. React Native declares a newer revision,
// which makes clean local builds download and retain both multi-gigabyte NDKs.
subprojects { subproject ->
subproject.plugins.withId("com.android.application") {
subproject.android.ndkVersion = rootProject.ext.ndkVersion
}
subproject.plugins.withId("com.android.library") {
subproject.android.ndkVersion = rootProject.ext.ndkVersion
}
}
${BLOCK_END}`;
module.exports = function withAndroidUnifiedNdk(config) {
return withProjectBuildGradle(config, (nextConfig) => {
if (nextConfig.modResults.language !== "groovy") {
throw new Error("withAndroidUnifiedNdk requires a Groovy Android project build file.");
}
const generatedBlock = new RegExp(
`${BLOCK_START.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[\\s\\S]*?${BLOCK_END.replace(
/[.*+?^${}()|[\]\\]/g,
"\\$&",
)}\\n?`,
"g",
);
const contents = nextConfig.modResults.contents.replace(generatedBlock, "").trimEnd();
nextConfig.modResults.contents = `${contents}\n\n${BLOCK}\n`;
return nextConfig;
});
};