build(deps): add Jiguang SDK repositories and CMake job limit plugin
Some checks failed
Frontend CI / ota (android) (push) Failing after 54s
Frontend CI / ota (ios) (push) Failing after 52s
Frontend CI / build-and-push-web (push) Has been cancelled
Frontend CI / build-android-apk (push) Has been cancelled

Add Jiguang Maven repository (developer.jiguang.cn) to dependency resolution management for JPush SDK integration. Integrate new Expo config plugins for CMake job limiting and JCore patching.

- Add jiguang maven repo to dependencyResolutionManagement and all buildscript repositories
- Create withCmakeJobLimit plugin to set cmake job limits in gradle properties
- Create withJcorePatch plugin for JCore SDK configuration
- Increase CMAKE_BUILD_PARALLEL_LEVEL from 4 to 8 for faster native builds
- Add gradle HTTP timeout settings (30s connection/socket timeout)
- Remove npmmirror registry from npmrc and CI workflows (use default npm registry)
- Downgrade upload-artifact action from v4 to v3 for compatibility
- Remove docker layer caching for frontend-web build
This commit is contained in:
lafay
2026-06-15 22:58:48 +08:00
parent f3d54a3f4c
commit 1012337e57
6 changed files with 157 additions and 10 deletions

View File

@@ -0,0 +1,60 @@
const { withDangerousMod } = require('@expo/config-plugins');
const fs = require('fs');
const path = require('path');
const MAX_JOBS = '8';
// React Native's hermes-engine build hardcodes
// Runtime.getRuntime().availableProcessors()
// for cmake --build -j, ignoring all env vars.
// On high-core CI runners this exhausts memory.
// This plugin patches hermes-engine/build.gradle.kts
// during prebuild to cap parallel jobs.
const withCmakeJobLimit = (config) =>
withDangerousMod(config, [
'android',
async (config) => {
const root = config.modRequest.projectRoot;
// 1. Patch hermes-engine: availableProcessors() -> "8"
const hermesPath = path.join(
root,
'node_modules',
'react-native',
'ReactAndroid',
'hermes-engine',
'build.gradle.kts',
);
if (fs.existsSync(hermesPath)) {
let content = fs.readFileSync(hermesPath, 'utf-8');
content = content.replace(
/Runtime\.getRuntime\(\)\.availableProcessors\(\)\.toString\(\)/,
`"${MAX_JOBS}"`,
);
fs.writeFileSync(hermesPath, content);
}
// 2. Patch app/build.gradle: add cmake -j argument to externalNativeBuild
const appGradlePath = path.join(
config.modRequest.platformProjectRoot,
'app',
'build.gradle',
);
if (fs.existsSync(appGradlePath)) {
let content = fs.readFileSync(appGradlePath, 'utf-8');
// Insert externalNativeBuild cmake arguments block inside the android { } block
// We add it right after "ndkVersion rootProject.ext.ndkVersion"
if (!content.includes('CMAKE_BUILD_PARALLEL_LEVEL')) {
content = content.replace(
/(\s*ndkVersion rootProject\.ext\.ndkVersion)/,
`$1\n externalNativeBuild {\n cmake {\n arguments "-j${MAX_JOBS}"\n }\n }`,
);
}
fs.writeFileSync(appGradlePath, content);
}
return config;
},
]);
module.exports = withCmakeJobLimit;

View File

@@ -22,6 +22,35 @@ const withHuaweiPush = (config, options = {}) => {
// is applied via buildscript classpath in build.gradle with the apms-plugin excluded.
if (!contents.includes('developer.huawei.com/repo')) {
const repoLine = ` maven { url 'https://developer.huawei.com/repo/' }`;
const jigLine = ` maven { url 'https://developer.jiguang.cn/maven' }`;
const hasPluginManagement = contents.includes('pluginManagement');
const hasRepositoriesInPM = /pluginManagement\s*\{[\s\S]*?repositories\s*\{/.test(contents);
if (hasRepositoriesInPM) {
config.modResults.contents = contents.replace(
/(pluginManagement\s*\{[\s\S]*?repositories\s*\{)/,
`$1\n ${repoLine}\n ${jigLine}`
);
} else if (hasPluginManagement) {
config.modResults.contents = contents.replace(
/(pluginManagement\s*\{)/,
`$1\n repositories {\n gradlePluginPortal()\n google()\n mavenCentral()\n ${repoLine}\n ${jigLine}\n }`
);
} else {
config.modResults.contents =
`pluginManagement {\n repositories {\n ${repoLine}\n ${jigLine}\n }\n}\n\n` +
config.modResults.contents;
}
}
// Add Jiguang Maven repo for dependency resolution (jcore/jpush SDK)
if (!contents.includes('developer.jiguang.cn/maven')) {
const depMgmtPattern = /dependencyResolutionManagement\s*\{[\s\S]*?repositories\s*\{/;
if (depMgmtPattern.test(config.modResults.contents)) {
config.modResults.contents = config.modResults.contents.replace(
depMgmtPattern,
` if (!contents.includes('developer.huawei.com/repo')) {
const repoLine = ` maven { url 'https://developer.huawei.com/repo/' }`;
const hasPluginManagement = contents.includes('pluginManagement');
const hasRepositoriesInPM = /pluginManagement\s*\{[\s\S]*?repositories\s*\{/.test(contents);
@@ -51,6 +80,9 @@ const withHuaweiPush = (config, options = {}) => {
`$&\n maven { url 'https://developer.huawei.com/repo/' }`
);
}
}\n maven { url 'https://developer.jiguang.cn/maven' }`
);
}
}
return config;

43
plugins/withJcorePatch.js Normal file
View File

@@ -0,0 +1,43 @@
const { withDangerousMod } = require('@expo/config-plugins');
const fs = require('fs');
const path = require('path');
// Patch jcore-react-native's build.gradle to remove the legacy flatDir block
// and jniLibs.srcDirs. The 'libs' directory no longer exists in the package —
// dependencies are fetched from Maven — but the stale config causes Gradle
// warnings and can stall dependency resolution on newer Gradle versions.
const withJcorePatch = (config) =>
withDangerousMod(config, [
'android',
async (config) => {
const root = config.modRequest.projectRoot;
const gradlePath = path.join(
root,
'node_modules',
'jcore-react-native',
'android',
'build.gradle',
);
if (!fs.existsSync(gradlePath)) return config;
let content = fs.readFileSync(gradlePath, 'utf-8');
// Remove flatDir block
content = content.replace(
/repositories\s*\{\s*flatDir\s*\{\s*dirs\s+['"]libs['"]\s*\}\s*\}/,
'',
);
// Remove jniLibs.srcDirs line and its enclosing sourceSets block if it becomes empty
content = content.replace(
/\s*sourceSets\s*\{\s*main\s*\{\s*jniLibs\.srcDirs\s*=\s*\['libs'\]\s*\}\s*\}/,
'',
);
fs.writeFileSync(gradlePath, content);
return config;
},
]);
module.exports = withJcorePatch;