Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GitHub Actions workflow to build Flutter app and create Release, put this file under `.github/workflows` folder.
on:
push:
branches:
- master
name: Build and Release Apps
jobs:
build:
name: Build Apps
runs-on: macos-latest
steps:
- name: Export Release Timestamp
run: echo "APP_VERSION=v$(date +'%Y.%m.%d.%H.%M.%S')" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v1
- name: Set up Java
uses: actions/setup-java@v2
with:
java-version: '15'
distribution: 'adopt'
- name: Set up Flutter
uses: subosito/flutter-action@v1
with:
channel: 'stable'
- name: Install pub Dependencies
run: flutter pub get
- name: Run Tests
run: flutter test
- name: Build Android App
run: flutter build apk --split-per-abi
- name: Build iOS App
run: |
flutter build ios --no-codesign
cd build/ios/iphoneos
mkdir Payload
cd Payload
ln -s ../Runner.app
cd ..
zip -r app.ipa Payload
- name: Build Web App
run: |
flutter build web
cd build/web
zip -r web-app.zip .
- name: Release Apps
uses: ncipollo/release-action@v1
with:
tag: ${{ env.APP_VERSION }}
name: ${{ env.APP_VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: 'build/app/outputs/apk/release/*.apk,build/ios/iphoneos/app.ipa,build/web/web-app.zip'
@sank8dalvi

This comment has been minimized.

Copy link

@sank8dalvi sank8dalvi commented Nov 21, 2020

set-env is deprecated in github actions and thus Export Release Timestamp is giving a error.
You can make changes according to the new environment file handling on github
Please update the run command with the following new syntax to fix it.

echo "APP_VERSION=release_$(date +'%Y-%m-%d_%H-%m-%S')" >> $GITHUB_ENV

@devhammed

This comment has been minimized.

Copy link
Owner Author

@devhammed devhammed commented Nov 22, 2020

set-env is deprecated in github actions and thus Export Release Timestamp is giving a error.
You can make changes according to the new environment file handling on github
Please update the run command with the following new syntax to fix it.

echo "APP_VERSION=release_$(date +'%Y-%m-%d_%H-%m-%S')" >> $GITHUB_ENV

Thank you ☺️

I have updated it accordingly.

@ariefwijaya

This comment has been minimized.

Copy link

@ariefwijaya ariefwijaya commented Jun 18, 2021

I've tried your code but I got this error when building APK.

Run flutter build apk --release

Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

Running Gradle task 'assembleRelease'...                        
warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
Note: Some input files use or override a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

Note: Some input files use unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

3 warnings

warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

3 warnings


warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
Note: /Users/runner/hostedtoolcache/flutter/2.2.2-stable/x64/.pub-cache/hosted/pub.dartlang.org/device_info_plus-1.0.1/android/src/main/java/dev/fluttercommunity/plus/device_info/DeviceInfoPlusPlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

3 warnings

warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.


Note: /Users/runner/hostedtoolcache/flutter/2.2.2-stable/x64/.pub-cache/hosted/pub.dartlang.org/flutter_mailer-2.0.0/android/src/main/java/com/dataxad/flutter_mailer/FlutterMailerPlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

3 warnings
warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

3 warnings

warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

Note: /Users/runner/hostedtoolcache/flutter/2.2.2-stable/x64/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.1/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

3 warnings


warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

error: warnings found and -Werror specified



FAILURE: Build failed with an exception.



* What went wrong:

Execution failed for task ':connectivity:compileReleaseJavaWithJavac'.

> Compilation failed; see the compiler error output for details.



* 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 39s
Running Gradle task 'assembleRelease'...                          282.2s
Gradle task assembleRelease failed with exit code 1
Error: Process completed with exit code 1.
@apoorvpandey0

This comment has been minimized.

Copy link

@apoorvpandey0 apoorvpandey0 commented Jun 22, 2021

Where is the file stored?
I had added build to gitignore in my project

@devhammed

This comment has been minimized.

Copy link
Owner Author

@devhammed devhammed commented Jun 22, 2021

I've tried your code but I got this error when building APK.

Run flutter build apk --release

Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

Running Gradle task 'assembleRelease'...                        
warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
Note: Some input files use or override a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

Note: Some input files use unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

3 warnings

warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

3 warnings


warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
Note: /Users/runner/hostedtoolcache/flutter/2.2.2-stable/x64/.pub-cache/hosted/pub.dartlang.org/device_info_plus-1.0.1/android/src/main/java/dev/fluttercommunity/plus/device_info/DeviceInfoPlusPlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

3 warnings

warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.


Note: /Users/runner/hostedtoolcache/flutter/2.2.2-stable/x64/.pub-cache/hosted/pub.dartlang.org/flutter_mailer-2.0.0/android/src/main/java/com/dataxad/flutter_mailer/FlutterMailerPlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

3 warnings
warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

3 warnings

warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

Note: /Users/runner/hostedtoolcache/flutter/2.2.2-stable/x64/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.1/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

3 warnings


warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

error: warnings found and -Werror specified



FAILURE: Build failed with an exception.



* What went wrong:

Execution failed for task ':connectivity:compileReleaseJavaWithJavac'.

> Compilation failed; see the compiler error output for details.



* 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 39s
Running Gradle task 'assembleRelease'...                          282.2s
Gradle task assembleRelease failed with exit code 1
Error: Process completed with exit code 1.

This doesn't seem to be an error with the builder but the package you are using.

@devhammed

This comment has been minimized.

Copy link
Owner Author

@devhammed devhammed commented Jun 22, 2021

Where is the file stored?
I had added build to gitignore in my project

put this file under .github/workflows folder.

@apoorvpandey0

This comment has been minimized.

Copy link

@apoorvpandey0 apoorvpandey0 commented Jun 22, 2021

Where is the file stored?
I had added build to gitignore in my project

put this file under .github/workflows folder.

Yes this file is under .github/workflows, I'm asking about the build files, the .ipa , .apk and web.zip files.
Where are those files being stored ?
I hope this makes it a bit more clear.

@devhammed

This comment has been minimized.

Copy link
Owner Author

@devhammed devhammed commented Jun 22, 2021

Where is the file stored?
I had added build to gitignore in my project

put this file under .github/workflows folder.

Yes this file is under .github/workflows, I'm asking about the build files, the .ipa , .apk and web.zip files.
Where are those files being stored ?
I hope this makes it a bit more clear.

Oh, it will be part of your release assets, kindly check your repository releases page.

@ariefwijaya

This comment has been minimized.

Copy link

@ariefwijaya ariefwijaya commented Jun 23, 2021

I've tried your code but I got this error when building APK.

Run flutter build apk --release

Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

Running Gradle task 'assembleRelease'...                        
warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
Note: Some input files use or override a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

Note: Some input files use unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

3 warnings

warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

3 warnings


warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
Note: /Users/runner/hostedtoolcache/flutter/2.2.2-stable/x64/.pub-cache/hosted/pub.dartlang.org/device_info_plus-1.0.1/android/src/main/java/dev/fluttercommunity/plus/device_info/DeviceInfoPlusPlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

3 warnings

warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.


Note: /Users/runner/hostedtoolcache/flutter/2.2.2-stable/x64/.pub-cache/hosted/pub.dartlang.org/flutter_mailer-2.0.0/android/src/main/java/com/dataxad/flutter_mailer/FlutterMailerPlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

3 warnings
warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

3 warnings

warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

Note: /Users/runner/hostedtoolcache/flutter/2.2.2-stable/x64/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.1/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

3 warnings


warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

error: warnings found and -Werror specified



FAILURE: Build failed with an exception.



* What went wrong:

Execution failed for task ':connectivity:compileReleaseJavaWithJavac'.

> Compilation failed; see the compiler error output for details.



* 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 39s
Running Gradle task 'assembleRelease'...                          282.2s
Gradle task assembleRelease failed with exit code 1
Error: Process completed with exit code 1.

This doesn't seem to be an error with the builder but the package you are using.

But it worked in my local environment. I can build without any problem using Flutter build command. Is it because of gradle or do I need configure android sdk in this workflow?

@devhammed

This comment has been minimized.

Copy link
Owner Author

@devhammed devhammed commented Jun 23, 2021

I've tried your code but I got this error when building APK.

Run flutter build apk --release

Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

Running Gradle task 'assembleRelease'...                        
warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
Note: Some input files use or override a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

Note: Some input files use unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

3 warnings

warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

3 warnings


warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
Note: /Users/runner/hostedtoolcache/flutter/2.2.2-stable/x64/.pub-cache/hosted/pub.dartlang.org/device_info_plus-1.0.1/android/src/main/java/dev/fluttercommunity/plus/device_info/DeviceInfoPlusPlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

3 warnings

warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.


Note: /Users/runner/hostedtoolcache/flutter/2.2.2-stable/x64/.pub-cache/hosted/pub.dartlang.org/flutter_mailer-2.0.0/android/src/main/java/com/dataxad/flutter_mailer/FlutterMailerPlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

3 warnings
warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

3 warnings

warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

Note: /Users/runner/hostedtoolcache/flutter/2.2.2-stable/x64/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.1/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

3 warnings


warning: [options] source value 7 is obsolete and will be removed in a future release

warning: [options] target value 7 is obsolete and will be removed in a future release

warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.

error: warnings found and -Werror specified



FAILURE: Build failed with an exception.



* What went wrong:

Execution failed for task ':connectivity:compileReleaseJavaWithJavac'.

> Compilation failed; see the compiler error output for details.



* 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 39s
Running Gradle task 'assembleRelease'...                          282.2s
Gradle task assembleRelease failed with exit code 1
Error: Process completed with exit code 1.

This doesn't seem to be an error with the builder but the package you are using.

But it worked in my local environment. I can build without any problem using Flutter build command. Is it because of gradle or do I need configure android sdk in this workflow?

I think this has to do with the Java version, I have updated it, kindly copy the new workflow.

@nd-sin

This comment has been minimized.

Copy link

@nd-sin nd-sin commented Jul 6, 2021

I got this following error and changed the java-version: '15' -> java-version: '8' then it worked.

Running Gradle task 'assembleRelease'... java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7

@ariefwijaya

This comment has been minimized.

Copy link

@ariefwijaya ariefwijaya commented Jul 6, 2021

I got this following error and changed the java-version: '15' -> java-version: '8' then it worked.

Running Gradle task 'assembleRelease'... java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7

Thank youu.. I agree with you. java-version is my problem.

@thecodepapaya

This comment has been minimized.

Copy link

@thecodepapaya thecodepapaya commented Sep 10, 2021

The minutes tag run: echo "APP_VERSION=v$(date +'%Y.%m.%d.%H.%m.%S')" >> $GITHUB_ENV is actually returning the month. I guess it should be M instead of m.

run: echo "APP_VERSION=v$(date +'%Y.%m.%d.%H.%M.%S')" >> $GITHUB_ENV

Notice the %M between %H and %S

@devhammed

This comment has been minimized.

Copy link
Owner Author

@devhammed devhammed commented Sep 10, 2021

The minutes tag run: echo "APP_VERSION=v$(date +'%Y.%m.%d.%H.%m.%S')" >> $GITHUB_ENV is actually returning the month. I guess it should be M instead of m.

run: echo "APP_VERSION=v$(date +'%Y.%m.%d.%H.%M.%S')" >> $GITHUB_ENV

Notice the %M between %H and %S

OMG!

Thank you and I have updated it.

@hasanm08

This comment has been minimized.

Copy link

@hasanm08 hasanm08 commented Sep 22, 2021

use runs-on: macos-11 to avoid sum problems

@devhammed

This comment has been minimized.

Copy link
Owner Author

@devhammed devhammed commented Sep 23, 2021

use runs-on: macos-11 to avoid sum problems

Okay, some problems like?

@hasanm08

This comment has been minimized.

Copy link

@hasanm08 hasanm08 commented Sep 23, 2021

use runs-on: macos-11 to avoid sum problems

Okay, some problems like?

I needed macos version 11 to built ios in Flutter version 2.5.1

@devhammed

This comment has been minimized.

Copy link
Owner Author

@devhammed devhammed commented Sep 24, 2021

use runs-on: macos-11 to avoid sum problems

Okay, some problems like?

I needed macos version 11 to built ios in Flutter version 2.5.1

Oh Alright.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment