Skip to content

Commit

Permalink
Merge pull request #1 from spectre-project/dev
Browse files Browse the repository at this point in the history
Include APK signing and code cleanup
  • Loading branch information
x100111010 authored Aug 6, 2024
2 parents f4a2665 + 5f7da40 commit 5e3da9d
Show file tree
Hide file tree
Showing 84 changed files with 15,814 additions and 20,100 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/build_android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
build:
runs-on: windows-latest
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -22,16 +22,25 @@ jobs:
java-version: '17'

- name: Run code generation
run: dart run build_runner build --delete-conflicting-outputs
run: dart run build_runner build

- name: Install dependencies
run: flutter pub get

- name: Build Android apk
run: flutter build apk --split-per-abi
- name: Decode keystore, build Android APK and sign
env:
SIGNING_KEYSTORE: "keystore.jks"
SIGNING_KEYSTORE_PASSWORD: ${{ secrets.SIGNING_KEYSTORE_PASSWORD }}
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
run: |
echo "${{ secrets.SIGNING_KEYSTORE }}" | base64 --decode > android/app/keystore.jks
flutter build apk --release
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: android-build
path: build/app/outputs/flutter-apk/*.apk
path: build/app/outputs/flutter-apk/app-release.apk
if-no-files-found: ignore
retention-days: 7 # specifies how long to keep the artifact
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Tests
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Dart
uses: dart-lang/setup-dart@v1

- name: Install Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
- run: flutter --version

- name: Get Flutter Dependencies
run: flutter pub get

- name: Generate Dart code
run: dart run build_runner build

- name: Check Dart Code Formatting
run: dart format --output=none --set-exit-if-changed .

- name: Analyze Dart Code
run: dart analyze

- name: Run Flutter Tests
run: flutter test
29 changes: 20 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,27 @@ jobs:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'

- name: Build Android with ABI splits

- name: Get dependencies
run: flutter pub get

- name: Run code generation
run: dart run build_runner build

- name: Decode keystore & build Android
env:
SIGNING_KEYSTORE: "keystore.jks"
SIGNING_KEYSTORE_PASSWORD: ${{ secrets.SIGNING_KEYSTORE_PASSWORD }}
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
run: |
flutter pub get
dart run build_runner build --delete-conflicting-outputs
flutter build apk --split-per-abi
echo "${{ secrets.SIGNING_KEYSTORE }}" | base64 --decode > android/app/keystore.jks
# build Android APK with ABI splits
flutter build apk --release --split-per-abi
# build universal Android APK
flutter build apk --release
# 'bin' directory to store and upload the renamed APKs
mkdir bin
Expand All @@ -40,10 +55,6 @@ jobs:
mv build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk bin/spectrum-${{ github.event.release.tag_name }}-app-armeabi-v7a-release.apk
mv build/app/outputs/flutter-apk/app-x86_64-release.apk bin/spectrum-${{ github.event.release.tag_name }}-app-x86_64-release.apk
- name: Build Universal Android APK
run: |
flutter build apk
# Rename Universal APK with Release Tag
mv build/app/outputs/flutter-apk/app-release.apk bin/spectrum-${{ github.event.release.tag_name }}-app-universal.apk
Expand Down
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## What is Spectrum?

[![Build Status](https://github.com/spectre-project/spectre-mobile/actions/workflows/ci.yml/badge.svg)](https://github.com/spectre-project/spectre-mobile/actions/workflows/ci.yml)
[![Latest Release](https://img.shields.io/github/v/release/spectre-project/spectre-mobile?display_name=tag&style=flat-square)](https://github.com/spectre-project/spectre-mobile/releases)
[![LICENSE](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/spectre-project/spectre-mobile/blob/main/LICENSE)
[![Downloads Latest](https://img.shields.io/github/downloads/spectre-project/spectre-mobile/latest/total?style=flat-square)](https://github.com/spectre-project/spectre-mobile/releases/latest)
Expand Down Expand Up @@ -32,6 +33,12 @@ flutter build apk
```
This command compiles the app into a single universal APK compatible with all device architectures.

If you want to create a signed APK, you need to include the `--release` argument:
```bash
flutter build apk --release
```
Adding the `--release` argument will build the app in release mode, which triggers the signing process using the release signing configuration defined in your `build.gradle` file. This produces a signed APK ready for distribution.

For generating APKs for specific device architectures, use:
```bash
flutter build apk --split-per-abi
Expand Down Expand Up @@ -77,6 +84,84 @@ If you need any help, feel free to [file a feature request or an issue](https://
| ![](assets/images/b1.png) | ![](assets/images/b2.png) | ![](assets/images/b3.png) |
| ![](assets/images/c1.png) | ![](assets/images/c2.png) | ![](assets/images/c3.png) |

## Signing an APK in GitHub Workflows

In the repository, the APK signing process during GitHub Actions is implemented through the following steps:

1. **Creating a Keystore**:
A keystore file is generated which will be used to sign the APK. This is done using the `keytool` command:

```bash
keytool -genkey -v -keystore release.keystore -alias your_key_alias -keyalg RSA -keysize 2048 -validity 10000
```

This command creates a keystore file named `release.keystore`. The alias for the key, `your_key_alias`, should be replaced with a desired name.

2. **Encoding the Keystore**:
To securely store the keystore in GitHub Secrets, it is encoded in base64 using the following command:

```bash
base64 release.keystore > release.keystore.base64
```

The contents of the resulting `release.keystore.base64` file are then copied and stored as a GitHub Secret.

3. **Setting GitHub Secrets**:
In the GitHub repository settings, specific secrets are configured under `Settings > Secrets and variables > Actions > New repository secret`. The required secrets include:

- `SIGNING_KEYSTORE`: Contains the base64 encoded contents of the keystore.
- `SIGNING_KEYSTORE_PASSWORD`: Stores the password for the keystore.
- `SIGNING_KEY_ALIAS`: Represents the alias name for the key.
- `SIGNING_KEY_PASSWORD`: Holds the password for the key alias.

4. **Configuring Build Types in `build.gradle`**:
The `android/app/build.gradle` file is configured to handle the signing process based on the availability of environment variables. If `SIGNING_KEYSTORE` is defined, it triggers the signing of the APK with the provided credentials. If not, the build defaults to a debug configuration.

```groovy
buildTypes {
release {
signingConfigs {
if (System.getenv("SIGNING_KEYSTORE") != null) {
create("release") {
storeFile = file(System.getenv("SIGNING_KEYSTORE"))
storePassword = System.getenv("SIGNING_KEYSTORE_PASSWORD")
keyAlias = System.getenv("SIGNING_KEY_ALIAS")
keyPassword = System.getenv("SIGNING_KEY_PASSWORD")
}
signingConfig = signingConfigs.release
} else {
signingConfig = signingConfigs.debug
applicationIdSuffix ".debug"
}
}
minifyEnabled true
}
debug {
shrinkResources false
minifyEnabled false
applicationIdSuffix ".debug"
signingConfig signingConfigs.debug
}
}
```

5. **GitHub Workflow Step**:
The GitHub Actions workflow includes a step to decode the keystore and build the signed APK:

```yaml
- name: Decode keystore, build Android APK and sign
env:
SIGNING_KEYSTORE: "keystore.jks"
SIGNING_KEYSTORE_PASSWORD: ${{ secrets.SIGNING_KEYSTORE_PASSWORD }}
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
run: |
echo "${{ secrets.SIGNING_KEYSTORE }}" | base64 --decode > android/app/keystore.jks
flutter build apk --release
```
In this step, the keystore is decoded from its base64 encoded form and saved to `android/app/keystore.jks`, followed by building the APK in release mode with the appropriate signing configuration.

## License

All code is copyrighted by the Kaspium Wallet authors and the Spectre Network
Expand Down
36 changes: 20 additions & 16 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,29 @@ android {
versionName flutterVersionName
}

signingConfigs {
release {
if (keystorePropertiesFile.exists()) {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
}

buildTypes {
release {
if (keystorePropertiesFile.exists()) {
signingConfig signingConfigs.release
minifyEnabled true
} else {
signingConfig signingConfigs.debug
signingConfigs {
if (System.getenv("SIGNING_KEYSTORE") != null) {
create("release") {
storeFile = file(System.getenv("SIGNING_KEYSTORE"))
storePassword = System.getenv("SIGNING_KEYSTORE_PASSWORD")
keyAlias = System.getenv("SIGNING_KEY_ALIAS")
keyPassword = System.getenv("SIGNING_KEY_PASSWORD")
}
signingConfig = signingConfigs.release
} else {
signingConfig = signingConfigs.debug
applicationIdSuffix ".debug"
}
}
minifyEnabled true
}
debug {
shrinkResources false
minifyEnabled false
applicationIdSuffix ".debug"
signingConfig signingConfigs.debug
}
}
}
Expand Down
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}

Expand Down
4 changes: 3 additions & 1 deletion l10n.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
output-localization-file: app_localizations.dart
output-class: AppLocalizations
untranslated-messages-file: missing_translations.txt
Loading

0 comments on commit 5e3da9d

Please sign in to comment.