Skip to content

Commit

Permalink
feat: build and release universal APK
Browse files Browse the repository at this point in the history
  • Loading branch information
acezard authored and Ldoppea committed Apr 30, 2024
1 parent 8b8e338 commit 8642262
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 38 deletions.
54 changes: 47 additions & 7 deletions .github/workflows/build-android-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,57 @@ jobs:
env:
BUILD_TOOLS_VERSION: "33.0.0"

- name: Upload AAB artifact to GitHub
uses: actions/upload-artifact@v3
with:
name: Signed Android AAB ${{ inputs.brand }}
path: |
android/app/build/outputs/bundle/prodRelease/*.aab
- name: Upload App to Google Play
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJsonPlainText: ${{ secrets.ANDROID_SERVICE_ACCOUNT_JSON_TEXT }}
packageName: ${{ inputs.brand != 'cozy' && format('io.cozy.flagship.mobile.{0}', inputs.brand) || 'io.cozy.flagship.mobile' }}
releaseFiles: android/app/build/outputs/bundle/prodRelease/*.aab
track: internal

- name: Download BundleTool
run: |
curl -L https://github.com/google/bundletool/releases/download/1.8.0/bundletool-all-1.8.0.jar -o bundletool.jar
- name: Decode signing key
run: echo "${{ secrets[format('{0}_ANDROID_SIGNING_KEY', inputs.brand)] }}" | base64 --decode > signingKey.jks
env:
BUILD_TOOLS_VERSION: "33.0.0"

- name: Generate APK Set from AAB
run: |
java -jar bundletool.jar build-apks \
--bundle=android/app/build/outputs/bundle/prodRelease/app-prod-release.aab \
--output=app-prod-release.apks \
--mode=universal \
--ks=signingKey.jks \
--ks-pass=pass:${{ secrets[format('{0}_ANDROID_KEY_STORE_PASSWORD', inputs.brand)] }} \
--ks-key-alias=${{ secrets[format('{0}_ANDROID_ALIAS', inputs.brand)] }} \
--key-pass=pass:${{ secrets[format('{0}_ANDROID_KEY_PASSWORD', inputs.brand)] }}
- name: Rename .apks file to .zip
run: mv app-prod-release.apks app-prod-release.zip

- name: Unzip the universal APK from the .zip file
run: unzip app-prod-release.zip -d ./extracted-apks

- name: Rename and move Universal APK
run: |
APK_PATH=$(find ./extracted-apks -name '*.apk')
mv "$APK_PATH" "./extracted-apks/cozy_flagship_universal.apk"
- name: Extract Version Info and Define Artifact Name
run: |
GRADLE_PATH="./android/app/build.gradle"
VERSION_CODE=$(awk '/versionCode/ {print}' $GRADLE_PATH | sed 's/[^0-9*]//g' | bc)
VERSION_NAME=$(grep versionName $GRADLE_PATH | awk -F '"' '{print $2}')
ARTIFACT_NAME="App-$VERSION_NAME-$VERSION_CODE-${{ github.event.inputs.brand }}"
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> $GITHUB_ENV
echo "::set-output name=artifact_name::$ARTIFACT_NAME"
id: artifact_info

- name: Upload APK artifact to GitHub
uses: actions/upload-artifact@v3
with:
name: ${{ steps.artifact_info.outputs.artifact_name }}
path: ./extracted-apks/cozy_flagship_universal.apk
34 changes: 3 additions & 31 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ def jscFlavor = 'org.webkit:android-jsc:+'
*/
def enableHermes = project.ext.react.get("enableHermes", false);

/**
* Architectures to build native code for in debug.
*/
def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures")

android {
ndkVersion rootProject.ext.ndkVersion

Expand All @@ -143,18 +138,16 @@ android {
namespace = "io.cozy.flagship.mobile"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 101260
versionCode 101260 * 10000 // Legacy version number patch, needed for Play Store version increment
versionName "1.1.26"
multiDexEnabled true
resValue "string", "build_config_package", "io.cozy.flagship.mobile"
missingDimensionStrategy "store", "play"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
enable false
universalApk true
}
}
signingConfigs {
Expand All @@ -168,11 +161,6 @@ android {
buildTypes {
debug {
signingConfig signingConfigs.debug
if (nativeArchitectures) {
ndk {
abiFilters nativeArchitectures.split(',')
}
}
}
release {
// Caution! In production, you need to generate your own keystore file.
Expand All @@ -184,22 +172,6 @@ android {
}
}

// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}

}
}

// to load dev/google-services.json and prod/google-services.json
flavorDimensions "version"
productFlavors {
Expand Down

0 comments on commit 8642262

Please sign in to comment.