20260628215623
This commit is contained in:
1 parent
51622a4b1a
commit
e687846eb4
68 files changed
+2234
-1591
No files matched your search
@@ -1,39 +1,42 @@
|
||||
// plugins/withAndroidSignature.js
|
||||
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const { withAppBuildGradle } = require('expo/config-plugins')
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const { withAppBuildGradle } = require("expo/config-plugins");
|
||||
|
||||
module.exports = function withAndroidSignature(config) {
|
||||
return withAppBuildGradle(config, (config) => {
|
||||
if (config.modResults.language === 'groovy') {
|
||||
config.modResults.contents = setAndroidSignature(config.modResults.contents)
|
||||
if (config.modResults.language === "groovy") {
|
||||
config.modResults.contents = setAndroidSignature(config.modResults.contents);
|
||||
} else {
|
||||
throw new Error("如果不是 groovy,则无法在 app/build.gradle 中设置 signingConfigs");
|
||||
}
|
||||
else {
|
||||
throw new Error('如果不是 groovy,则无法在 app/build.gradle 中设置 signingConfigs')
|
||||
}
|
||||
return config
|
||||
})
|
||||
}
|
||||
return config;
|
||||
});
|
||||
};
|
||||
|
||||
function setAndroidSignature(appBuildGradle) {
|
||||
if (!fs.existsSync(path.resolve(__dirname, '../credentials/credentials.json'))) {
|
||||
console.warn('警告:没有设置正式版本的 Android Keystore 文件,因为 credentials.json 不存在。')
|
||||
return appBuildGradle
|
||||
if (!fs.existsSync(path.resolve(__dirname, "../credentials/credentials.json"))) {
|
||||
console.warn("警告:没有设置正式版本的 Android Keystore 文件,因为 credentials.json 不存在。");
|
||||
return appBuildGradle;
|
||||
}
|
||||
const info = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../credentials/credentials.json'), { encoding: 'utf8' }))
|
||||
const info = JSON.parse(
|
||||
fs.readFileSync(path.resolve(__dirname, "../credentials/credentials.json"), {
|
||||
encoding: "utf8",
|
||||
}),
|
||||
);
|
||||
|
||||
// 使用正则表达式插入签名信息
|
||||
let output = appBuildGradle.replace(
|
||||
/(signingConfigs\s*\{)/,
|
||||
`$1
|
||||
release {
|
||||
storeFile file(${JSON.stringify(path.resolve(__dirname, '../credentials/oneao-android.keystore'))})
|
||||
storeFile file(${JSON.stringify(path.resolve(__dirname, "../credentials/oneao-android.keystore"))})
|
||||
storePassword ${JSON.stringify(info.android.keystore.keystorePassword)}
|
||||
keyAlias ${JSON.stringify(info.android.keystore.keyAlias)}
|
||||
keyPassword ${JSON.stringify(info.android.keystore.keyPassword)}
|
||||
}`,
|
||||
)
|
||||
);
|
||||
|
||||
// 使用正则表达式替换 signingConfig
|
||||
output = output.replace(
|
||||
@@ -41,7 +44,7 @@ function setAndroidSignature(appBuildGradle) {
|
||||
`$1
|
||||
signingConfig signingConfigs.release
|
||||
`,
|
||||
)
|
||||
);
|
||||
|
||||
return output
|
||||
return output;
|
||||
}
|
||||
Reference in new issue
Block a user