From 5af61ff97bd2386fee318c5b899232257d977b24 Mon Sep 17 00:00:00 2001 From: Super12138 <70494801+Super12138@users.noreply.github.com> Date: Wed, 10 Apr 2024 20:02:52 +0800 Subject: [PATCH] Use a new way to sign apk --- .github/workflows/android_ci.yml | 22 +++++++++++----------- app/build.gradle.kts | 13 +++++++++++++ gradle.properties | 3 ++- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/workflows/android_ci.yml b/.github/workflows/android_ci.yml index 592c62e..220accc 100644 --- a/.github/workflows/android_ci.yml +++ b/.github/workflows/android_ci.yml @@ -25,20 +25,20 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew + - name: Write sign info + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && github.repository == 'Super12138/ToDo' + run: | + if [ ! -z "${{ secrets.SIGNING_KEY }}" ]; then + echo releaseStorePassword='${{ secrets.KEY_STORE_PASSWORD }}' >> gradle.properties + echo releaseKeyAlias='${{ secrets.ALIAS }}' >> gradle.properties + echo releaseKeyPassword='${{ secrets.KEY_PASSWORD }}' >> gradle.properties + echo releaseStoreFile='${{ github.workspace }}/key.jks' >> gradle.properties + echo ${{ secrets.SIGNING_KEY }} | base64 --decode > ${{ github.workspace }}/key.jks + fi + - name: Build with Gradle run: ./gradlew assembleRelease - - uses: ilharp/sign-android-release@nightly - name: Sign APK - id: sign_app - with: - releaseDir: app/build/outputs/apk/release - signingKey: ${{ secrets.ANDROID_SIGNING_KEY }} - keyAlias: ${{ secrets.ANDROID_KEY_ALIAS }} - keyStorePassword: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }} - keyPassword: ${{ secrets.ANDROID_KEY_PASSWORD }} - buildToolsVersion: 33.0.0 - - name: Upload APK uses: actions/upload-artifact@v4.3.1 with: diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c3f4171..ee07ed4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -15,6 +15,18 @@ android { namespace = "cn.super12138.todo" compileSdk = 34 + // 获取 Release 签名 + val releaseSigning = if (project.hasProperty("releaseStoreFile")) { + signingConfigs.create("release") { + storeFile = File(project.properties["releaseStoreFile"] as String) + storePassword = project.properties["releaseStorePassword"] as String + keyAlias = project.properties["releaseKeyAlias"] as String + keyPassword = project.properties["releaseKeyPassword"] as String + } + } else { + signingConfigs.getByName("debug") + } + defaultConfig { applicationId = "cn.super12138.todo" minSdk = 24 @@ -29,6 +41,7 @@ android { buildTypes { release { + signingConfig = releaseSigning isMinifyEnabled = true isShrinkResources = true proguardFiles( diff --git a/gradle.properties b/gradle.properties index 3c5031e..8ea0209 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,4 +20,5 @@ kotlin.code.style=official # Enables namespacing of each library's R class so that its R class includes only the # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library -android.nonTransitiveRClass=true \ No newline at end of file +android.nonTransitiveRClass=true +