Build APKs in CI
triallax opened this issue · 6 comments
Building debug APKs in the CI would be nice. It would save time (no need to manually build APKs anymore) and make testing easier.
We can look at NewPipe for inspiration. One thing that I really like about how it's done in NewPipe is that each branch has a unique bundle ID, meaning that you can have APKs for multiple PRs installed at once (beside the release app too), without any conflicts. The code for that sits here.
I'm trying to build clima, but looks like the build process tries to sign by default, even though there's no signing key:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:packageRelease'.
> A failure occurred while executing com.android.build.gradle.tasks.PackageAndroidArtifact$IncrementalSplitterRunnable
> SigningConfig "release" is missing required property "storeFile".
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 5m 15s
Running Gradle task 'assembleRelease'... 315.9s
Gradle task assembleRelease failed with exit code 1
I'm not sure if just generating a one-shot key is valid (I guess...?). Any ideas how to do that in a quick way?
I'm using Sourcehut Builds (mostly because it's what I have access to, and want some build pipelines to experiment making some changes of my own).
This is my test manifest:
# Copied and adapted from https://git.sr.ht/~emersion/goguma/tree/master/item/.builds/android.yml
# See https://git.sr.ht/~emersion/goguma/tree/master/item/LICENSE
image: archlinux
packages:
- android-platform
- android-sdk
- android-sdk-build-tools
- android-sdk-cmdline-tools-latest
- android-sdk-platform-tools
- flutter
- jdk11-openjdk
sources:
- https://github.com/Lacerte/clima.git
# secrets:
# - XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX # keystore.jks
# - XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX # keystore.properties
artifacts:
- clima/packages/clima_ui/build/app/outputs/flutter-apk/app-release.apk
tasks:
- setup-tools: |
sudo chown -R $USER /opt/flutter /opt/android-sdk
source /etc/profile
flutter precache --linux
yes | flutter doctor --android-licenses >/dev/null
flutter doctor -v
# - configure: |
# cd clima/packages/clima_ui/
# ln -s ~/keystore.properties android/keystore.properties
# ln -s ~/keystore.jks android/keystore.jks
- build: |
cd clima/packages/clima_ui/
flutter build apk --build-number="$(git rev-list --first-parent --count HEAD)"
- analyze: |
cd clima
flutter analyze --no-fatal-infos
Thanks, that worked!
I did get a build working after all. This is the manifest for builds.sr.ht, and it should be pretty simple to port it to any CI provider:
# Copied and adapted from https://git.sr.ht/~emersion/goguma/tree/master/item/.builds/android.yml
# See https://git.sr.ht/~emersion/goguma/tree/master/item/LICENSE
image: archlinux
packages:
- android-platform
- android-sdk
- android-sdk-build-tools
- android-sdk-cmdline-tools-latest
- android-sdk-platform-tools
- flutter
- jdk11-openjdk
- curl
- unzip
sources:
- https://github.com/Lacerte/clima.git
artifacts:
- clima/packages/clima_ui/build/app/outputs/flutter-apk/app-release.apk
tasks:
- setup-tools: |
sudo chown -R $USER /opt/flutter /opt/android-sdk
source /etc/profile
flutter precache --linux
yes | flutter doctor --android-licenses >/dev/null
flutter doctor -v
- patch: |
cd clima
curl -LO https://github.com/Lacerte/clima/files/8626116/patch.zip
unzip patch.zip
git apply 0001-Use-debug-signing-keys.patch
- build: |
cd clima/packages/clima_ui/
flutter build apk --build-number="$(git rev-list --first-parent --count HEAD)"
However, the built artefact fails to install -- I suspect it's due to the missing signature. I want to script the generation of a new key during build, but simply haven't had time to look into it.
However, the built artefact fails to install
Do you mean that it fails to install if you already have Clima installed from F-Droid? If so, that's the expected behavior, since the APK signatures are different. If you can't install the APK even without having Clima already installed though, then there's a problem indeed.
I suspect it's due to the missing signature.
That's not quite right; the APK does have a signature.
Oh, right. Uninstalling the existing version and installing the one from the link above worked.
I guess I now have a pipeline to try and make some tweaks.