ReactiveCircus / android-emulator-runner

A GitHub Action for installing, configuring and running hardware-accelerated Android Emulators on macOS virtual machines.
Apache License 2.0
937 stars 184 forks source link

Unable to connect to Google Play Services #269

Closed baconcheese113 closed 1 year ago

baconcheese113 commented 1 year ago

Trying to setup Github Actions with my Flutter integration tests. Currently the iOS job succeeds but the Android job fails, initially with this error

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following FirebaseException was thrown running a test:
[firebase_messaging/unknown] java.io.IOException: java.util.concurrent.ExecutionException:
java.io.IOException: AUTHENTICATION_FAILED

#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
<asynchronous suspension>
#2      StackZoneSpecification._registerUnaryCallback.<anonymous closure>
(package:stack_trace/src/stack_zone_specification.dart:125:47)
<asynchronous suspension>

When the exception was thrown, this was the stack:
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)

The test description was:
  Should register

And my job

android:
  runs-on: macos-latest
  strategy:
    matrix:
      api-level:
        - 29
    fail-fast: true
  steps:
    - uses: ikalnytskyi/action-setup-postgres@v3
      with:
        username: postgres
        password: postgres
        database: postgres
        port: 5432
      id: postgres

    - name: Checkout app repo
      uses: actions/checkout@v3
      with:
        path: handle-it-app

    - name: Checkout server repo
      uses: actions/checkout@v3
      with:
        repository: baconcheese113/handle-it-server
        path: handle-it-server

    - name: Setup Nodejs
      uses: actions/setup-node@v3
      with:
        node-version: 18.7.0
        cache: 'npm'
        cache-dependency-path: './handle-it-server/package-lock.json'

    - name: Run HandleIt backend
      run: |
        cd handle-it-server
        touch .env
        echo "DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres?schema=public" >> .env
        echo "FCM_TOKEN=test_fcm_token" >> .env
        echo "JWT_SECRET=test_secret" >> .env
        echo "FIREBASE_PROJECT_ID=handleit-f352d" >> .env
        echo "FIREBASE_PRIVATE_KEY=${{ secrets.FIREBASE_PRIVATE_KEY }}" >> .env
        echo "FIREBASE_CLIENT_EMAIL=firebase-adminsdk-icmto@handleit-f352d.iam.gserviceaccount.com" >> .env
        echo "HUB_CURRENT_FIRMWARE_VERSION=0.1.0" >> .env
        echo "SENSOR_CURRENT_FIRMWARE_VERSION=0.1.1" >> .env
        npm install
        npm run push-db:dev
        npm run build
        npm run seed

    - name: Set up JDK 11
      uses: actions/setup-java@v1
      with:
        java-version: 11

    - name: Cache Flutter dependencies
      uses: actions/cache@v3
      with:
        path: ${{ runner.tool_cache }}//flutter
        key: flutter-${{ env.FLUTTER_VERSION }}-stable

    - name: Setup Flutter SDK
      uses: subosito/flutter-action@v2
      with:
        channel: stable
        flutter-version: ${{ env.FLUTTER_VERSION }}

    - name: Install Flutter dependencies
      run: |
        cd handle-it-app
        flutter --version
        flutter pub get

    - name: Add built files
      run: |
        cd handle-it-app
        touch .env
        echo API_URL=http://10.0.2.2:4000 >> .env
        echo FIRMWARE_SERVER_URL=${{ secrets.FIRMWARE_SERVER_URL }} >> .env
        echo GOOGLE_MAPS_API_KEY=${{ secrets.GOOGLE_MAPS_API_KEY }} >> .env
        cat .env
        flutter pub run build_runner build

    - name: Start server
      run: |
        cd handle-it-server &&
        npm run start &
        sleep 5 &&
        curl http://localhost:4000 -I

    - name: Gradle cache
      uses: gradle/gradle-build-action@v2

    - name: AVD cache
      uses: actions/cache@v3
      id: avd-cache
      with:
        path: |
          ~/.android/avd/*
          ~/.android/avb*
        key: avd-${{ matrix.api-level }}

    - name: Create AVD and generate snapshot for caching
      if: steps.avd-cache.outputs.cache-hit != true
      uses: reactivecircus/android-emulator-runner@v2
      with:
        api-level: ${{ matrix.api-level }}
        profile: Nexus 5
        target: playstore
        arch: x86_64
        force-avd-creation: false
        emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
        disable-animations: false
        script: echo "Generated AVD snapshot for caching."

    - name: Run integration tests
      # more info on https://github.com/ReactiveCircus/android-emulator-runner
      uses: reactivecircus/android-emulator-runner@v2
      with:
        api-level: ${{ matrix.api-level }}
        profile: Nexus 5
        target: playstore
        arch: x86_64
        force-avd-creation: false
        emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
        disable-animations: false
        script: cd handle-it-app && flutter test integration_test --flavor devtest --verbose

With a bit of googling, it seems the AUTHENTICATION_FAILED error stems from not having access to Google Play Services Any idea why it wouldn't be working with this config? I've tried google_apis and playstore as the targets

baconcheese113 commented 1 year ago

image It appears as tho API level 28 must be used for compatibility with google_apis

ychescale9 commented 1 year ago

Not all combinations are available. Please run sdkmanager --list | grep system-images to see all the system images Google has published.

baconcheese113 commented 1 year ago

That's a good resource to have, but it does list each API as having a playstore compatible image

Screen Shot 2022-10-03 at 5 10 46 PM
ychescale9 commented 1 year ago

If your tests are failing on all API levels, it's probably not something related to the action.

If you can get the tests to pass locally with the same system image, it should work on CI.