Github Actions Flutter CI Error: No version of NDK matched - flutter

Project Repository
I've been push the commit
but, I got error
* What went wrong:
Execution failed for task ':app:stripReleaseDebugSymbols'.
> No version of NDK matched the requested version 20.0.5594570. Versions available locally: 21.0.6113669
Below is the CI code(Flutter CI - Customer):
name: Flutter CI - Customer
on:
push:
branches:
- master
paths:
- holinoti_customer/**
- .github/workflows/flutter-customer.yml
pull_request:
branches:
- master
paths:
- holinoti_customer/**
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2.0.0
- name: Set up JDK 11
uses: actions/setup-java#v1
with:
java-version: 11.0.2
- name: Android NDK toolchain Setup
uses: ravinderjangra/android-ndk-toolchain-setup#0.1
with:
api: '21'
arch: 'arm'
install-location: 'toolchains'
- uses: subosito/flutter-action#v1.1.1
with:
flutter-version: '1.12.x' # you can use 1.12
- name: Install dependencies
run: flutter pub get
working-directory: holinoti_customer
- name: Test Build
run: flutter build apk
working-directory: holinoti_customer
In my local project, I set the ndk path in android studio's project structure
However, this solution is can't applied on Github Action
So, I tried to use Android NDK toolchain Setup, but still fail

Instead of using the local.properties file, set ndkVersion in your build.gradle to match the one available on your CI server. i.e.
android {
ndkVersion "21.1.6352462"
}
(I'm assuming that your CI has updated to make r21b available since then, otherwise use the 21.0.blah version from the error message.)
That way your CI and your local build both use the same version.
That was the motivation for this change, btw: keeping builds reproducible. Previously your CI and your local builds were using different versions of the NDK, and that can be a surprising and annoying source of bugs :)

Check updates of SDK Tools update the NDK and CMake tools.

Related

Swift Package Github Action CI [duplicate]

I have swift package for iOS apps (it needs UIKit to run). I wan't to build this package using Github action this is how my workflow looks like
name: Swift
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout#v2
- uses: YOCKOW/Action-setup-swift#master
with:
swift-version: '5.3'
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
When I run this build I got error: no such module 'UIKit'.
So I have 2 options:
make my package UIKit independent (actually don't know how)
configure build to run on iOS specifically
What should I do?
We're using xcodebuild instead of swift build to do platform specific CI from GitHub Actions. See specific example at https://github.com/firebase/firebase-ios-sdk/blob/master/.github/workflows/spm.yml and https://github.com/firebase/firebase-ios-sdk/blob/master/scripts/build.sh#L540
The simplest approach as of 2022 is to use xcodebuild like stated above.
Condensed to the basics, the script can be as simple as this:
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift
name: Build and Test
on:
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout#v3
# Sanity check to make sure we use a valid device in the next step
- name: List available devices
run: xcrun simctl list devicetypes
#generic/platform=iOS is sufficient for just building, - but need to specify concrete destination for tests
- name: Build and run tests
run: xcodebuild test -scheme YourSchemeNameHere -destination 'platform=iOS Simulator,name=iPhone 13 Pro' #or any other name from the list of sim devices
This is enough to build the project and run tests on it.
In some cases you may need to install a later version of Swift than what's available by default on Github Actions, - you can use a third party step for that and use xcode-select.

Set current date and time as release APK name in GitHub workflows

I have a GitHub workflow for releasing nightly snapshots of the repository. This is how the workflow file looks right now:
# Define workflow name
name: main
# This workflow is triggered on pushes to the repository.
on:
push:
branches:
- main
jobs:
build:
# This job will run on windows virtual machine
runs-on: windows-latest
steps:
# Setup Java environment in order to build the Android app.
- uses: actions/checkout#v1
- uses: actions/setup-java#v1
with:
java-version: '12.x'
# Setup the flutter environment.
- uses: subosito/flutter-action#v1
with:
channel: 'stable' # 'dev', 'alpha', default to: 'stable'
flutter-version: '3.3.7' # version of flutter
# Get flutter dependencies.
- run: flutter clean
- run: flutter pub get
# Build apk.
- run: flutter build apk --release
# Upload generated apk to the artifacts.
- uses: actions/upload-artifact#v1
with:
name: app-release # want to set current date time over here
path: build/app/outputs/flutter-apk/app-release.apk
I want current datetime as release apk name. However, I couldn't find any documentation on it. How should I do it?
You can specify versionName and versionCode in the android/local.properties
flutter.versionName=YOUR-DATE-HERE
flutter.versionCode=1
UPDATE
You can specify the exact file name of generated apk file by modifying build.gradle file
buildTypes {
applicationVariants.all{
variant ->
variant.outputs.each{
// on below line we are setting a name to our apk
output->
def formattedDate = new Date().format('yyyy-MM-dd-HH-mm-ss')
output.outputFileName = formattedDate
}
}
}

Flutter continuous integration (CI) not working on github because the project is inside a folder

I'm trying to implement continuous integration on my github repository.
If the project is at the same level as root, it works. But I want to have the project inside a folder to keep it organized. On my local setup, I would do "cd my_folder", but I tried to add that to the .yml script and still fails.
Error shown:
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Error: Process completed with exit code 1.
Basically it fails because it's trying to do pub get at the root of the repository where pubspec.yaml doesn't exist, instead of inside of the folder.
This is the code:
on:
push:
branches:
- development
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- uses: actions/setup-java#v1
with:
java-version: '12.x'
- uses: subosito/flutter-action#v1
with:
channel: 'beta'
# Enter into the flutter project.
- run: cd my_folder # Here I tried to put this command, but is useless
# Get flutter dependencies.
- run: flutter pub get # <--- Here is the error
# Statically analyze the Dart code for any errors.
- run: flutter analyze .
# Run widget tests for our flutter project.
- run: flutter test
I found the solution, just needed to add a working-directory
Final code
name: CI
on:
push:
branches:
- development
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- uses: actions/setup-java#v1
with:
java-version: '12.x'
- uses: subosito/flutter-action#v1
with:
channel: 'beta'
- name: Get flutter dependencies
run: flutter pub get
working-directory: my_folder
- name: Statically analyze the Dart code for any errors.
run: flutter analyze .
working-directory: my_folder
- name: Run widget tests for our flutter project.
run: flutter test
working-directory: my_folder
This error tells you that there is no pubspec.yaml in your development branch, try to push your pubspec.yaml to the development branch.

Flutter analyze / build fails in GitHub action

When the following action is run, it fails on flutter analyze. If I remove it, it fails later on flutter build. Both commands work fine locally. I understand the message, but fail to grasp what might be wrong with the package path.
GitHub action error:
flutter analyze
shell: /bin/bash -e {0}
env:
JAVA_HOME_12.0.2_x64: /opt/hostedtoolcache/jdk/12.0.2/x64
JAVA_HOME: /opt/hostedtoolcache/jdk/12.0.2/x64
JAVA_HOME_12_0_2_X64: /opt/hostedtoolcache/jdk/12.0.2/x64
FLUTTER_HOME: /opt/hostedtoolcache/flutter/1.22.5-stable/x64
Analyzing myApp...
error • Target of URI doesn't exist: 'package:myApp/app.dart' • lib/main.dart:7:8 • uri_does_not_exist
error • The function 'App' isn't defined • lib/main.dart:38:16 • undefined_function
2 issues found. (ran in 18.4s)
Error: Process completed with exit code 1.
Action source:
name: Flutter Android Test and Build
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build_android:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout#v2
- name: Setup Java
uses: actions/setup-java#v1
with:
java-version: "12.x"
- name: Setup Flutter
uses: subosito/flutter-action#v1
with:
flutter-version: "1.22.5"
- name: Install Flutter dependencies
run: flutter pub get
- name: Format files
run: flutter format --set-exit-if-changed .
- name: Analyze code
run: flutter analyze
- name: Run tests
run: flutter test
- name: Build Android
run: flutter build apk
Passing --no-fatal-infos and --no-fatal-warnings as a flag to flutter analyzer worked for me.
Here: flutter analyze --no-fatal-infos --no-fatal-warnings
This is because, unlike dart analyzer, flutter analyzer returns a fatal exit code of 1 regardless of the severity issue (info, warning, error).
Reference
The issue was in a upper case / lower case file name typo. OSX filesystem is by default case insensitive, while Ubuntu, on which the GitHub Action runs, is not.

How to build Flutter in GitHub Actions CI/CD

I'm trying out GitHub Actions to build my Flutter app but I don't know which container image to choose from.
Is there a trusted container image that I can use for Flutter?
What are the adjustments I need to make so that the Flutter SDK is available during my build step?
Run flutter pub get
/__w/_temp/46389e95-36bc-464e-ab34-41715eb4dccb.sh: 1: /__w/_temp/46389e95-36bc-464e-ab34-41715eb4dccb.sh: flutter: not found
##[error]Process completed with exit code 127.
I adapted the dart.yml file generated by GitHub Actions to look like this:
name: Dart CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
container:
image: google/dart:latest
steps:
- uses: actions/checkout#v1
- name: Install dependencies
run: flutter pub get
- name: Run tests
run: flutter test
You don't need to use a flutter specific container, there is a Flutter Action available that runs on the default Windows, Linux and macOS containers.
This means that building your flutter app is as simple as using the action (you will also need the Java action) and then running the flutter build command. The following example runs an aot build:
on: push
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
# The flutter action needs java so include it
- uses: actions/setup-java#v1
with:
java-version: '12.x'
# Include the flutter action
- uses: subosito/flutter-action#v1
with:
channel: 'stable'
# Get flutter packages
- run: flutter pub get
# Build :D
- run: flutter build aot
I wrote a blog post about building and testing flutter using actions if you'd like to learn more.
I let my one running without Docker.
You could try to install flutter and run flutter pub get. I used in my example subosito/flutter-action#v1
name: CI
on:
pull_request:
branches:
- development
- master
jobs:
test:
name: Flutter Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- uses: actions/setup-java#v1
with:
java-version: '12.x'
- uses: subosito/flutter-action#v1
with:
flutter-version: '1.7.8+hotfix.4'
- run: flutter doctor
- run: flutter pub get
- run: flutter test
#Rezwan provided the link to the image I was looking for.
I'm still not able to run it due to the following issues:
https://github.com/cirruslabs/docker-images-flutter/issues/27
GitHub Actions workflow error: Cannot create file, path = '/github/home/.flutter'
I leave here a link to the production project with the app in the stores.
Maybe it saves time for somebody, I would be glad to have it when I implement it.
Uses secret keys for signing releases.
Create .apks for different flavors.
Add the build number to the files.
Create a GitHub release.
https://github.com/AgoraDesk-LocalMonero/agoradesk-app-foss/blob/main/.github/workflows/build_from_tags_ci.yml