fix(android): remove broken Gradle signing patch, sign APK with apksigner only
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
61
.github/scripts/patch-android-gradle.mjs
vendored
61
.github/scripts/patch-android-gradle.mjs
vendored
@@ -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");
|
|
||||||
9
.github/scripts/setup-android-signing.sh
vendored
9
.github/scripts/setup-android-signing.sh
vendored
@@ -27,13 +27,4 @@ export WEB2APP_ANDROID_STORE_PASS="${STORE_PASS}"
|
|||||||
export WEB2APP_ANDROID_KEY_PASS="${KEY_PASS}"
|
export WEB2APP_ANDROID_KEY_PASS="${KEY_PASS}"
|
||||||
export WEB2APP_ANDROID_KEY_ALIAS="${KEY_ALIAS}"
|
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}"
|
echo "Android signing material ready at ${KEYSTORE_PATH}"
|
||||||
|
|||||||
11
.github/workflows/build-app.yml
vendored
11
.github/workflows/build-app.yml
vendored
@@ -117,17 +117,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
NDK_HOME: ${{ env.ANDROID_HOME }}/ndk/${{ env.NDK_VERSION }}
|
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
|
- name: Build Android APK
|
||||||
working-directory: template
|
working-directory: template
|
||||||
run: npm run tauri android build -- --apk
|
run: npm run tauri android build -- --apk
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ powershell Compress-Archive -Path * -DestinationPath ../sample-site.zip -Force
|
|||||||
|
|
||||||
### Android 签名与安装
|
### Android 签名与安装
|
||||||
|
|
||||||
- CI 构建完成后会用 `apksigner` 对 APK **签名**,可直接侧载安装
|
- CI 先构建未签名 APK,再用 `apksigner` **签名**,可直接侧载安装(不修改 Gradle 配置,避免构建失败)
|
||||||
- 未配置 Secrets 时,workflow 会生成临时 CI 证书(密码 `web2app-ci`,仅适合 demo)
|
- 未配置 Secrets 时,workflow 会生成临时 CI 证书(密码 `web2app-ci`,仅适合 demo)
|
||||||
- 生产环境建议在仓库 Settings → Secrets 配置:
|
- 生产环境建议在仓库 Settings → Secrets 配置:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user