From 78689dfecc9f63e2d250b217918c4bd0f96adf5c Mon Sep 17 00:00:00 2001 From: Shubham Singh Date: Tue, 1 Oct 2024 15:44:22 +0530 Subject: [PATCH] Frontend: Add APK generation workflow --- ...rontend_web.yaml => publish_frontend.yaml} | 47 ++++++++++++++++--- frontend/android/app/build.gradle | 34 ++++++++++++-- frontend/android/app/proguard-rules.pro | 0 .../android/app/src/debug/AndroidManifest.xml | 2 +- .../android/app/src/main/AndroidManifest.xml | 34 ++++++++------ .../downtheaisle}/MainActivity.kt | 2 +- .../app/src/profile/AndroidManifest.xml | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +- frontend/lib/main.dart | 6 ++- 9 files changed, 101 insertions(+), 30 deletions(-) rename .github/workflows/{publish_frontend_web.yaml => publish_frontend.yaml} (57%) create mode 100644 frontend/android/app/proguard-rules.pro rename frontend/android/app/src/main/kotlin/{com/example/frontend => app/downtheaisle}/MainActivity.kt (76%) diff --git a/.github/workflows/publish_frontend_web.yaml b/.github/workflows/publish_frontend.yaml similarity index 57% rename from .github/workflows/publish_frontend_web.yaml rename to .github/workflows/publish_frontend.yaml index c45292d..7838389 100644 --- a/.github/workflows/publish_frontend_web.yaml +++ b/.github/workflows/publish_frontend.yaml @@ -1,11 +1,11 @@ -name: Deploy Flutter Web Frontend +name: Deploy Flutter Frontend Apps on: push: - branches: - - main + tags: + - 'v*' paths: - - '.github/workflows/publish_frontend_web.yaml' + - '.github/workflows/publish_frontend.yaml' - 'core/**' - 'frontend/**' workflow_dispatch: @@ -20,10 +20,16 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' - name: Cache Flutter packages - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: | ~/.pub-cache @@ -60,6 +66,27 @@ jobs: working-directory: ./frontend run: flutter pub run build_runner build --delete-conflicting-outputs + - name: Decode Keystore + uses: timheuer/base64-to-file@v1.2 + with: + fileName: 'keystore.jks' + fileDir: './frontend/android/app/' + encodedString: ${{ secrets.KEYSTORE_BASE64 }} + + - name: Build APK + working-directory: ./frontend + env: + STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} + KEY_ALIAS: ${{ secrets.KEY_ALIAS }} + KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} + run: flutter build apk --release + + - name: Upload APK + uses: actions/upload-artifact@v3 + with: + name: release-apk + path: frontend/build/app/outputs/flutter-apk/app-release.apk + - name: Build web app working-directory: ./frontend run: flutter build web --dart-define APP_ENV=production --base-href /down_the_aisle/ @@ -69,3 +96,11 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./frontend/build/web + + - name: Create Release + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + files: frontend/build/app/outputs/flutter-apk/app-release.apk + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/frontend/android/app/build.gradle b/frontend/android/app/build.gradle index feed5cc..c2462ba 100644 --- a/frontend/android/app/build.gradle +++ b/frontend/android/app/build.gradle @@ -5,8 +5,27 @@ plugins { id "dev.flutter.flutter-gradle-plugin" } +def getKeyProperty(String propertyName, String defaultValue = null) { + def envValue = System.getenv(propertyName) + if (envValue != null && !envValue.isEmpty()) { + return envValue + } + + def keyPropertiesFile = rootProject.file("key.properties") + if (keyPropertiesFile.exists()) { + Properties keyProperties = new Properties() + keyProperties.load(new FileInputStream(keyPropertiesFile)) + def propValue = keyProperties[propertyName] + if (propValue != null && !propValue.isEmpty()) { + return propValue + } + } + + return defaultValue +} + android { - namespace = "com.example.frontend" + namespace = "app.downtheaisle" compileSdk = flutter.compileSdkVersion ndkVersion = flutter.ndkVersion @@ -29,11 +48,18 @@ android { versionName = flutter.versionName } + signingConfigs { + release { + keyAlias = getKeyProperty("KEY_ALIAS") + keyPassword = getKeyProperty("KEY_PASSWORD") + storeFile = file(getKeyProperty("STORE_FILE", "keystore.jks")) + storePassword = getKeyProperty("STORE_PASSWORD") + } + } + buildTypes { release { - // TODO: Add your own signing config for the release build. - // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig = signingConfigs.debug + signingConfig = signingConfigs.release } } } diff --git a/frontend/android/app/proguard-rules.pro b/frontend/android/app/proguard-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/frontend/android/app/src/debug/AndroidManifest.xml b/frontend/android/app/src/debug/AndroidManifest.xml index 399f698..4d95910 100644 --- a/frontend/android/app/src/debug/AndroidManifest.xml +++ b/frontend/android/app/src/debug/AndroidManifest.xml @@ -3,5 +3,5 @@ the Flutter tool needs it to communicate with the running application to allow setting breakpoints, to provide hot reload, etc. --> - + diff --git a/frontend/android/app/src/main/AndroidManifest.xml b/frontend/android/app/src/main/AndroidManifest.xml index ed471b2..b7c8e34 100644 --- a/frontend/android/app/src/main/AndroidManifest.xml +++ b/frontend/android/app/src/main/AndroidManifest.xml @@ -1,29 +1,33 @@ - + + + + + android:icon="@mipmap/ic_launcher" + android:label="Down The Aisle"> + android:windowSoftInputMode="adjustResize" + tools:ignore="DiscouragedApi,LockedOrientationActivity"> + android:name="io.flutter.embedding.android.NormalTheme" + android:resource="@style/NormalTheme" /> - - + + - - + + diff --git a/frontend/android/app/src/main/kotlin/com/example/frontend/MainActivity.kt b/frontend/android/app/src/main/kotlin/app/downtheaisle/MainActivity.kt similarity index 76% rename from frontend/android/app/src/main/kotlin/com/example/frontend/MainActivity.kt rename to frontend/android/app/src/main/kotlin/app/downtheaisle/MainActivity.kt index 7ab7680..7e17478 100644 --- a/frontend/android/app/src/main/kotlin/com/example/frontend/MainActivity.kt +++ b/frontend/android/app/src/main/kotlin/app/downtheaisle/MainActivity.kt @@ -1,4 +1,4 @@ -package com.example.frontend +package app.downtheaisle import io.flutter.embedding.android.FlutterActivity diff --git a/frontend/android/app/src/profile/AndroidManifest.xml b/frontend/android/app/src/profile/AndroidManifest.xml index 399f698..4d95910 100644 --- a/frontend/android/app/src/profile/AndroidManifest.xml +++ b/frontend/android/app/src/profile/AndroidManifest.xml @@ -3,5 +3,5 @@ the Flutter tool needs it to communicate with the running application to allow setting breakpoints, to provide hot reload, etc. --> - + diff --git a/frontend/android/gradle/wrapper/gradle-wrapper.properties b/frontend/android/gradle/wrapper/gradle-wrapper.properties index 7bb2df6..9355b41 100644 --- a/frontend/android/gradle/wrapper/gradle-wrapper.properties +++ b/frontend/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip diff --git a/frontend/lib/main.dart b/frontend/lib/main.dart index 7d64812..4aba95f 100644 --- a/frontend/lib/main.dart +++ b/frontend/lib/main.dart @@ -40,7 +40,11 @@ Future main() async { } void _setupDesktopWindow() { - if (!kIsWeb) { + final isLinux = defaultTargetPlatform == TargetPlatform.linux; + final isMacOS = defaultTargetPlatform == TargetPlatform.macOS; + final isWindows = defaultTargetPlatform == TargetPlatform.windows; + final isDesktop = !kIsWeb && (isLinux || isMacOS || isWindows); + if (isDesktop) { windowManager ..ensureInitialized() ..waitUntilReadyToShow(