fix(push): add allprojects.repositories for runtime dependency resolution
Ensure Honor and Huawei Maven repos are added to both buildscript.repositories and allprojects.repositories in root build.gradle. Runtime dependencies like com.hihonor.mcs:push and com.huawei.hms:push are resolved via allprojects, not buildscript. Also consolidate all build.gradle modifications to use withDangerousMod directly, avoiding silent hook drops in Expo SDK 56+.
This commit is contained in:
@@ -179,6 +179,43 @@ const withHuaweiPush = (config, options = {}) => {
|
||||
config = withDangerousMod(config, [
|
||||
'android',
|
||||
async (config) => {
|
||||
// Ensure Huawei Maven repo is in allprojects.repositories (not just buildscript).
|
||||
// Runtime dependencies like com.huawei.hms:push must be resolved via allprojects,
|
||||
// and the earlier withProjectBuildGradle hook may be silently dropped in Expo SDK 56+.
|
||||
const rootBuildGradlePath = path.join(config.modRequest.platformProjectRoot, 'build.gradle');
|
||||
if (fs.existsSync(rootBuildGradlePath)) {
|
||||
let rootGradle = fs.readFileSync(rootBuildGradlePath, 'utf-8');
|
||||
const huaweiRepoLine = ` maven { url 'https://developer.huawei.com/repo/' }`;
|
||||
let rootChanged = false;
|
||||
|
||||
// buildscript.repositories
|
||||
if (!rootGradle.match(/buildscript\s*\{[\s\S]*?developer\.huawei\.com\/repo/)) {
|
||||
const bsPattern = /(buildscript\s*\{[\s\S]*?repositories\s*\{)/;
|
||||
if (bsPattern.test(rootGradle)) {
|
||||
rootGradle = rootGradle.replace(bsPattern, `$1\n${huaweiRepoLine}`);
|
||||
rootChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
// allprojects.repositories (runtime deps resolution)
|
||||
if (!rootGradle.match(/allprojects\s*\{[\s\S]*?developer\.huawei\.com\/repo/)) {
|
||||
const allProjectsPattern = /(allprojects\s*\{[\s\S]*?repositories\s*\{)/;
|
||||
if (allProjectsPattern.test(rootGradle)) {
|
||||
rootGradle = rootGradle.replace(allProjectsPattern, `$1\n${huaweiRepoLine}`);
|
||||
rootChanged = true;
|
||||
} else {
|
||||
const allProjectsBlock = `\nallprojects {\n repositories {${huaweiRepoLine}\n }\n}\n`;
|
||||
rootGradle = rootGradle + allProjectsBlock;
|
||||
rootChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (rootChanged) {
|
||||
fs.writeFileSync(rootBuildGradlePath, rootGradle);
|
||||
console.log('[withHuaweiPush] ensured Huawei Maven repo in buildscript + allprojects');
|
||||
}
|
||||
}
|
||||
|
||||
const appDir = path.join(config.modRequest.platformProjectRoot, 'app');
|
||||
const srcFile = path.join(config.modRequest.projectRoot, 'plugins', 'agconnect-services.json');
|
||||
const destFile = path.join(appDir, 'agconnect-services.json');
|
||||
|
||||
Reference in New Issue
Block a user