Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Introduce Min supported Android SDK tests #1897

Merged
merged 22 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
call-test:
needs: call-build-example
uses: ./.github/workflows/test.yml
with:
enable_min_version: true

deploy-github-pages:
needs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ jobs:
enable_windows: ${{ github.event.pull_request.draft == false }}
enable_linux: ${{ github.event.pull_request.draft == false }}
enable_macos: ${{ github.event.pull_request.draft == false }}
enable_min_version: true
75 changes: 41 additions & 34 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ on:
required: false
default: true
type: boolean
enable_min_version:
description: 'Test Platform min version'
required: false
default: false
type: boolean

workflow_call:
inputs:
flutter_version:
Expand Down Expand Up @@ -96,6 +102,10 @@ on:
required: false
default: true
type: boolean
enable_min_version:
required: false
default: false
type: boolean

jobs:
test:
Expand Down Expand Up @@ -179,45 +189,43 @@ jobs:
--web-browser-flag="--disable-web-security" \
--dart-define USE_LOCAL_SERVER=true

android-min:
runs-on: ubuntu-latest
timeout-minutes: 90
if: inputs.enable_min_version && inputs.enable_android
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
flutter-version: ${{ inputs.flutter_version }}
channel: ${{ inputs.flutter_channel }}
- uses: bluefireteam/melos-action@v3
- name: Setup Android Emulator
timeout-minutes: 10
run: bash ./scripts/ci/setup-android.sh 21 default
- name: Run Flutter integration tests
working-directory: ./packages/audioplayers/example
# Need to execute lib and app tests one by one, see: https://github.com/flutter/flutter/issues/101031
run: |
( cd server; dart run bin/server.dart ) &
flutter test integration_test/platform_test.dart --dart-define USE_LOCAL_SERVER=true --dart-define TEST_FEATURE_BYTES_SOURCE=false --dart-define TEST_FEATURE_PLAYBACK_RATE=false
flutter test integration_test/lib_test.dart --dart-define USE_LOCAL_SERVER=true --dart-define TEST_FEATURE_BYTES_SOURCE=false --dart-define TEST_FEATURE_PLAYBACK_RATE=false
flutter test integration_test/app_test.dart --dart-define USE_LOCAL_SERVER=true --dart-define TEST_FEATURE_BYTES_SOURCE=false --dart-define TEST_FEATURE_PLAYBACK_RATE=false

android:
runs-on: ubuntu-latest
timeout-minutes: 90
if: inputs.enable_android
steps:
- name: Set env vars
run: |
echo "ANDROID_AVD_HOME=$HOME/.android/avd" >> $GITHUB_ENV
echo "ANDROID_CMDLINE_TOOLS=$ANDROID_HOME/cmdline-tools/latest/bin" >> $GITHUB_ENV
echo "ANDROID_CMDLINE_TOOLS: $ANDROID_CMDLINE_TOOLS"
echo "ANDROID_AVD_HOME: $ANDROID_AVD_HOME"
- uses: actions/checkout@v4
- name: Enable KVM group perms
# see: https://github.com/actions/runner-images/discussions/7191
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- uses: subosito/flutter-action@v2
with:
flutter-version: ${{ inputs.flutter_version }}
channel: ${{ inputs.flutter_channel }}
- uses: bluefireteam/melos-action@v3

- name: Download Android emulator image
run: |
mkdir -p $ANDROID_AVD_HOME
echo "y" | $ANDROID_CMDLINE_TOOLS/sdkmanager --install "system-images;android-30;aosp_atd;x86_64"
echo "no" | $ANDROID_CMDLINE_TOOLS/avdmanager create avd --force --name emu --device "Nexus 5X" -k "system-images;android-30;aosp_atd;x86_64"
- run: $ANDROID_HOME/emulator/emulator -list-avds
- name: Start Android emulator
- name: Setup Android Emulator
timeout-minutes: 10
run: |
echo "Starting emulator"
$ANDROID_CMDLINE_TOOLS/sdkmanager "platform-tools" "platforms;android-30"
nohup $ANDROID_HOME/emulator/emulator -avd emu -no-audio -no-snapshot -no-window &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'
$ANDROID_HOME/platform-tools/adb devices
echo "Emulator started"
run: bash ./scripts/ci/setup-android.sh 30
- name: Run Flutter integration tests
working-directory: ./packages/audioplayers/example
# Need to execute lib and app tests one by one, see: https://github.com/flutter/flutter/issues/101031
Expand All @@ -226,16 +234,15 @@ jobs:
flutter test integration_test/platform_test.dart --dart-define USE_LOCAL_SERVER=true
flutter test integration_test/lib_test.dart --dart-define USE_LOCAL_SERVER=true
flutter test integration_test/app_test.dart --dart-define USE_LOCAL_SERVER=true

- name: Run Android unit tests
working-directory: ./packages/audioplayers/example/android
run: ./gradlew test

ios-16:
ios-min:
# Run lib tests only to ensure compatibility with iOS 16.
runs-on: macos-13
timeout-minutes: 60
if: inputs.enable_ios
if: inputs.enable_min_version && inputs.enable_ios
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
Expand All @@ -256,7 +263,7 @@ jobs:
( cd server; dart run bin/server.dart ) &
flutter test -d $UDID integration_test/lib_test.dart --dart-define USE_LOCAL_SERVER=true

ios-17:
ios:
runs-on: macos-14
timeout-minutes: 60
if: inputs.enable_ios
Expand All @@ -281,11 +288,11 @@ jobs:
flutter test -d $UDID integration_test/lib_test.dart --dart-define USE_LOCAL_SERVER=true
flutter test -d $UDID integration_test/app_test.dart --dart-define USE_LOCAL_SERVER=true

macos-13:
macos-min:
# TODO: Run lib tests only to ensure compatibility with macOS 13, once tests for macOS 14 succeed.
runs-on: macos-13
timeout-minutes: 30
if: inputs.enable_macos
if: inputs.enable_min_version && inputs.enable_macos
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
Expand All @@ -303,7 +310,7 @@ jobs:
flutter test -d macos integration_test/lib_test.dart --dart-define USE_LOCAL_SERVER=true
flutter test -d macos integration_test/app_test.dart --dart-define USE_LOCAL_SERVER=true

macos-14:
macos:
runs-on: macos-14
timeout-minutes: 30
if: inputs.enable_macos
Expand Down
4 changes: 4 additions & 0 deletions packages/audioplayers/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ android {
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = 17
}

defaultConfig {
applicationId = "xyz.luan.audioplayers.example"
minSdk = flutter.minSdkVersion
Expand Down
20 changes: 12 additions & 8 deletions packages/audioplayers/example/integration_test/lib_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,20 @@ void main() async {
await player.dispose();
});

testWidgets('bytes array source', (WidgetTester tester) async {
final player = AudioPlayer();
testWidgets(
'bytes array source',
(WidgetTester tester) async {
final player = AudioPlayer();

await player.play((await mp3BytesTestData()).source);
// Sources take some time to get initialized
await tester.pumpPlatform(const Duration(seconds: 8));
await player.stop();
await player.play((await mp3BytesTestData()).source);
// Sources take some time to get initialized
await tester.pumpPlatform(const Duration(seconds: 8));
await player.stop();

await player.dispose();
});
await player.dispose();
},
skip: !features.hasBytesSource,
);

group('AP events', () {
late AudioPlayer player;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import 'package:flutter/foundation.dart';

const testFeatureBytesSource = bool.fromEnvironment(
'TEST_FEATURE_BYTES_SOURCE',
defaultValue: true,
);

const testFeaturePlaybackRate = bool.fromEnvironment(
'TEST_FEATURE_PLAYBACK_RATE',
defaultValue: true,
);

/// Specify supported features for a platform.
class PlatformFeatures {
static const webPlatformFeatures = PlatformFeatures(
Expand All @@ -16,6 +26,10 @@ class PlatformFeatures {

static const androidPlatformFeatures = PlatformFeatures(
hasRecordingActive: false,
// ignore: avoid_redundant_argument_values
hasBytesSource: testFeatureBytesSource,
// ignore: avoid_redundant_argument_values
hasPlaybackRate: testFeaturePlaybackRate,
);

static const iosPlatformFeatures = PlatformFeatures(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class AudioplayersPlugin : FlutterPlugin {
"setSourceBytes" -> {
val bytes = call.argument<ByteArray>("bytes") ?: error("bytes are required")
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
error("Operation not supported on Android <= M")
error("BytesSource is not supported on Android <= M")
}
player.source = BytesSource(bytes)
}
Expand Down
48 changes: 48 additions & 0 deletions scripts/ci/setup-android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env
set -e

ANDROID_SDK_VERSION=${1:-35} # Default to 30 if no version is provided
ANDROID_SYSTEM_IMAGE_SOURCE=${2:-aosp_atd}
ANDROID_ABI=${3:-x86_64}

echo "Enable KVM permissions"
# see: https://github.com/actions/runner-images/discussions/7191
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

echo "Setting up Android environment for API level $ANDROID_SDK_VERSION"

# Set environment variables
export ANDROID_AVD_HOME="$HOME/.android/avd"
echo "ANDROID_AVD_HOME=$ANDROID_AVD_HOME" >> "$GITHUB_ENV"
echo "ANDROID_AVD_HOME: $ANDROID_AVD_HOME"
mkdir -p "$ANDROID_AVD_HOME"

export ANDROID_CMDLINE_TOOLS="$ANDROID_HOME/cmdline-tools/latest/bin"
echo "ANDROID_CMDLINE_TOOLS=$ANDROID_CMDLINE_TOOLS" >> "$GITHUB_ENV"
echo "ANDROID_CMDLINE_TOOLS: $ANDROID_CMDLINE_TOOLS"

echo "Install Android Emulator"
"$ANDROID_CMDLINE_TOOLS"/sdkmanager --install "emulator"

AVD_IMAGE="system-images;android-$ANDROID_SDK_VERSION;$ANDROID_SYSTEM_IMAGE_SOURCE;$ANDROID_ABI"

echo "Install Android System Image: $AVD_IMAGE"
echo "y" | "$ANDROID_CMDLINE_TOOLS"/sdkmanager --install "$AVD_IMAGE"

echo "Create AVD with Image: $AVD_IMAGE"
echo "no" | "$ANDROID_CMDLINE_TOOLS"/avdmanager create avd --force --name emu --device "Nexus 5X" -k "$AVD_IMAGE"

echo "List available AVDs"
"$ANDROID_HOME"/emulator/emulator -list-avds

echo "Install platform tools"
"$ANDROID_CMDLINE_TOOLS"/sdkmanager "platform-tools"

# Start Emulator
echo "Starting emulator"
nohup "$ANDROID_HOME"/emulator/emulator -avd emu -no-audio -no-snapshot -no-window &
"$ANDROID_HOME"/platform-tools/adb wait-for-device shell "while [[ -z \$(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82"
"$ANDROID_HOME"/platform-tools/adb devices
echo "Emulator started"