fix(android): remove broken Gradle signing patch, sign APK with apksigner only

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-28 09:12:07 +08:00
parent 0254ea8a6c
commit 0a807bf18f
4 changed files with 1 additions and 82 deletions

View File

@@ -1,61 +0,0 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const root = path.resolve(__dirname, "../..");
const gradlePath = path.join(
root,
"template/src-tauri/gen/android/app/build.gradle.kts",
);
if (!fs.existsSync(gradlePath)) {
console.log("Android gradle file not found, skipping patch");
process.exit(0);
}
let content = fs.readFileSync(gradlePath, "utf8");
if (content.includes("signingConfigs")) {
console.log("Android gradle already has signingConfigs");
process.exit(0);
}
if (!content.includes("import java.util.Properties")) {
content = content.replace(
/^(import .+\n)+/m,
(block) => `${block}import java.util.Properties\nimport java.io.FileInputStream\n`,
);
}
const signingBlock = `
signingConfigs {
create("release") {
val keystorePropertiesFile = rootProject.file("keystore.properties")
val keystoreProperties = Properties()
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}
keyAlias = keystoreProperties["keyAlias"] as String
keyPassword = keystoreProperties["password"] as String
storeFile = file(keystoreProperties["storeFile"] as String)
storePassword = keystoreProperties["password"] as String
}
}
`;
if (content.includes("buildTypes {")) {
content = content.replace("buildTypes {", `${signingBlock}\n buildTypes {`);
}
if (!content.includes('signingConfig = signingConfigs.getByName("release")')) {
content = content.replace(
/getByName\("release"\)\s*\{/,
`getByName("release") {
signingConfig = signingConfigs.getByName("release")`,
);
}
fs.writeFileSync(gradlePath, content);
console.log("Patched Android gradle signing configuration");

View File

@@ -27,13 +27,4 @@ export WEB2APP_ANDROID_STORE_PASS="${STORE_PASS}"
export WEB2APP_ANDROID_KEY_PASS="${KEY_PASS}"
export WEB2APP_ANDROID_KEY_ALIAS="${KEY_ALIAS}"
ANDROID_DIR="template/src-tauri/gen/android"
if [ -d "${ANDROID_DIR}" ]; then
cat > "${ANDROID_DIR}/keystore.properties" <<EOF
keyAlias=${KEY_ALIAS}
password=${KEY_PASS}
storeFile=${KEYSTORE_PATH}
EOF
fi
echo "Android signing material ready at ${KEYSTORE_PATH}"

View File

@@ -117,17 +117,6 @@ jobs:
env:
NDK_HOME: ${{ env.ANDROID_HOME }}/ndk/${{ env.NDK_VERSION }}
- name: Setup Android signing
run: bash .github/scripts/setup-android-signing.sh
env:
ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
- name: Patch Android Gradle signing
run: node .github/scripts/patch-android-gradle.mjs
- name: Build Android APK
working-directory: template
run: npm run tauri android build -- --apk

View File

@@ -104,7 +104,7 @@ powershell Compress-Archive -Path * -DestinationPath ../sample-site.zip -Force
### Android 签名与安装
- CI 构建完成后会`apksigner` 对 APK **签名**,可直接侧载安装
- CI 构建未签名 APK`apksigner` **签名**,可直接侧载安装(不修改 Gradle 配置,避免构建失败)
- 未配置 Secrets 时workflow 会生成临时 CI 证书(密码 `web2app-ci`,仅适合 demo
- 生产环境建议在仓库 Settings → Secrets 配置: