Skip to content

Commit 5c85ed2

Browse files
committed
workflow patch #2
1 parent 2a3cd08 commit 5c85ed2

2 files changed

Lines changed: 29 additions & 50 deletions

File tree

.github/workflows/android-build.yml

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -64,77 +64,40 @@ jobs:
6464
- name: Validate Gradle wrapper
6565
uses: gradle/wrapper-validation-action@v2
6666

67-
# Now builds for both releases and test branches will be signed
68-
- name: Build benchmark release APK
67+
# Decode the Base64 keystore into a file for Gradle to use
68+
- name: Setup keystore file
6969
run: |
70-
echo "Building benchmark release APK..."
70+
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 --decode > keystore.jks
71+
echo "Keystore file created at keystore.jks"
72+
73+
- name: Build signed benchmark release APK
74+
run: |
75+
echo "Building signed benchmark release APK with Gradle..."
76+
# This task will now automatically apply the signingConfig defined in build.gradle.kts
7177
./gradlew :app:assembleBenchmarkRelease
72-
env:
78+
env: # Pass secrets as environment variables to Gradle
79+
KEYSTORE_FILE_PATH: keystore.jks # Path to the decoded keystore file
7380
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
7481
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
7582
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
76-
KEYSTORE_FILE: ${{ secrets.KEYSTORE_FILE }}
77-
78-
- name: Setup keystore for signing
79-
run: |
80-
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 --decode > keystore.jks
81-
echo "Keystore file created"
82-
83-
- name: Sign APK
84-
run: |
85-
# Find the APK file
86-
APK_FILE=$(find app/build/outputs/apk/benchmarkRelease -name "*.apk" | head -1)
87-
if [ -z "$APK_FILE" ]; then
88-
echo "Error: No APK file found"
89-
exit 1
90-
fi
91-
92-
echo "Found APK: $APK_FILE"
93-
94-
# Find the correct build-tools version
95-
BUILD_TOOLS_VERSION=$(ls $ANDROID_HOME/build-tools/ | sort -V | tail -1)
96-
APKSIGNER_PATH="$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION/apksigner"
97-
98-
echo "Using build-tools version: $BUILD_TOOLS_VERSION"
99-
echo "APK signer path: $APKSIGNER_PATH"
100-
101-
# Check if apksigner exists
102-
if [ ! -f "$APKSIGNER_PATH" ]; then
103-
echo "Error: apksigner not found at $APKSIGNER_PATH"
104-
echo "Available build-tools versions:"
105-
ls -la $ANDROID_HOME/build-tools/
106-
exit 1
107-
fi
108-
109-
# Sign the APK
110-
"$APKSIGNER_PATH" sign --ks keystore.jks --ks-type PKCS12 --ks-key-alias "${{ secrets.KEY_ALIAS }}" --ks-pass pass:"${{ secrets.KEYSTORE_PASSWORD }}" --key-pass pass:"${{ secrets.KEY_PASSWORD }}" --out "${APK_FILE%.apk}-signed.apk" "$APK_FILE"
111-
112-
# Verify the signature
113-
"$APKSIGNER_PATH" verify "${APK_FILE%.apk}-signed.apk"
114-
115-
echo "APK signed and verified successfully"
116-
117-
# Replace unsigned APK with signed one
118-
mv "${APK_FILE%.apk}-signed.apk" "$APK_FILE"
11983

12084
- name: Rename APK with version
85+
id: rename-apk
12186
run: |
12287
APK_FILE=$(find app/build/outputs/apk/benchmarkRelease -name "*.apk" | head -1)
12388
if [ -z "$APK_FILE" ]; then
124-
echo "Error: No APK file found"
89+
echo "Error: No APK file found after Gradle build."
12590
exit 1
12691
fi
12792
12893
APK_DIR=$(dirname "$APK_FILE")
129-
APK_NAME=$(basename "$APK_FILE" .apk)
13094
VERSION="${{ steps.get-version.outputs.version }}"
13195
13296
NEW_NAME="ClipSync-Android-${VERSION}-signed.apk"
13397
13498
mv "$APK_FILE" "$APK_DIR/$NEW_NAME"
13599
echo "APK renamed to: $NEW_NAME"
136100
echo "apk-path=$APK_DIR/$NEW_NAME" >> $GITHUB_OUTPUT
137-
id: rename-apk
138101
139102
- name: Get APK info
140103
run: |

app/build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ android {
2525
unitTests.isIncludeAndroidResources = true
2626
}
2727

28+
signingConfigs {
29+
create("productionRelease") {
30+
storeFile = file(System.getenv("KEYSTORE_FILE_PATH") ?: "keystore.jks")
31+
storePassword = System.getenv("KEYSTORE_PASSWORD")
32+
keyAlias = System.getenv("KEY_ALIAS")
33+
keyPassword = System.getenv("KEY_PASSWORD")
34+
}
35+
}
36+
2837
buildTypes {
2938
release {
3039
val boolean = false
@@ -34,6 +43,13 @@ android {
3443
getDefaultProguardFile("proguard-android-optimize.txt"),
3544
"proguard-rules.pro"
3645
)
46+
47+
signingConfig = signingConfigs.getByName("productionRelease")
48+
}
49+
50+
create("benchmarkRelease") {
51+
initWith(buildTypes.getByName("release"))
52+
signingConfig = signingConfigs.getByName("productionRelease")
3753
}
3854
}
3955
compileOptions {

0 commit comments

Comments
 (0)