Adding an apk build and disabling the iOS build #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Mobile Applications | |
| on: | |
| # Trigger the mobile build on pushes to main and pull requests | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| # Android build job. Uses the Ubuntu runner to download the Android | |
| # command‑line tools, SDK, NDK, and CMake. Then it invokes the Gradle | |
| # wrapper (android/gradlew) to build a release APK using the project under | |
| # android/. The resulting APK and the repo's assets folder are packaged | |
| # into a single zip. Note: minSdk is 24 (Android 7.0+), targetSdk is 34. | |
| android: | |
| runs-on: ubuntu-latest | |
| env: | |
| ANDROID_HOME: ${{ github.workspace }}/android-sdk | |
| ANDROID_SDK_ROOT: ${{ github.workspace }}/android-sdk | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v3 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: temurin | |
| # Use JDK 17 to satisfy newer Android Gradle Plugin requirements | |
| java-version: '17' | |
| - name: Install Android SDK and NDK | |
| run: | | |
| set -e | |
| mkdir -p "$ANDROID_HOME" && cd "$ANDROID_HOME" | |
| # Download the latest command line tools. The version number may need updating over time. | |
| curl -sSL -o cmdline-tools.zip \ | |
| https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip | |
| # Remove any existing cmdline-tools to avoid nested directories | |
| rm -rf cmdline-tools | |
| unzip -q cmdline-tools.zip | |
| rm cmdline-tools.zip | |
| # The zip extracts a folder named 'cmdline-tools'. Rename it to a temporary name | |
| mv cmdline-tools cmdline-tools-temp | |
| # Create the expected hierarchy and move the extracted tools into 'latest' | |
| mkdir -p cmdline-tools | |
| mv cmdline-tools-temp cmdline-tools/latest | |
| # Add sdkmanager to PATH | |
| export PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$PATH" | |
| yes | sdkmanager --licenses | |
| sdkmanager \ | |
| "platform-tools" \ | |
| # Use platform 34 to match compileSdk/targetSdk in android/app/build.gradle | |
| "platforms;android-34" \ | |
| "build-tools;34.0.0" \ | |
| "ndk;27.2.12479018" \ | |
| "cmake;3.22.1" | |
| # Build the Android APK using the Gradle wrapper included in the repository. The Gradle build | |
| # will invoke CMake via externalNativeBuild and package the native library and assets into an APK. | |
| - name: Build Android APK | |
| run: | | |
| set -e | |
| # Change into the android project directory where gradlew lives | |
| cd android | |
| # Ensure the wrapper is executable | |
| chmod +x gradlew | |
| # Build a release APK; adjust the task if you need debug (assembleDebug) | |
| ./gradlew assembleRelease | |
| - name: Package Android APK and assets | |
| run: | | |
| set -e | |
| # Create a staging directory for packaging | |
| mkdir -p packaged | |
| # Find the generated APK (release build) and copy it into packaged | |
| APK_PATH=$(find android/app/build/outputs -type f -name "*.apk" | head -n 1 || true) | |
| if [ -n "$APK_PATH" ]; then | |
| cp "$APK_PATH" packaged/mw_recreation.apk | |
| else | |
| echo "No APK found; build may have failed" && exit 1 | |
| fi | |
| # Copy the assets directory for convenience (the APK already includes them) | |
| cp -r assets packaged/assets | |
| # Create a zip archive containing the APK and assets at the root of the zip | |
| (cd packaged && zip -r ../android-latest.zip .) | |
| - name: Upload Android package | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: android-latest | |
| path: android-latest.zip | |
| # iOS build job. Runs on a macOS runner because iOS compilation requires | |
| # Xcode. It configures CMake to generate an Xcode project targeting | |
| # arm64 devices. The deployment target is set to iOS 9.0; if that | |
| # fails in practice, updating to iOS 12 or 15 can be done by changing | |
| # the deployment target below. Packaging simply zips the resulting | |
| # .app bundle together with the assets directory. | |
| ios: | |
| # Temporarily disabled iOS build | |
| if: false | |
| runs-on: macos-12 | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v3 | |
| - name: Install dependencies | |
| run: | | |
| brew update | |
| brew install cmake | |
| - name: Configure iOS build with CMake | |
| run: | | |
| set -e | |
| cmake -S . -B build/ios -G Xcode \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DCMAKE_OSX_SYSROOT=iphoneos \ | |
| -DCMAKE_OSX_ARCHITECTURES=arm64 \ | |
| -DCMAKE_OSX_DEPLOYMENT_TARGET=9.0 | |
| - name: Build iOS | |
| run: | | |
| cmake --build build/ios --config Release --parallel | |
| - name: Package iOS binary and assets | |
| run: | | |
| set -e | |
| mkdir -p packaged | |
| # Find the .app bundle generated by the Xcode build and copy it into packaged | |
| find build/ios -name '*.app' -print -exec cp -R {} packaged/mw_recreation.app \; -quit | |
| cp -r assets packaged/assets | |
| zip -r macos-latest.zip packaged | |
| - name: Upload iOS package | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: macos-latest | |
| path: macos-latest.zip |