subosito / flutter-action

Flutter environment for use in GitHub Actions. It works on Linux, Windows, and macOS.
MIT License
2.28k stars 202 forks source link

Flutter not building app in the CI #321

Closed dag7dev closed 4 months ago

dag7dev commented 4 months ago

workflows/main.yml

name: Flutter Build and Release

on:
  push:
    branches:
      - master
    tags:
      - "v*.*.*"
  workflow_dispatch: 

jobs:
  build:
    runs-on: ubuntu-latest

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

    - name: Set up Flutter
      uses: subosito/flutter-action@v2
      with:
        flutter-version: '3.22.2'

    - name: Install dependencies
      run: flutter pub get

    - name: Build APK
      run: flutter build apk --release

    - name: Upload APK to release
      uses: softprops/action-gh-release@v2
      with:
        files: build/app/outputs/flutter-apk/app-release.apk
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Full log

flutter build apk --release
  shell: /usr/bin/bash -e {0}
  env:
    FLUTTER_ROOT: /opt/hostedtoolcache/flutter/stable-3.22.2-x64
    PUB_CACHE: /home/runner/.pub-cache

Running Gradle task 'assembleRelease'...                        
Checking the license for package Android SDK Platform-Tools in /usr/local/lib/android/sdk/licenses
License for package Android SDK Platform-Tools accepted.
Preparing "Install Android SDK Platform-Tools (revision: 35.0.1)".
"Install Android SDK Platform-Tools (revision: 35.0.1)" ready.
Installing Android SDK Platform-Tools in /usr/local/lib/android/sdk/platform-tools
"Install Android SDK Platform-Tools (revision: 35.0.1)" complete.
"Install Android SDK Platform-Tools (revision: 35.0.1)" finished.
Checking the license for package Android Emulator in /usr/local/lib/android/sdk/licenses
License for package Android Emulator accepted.
Preparing "Install Android Emulator (revision: 34.2.16)".
"Install Android Emulator (revision: 34.2.16)" ready.
Installing Android Emulator in /usr/local/lib/android/sdk/emulator
"Install Android Emulator (revision: 34.2.16)" complete.
"Install Android Emulator (revision: 34.2.16)" finished.
Checking the license for package Android SDK Tools in /usr/local/lib/android/sdk/licenses
License for package Android SDK Tools accepted.
Preparing "Install Android SDK Tools (revision: 26.1.1)".
"Install Android SDK Tools (revision: 26.1.1)" ready.
Installing Android SDK Tools in /usr/local/lib/android/sdk/tools
"Install Android SDK Tools (revision: 26.1.1)" complete.
"Install Android SDK Tools (revision: 26.1.1)" finished.
Checking the license for package Android SDK Build-Tools 30.0.3 in /usr/local/lib/android/sdk/licenses
License for package Android SDK Build-Tools 30.0.3 accepted.
Preparing "Install Android SDK Build-Tools 30.0.3 (revision: 30.0.3)".
"Install Android SDK Build-Tools 30.0.3 (revision: 30.0.3)" ready.
Installing Android SDK Build-Tools 30.0.3 in /usr/local/lib/android/sdk/build-tools/30.0.3
"Install Android SDK Build-Tools 30.0.3 (revision: 30.0.3)" complete.
"Install Android SDK Build-Tools 30.0.3 (revision: 30.0.3)" finished.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':device_info_plus:compileReleaseJavaWithJavac'.
> error: invalid source release: 17
* 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 4m 7s
Running Gradle task 'assembleRelease'...                          249.5s
Gradle task assembleRelease failed with exit code 1
Error: Process completed with exit code 1.

I have no idea what's wrong with it.

bhagat-abhishek commented 4 months ago

I am having the same issue, and after trying a lot of changes the error is still there. But to note is the with codemagic.io the build runs fine.

bartekpacia commented 4 months ago

This is a Java-related issue.

I recommend you make sure you're using a modern JDK when building your app. You can do this by inserting this step before subosito/flutter-action:

- name: Set up Java
  uses: actions/setup-java@v4
  with:
    distribution: zulu
    java-version: 21

in your android/app/build.gradle, make sure you set:

android {
    // ...
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }

This should help.

bhagat-abhishek commented 4 months ago

@bartekpacia yes, I have tried doing it when running the build. its the same although. Fun fact the code actually works to build in codemagic.io with and without the specific change.

bartekpacia commented 4 months ago

It means some part of environment is different across GHA and codemagic. It's up to you to figure that out.

bhagat-abhishek commented 4 months ago

@bartekpacia ohh, its gonna be hard for me. I am not even a beginner to flutter. sad; thanks for help though

bartekpacia commented 4 months ago

If your project is open-source, you can share link to it and to the workflow and I can take a look.

bhagat-abhishek commented 4 months ago

@bartekpacia no open source, but if you can lend some few minutes of yours; I could add you as collaborator.

bhagat-abhishek commented 4 months ago

@bartekpacia sorry if that was a wrong question from me; although thank you for the help.

bartekpacia commented 4 months ago

no, not at all. feel free to add me as collaborator and i'll spend 5 minutes looking into it. no promises though, i'm quite busy myself.

bhagat-abhishek commented 4 months ago

@bartekpacia hey thanks for your response, I have added you as collaborator. Do let me know of anything, I trust you with the code.

bartekpacia commented 4 months ago

@bhagat-abhishek See the PR. Your problem was using too old Gradle version (8.0) with a too new Java version (21). Please consult gradle-java compat matrix.

There is a different error right now, but I don't have time to fix that. I wish you all the best.

Also I'm going to close this issue right now since it's not related to this action.

bhagat-abhishek commented 4 months ago

@bartekpacia Thanks for you help, I will try it.