Using a completely new/empty project and trying to enable just_audio_background causes a runtime exception when running on Android Emulator (and real Android for that matter).
https://pub.dev/packages/just_audio_background
Works fully fine on iOS and web. Need it as a I have a customised audio player (using just_audio).
According to the instructions of just_audio_background it is initialised in main.dart like this:
Future<void> main() async {
await JustAudioBackground.init(
androidNotificationChannelId: 'com.ryanheise.bg_demo.channel.audio',
androidNotificationChannelName: 'Audio playback',
androidNotificationOngoing: true,
);
runApp(MyApp());
}
As it's not possible directly to edit main.dart in FlutterFlow, then this is solved (and works fine for iOS) by having a custom action included in the main.dart like this:
From a code perspective this should be the exact same as the example from just_audio_background.
On Android this problem then occurs when starting the app (it compiles fine, on a fully empty project with just the custom initial action). When starting this runtime exception shows up and the app halts.
java.lang.IllegalStateException: The Activity class declared in your AndroidManifest.xml is wrong or has not provided the correct FlutterEngine. Please see the README for instructions.
Full output:
Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
Upgrading build.gradle
Running Gradle task 'assembleDebug'... 6.9s
โ Built build/app/outputs/flutter-apk/app-debug.apk
Installing build/app/outputs/flutter-apk/app-debug.apk... 1,578ms
W/System.err(11289): java.lang.IllegalStateException: The Activity class declared in your AndroidManifest.xml is wrong or has not provided the correct FlutterEngine. Please see the README for instructions.
W/System.err(11289): at com.ryanheise.audioservice.AudioServicePlugin$ClientInterface.onMethodCall(AudioServicePlugin.java:445)
W/System.err(11289): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
W/System.err(11289): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
W/System.err(11289): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
W/System.err(11289): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
W/System.err(11289): at android.os.Handler.handleCallback(Handler.java:958)
W/System.err(11289): at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err(11289): at android.os.Looper.loopOnce(Looper.java:205)
W/System.err(11289): at android.os.Looper.loop(Looper.java:294)
W/System.err(11289): at android.app.ActivityThread.main(ActivityThread.java:8177)
W/System.err(11289): at java.lang.reflect.Method.invoke(Native Method)
W/System.err(11289): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
W/System.err(11289): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Syncing files to device sdk gphone64 arm64...
E/flutter (11289): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(The Activity class declared in your AndroidManifest.xml is wrong or has not provided the correct FlutterEngine. Please see the README for instructions., null, null, null)
E/flutter (11289): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7)
E/flutter (11289): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
E/flutter (11289): <asynchronous suspension>
E/flutter (11289): #2 MethodChannelAudioService.configure (package:audio_service_platform_interface/method_channel_audio_service.dart:14:5)
E/flutter (11289): <asynchronous suspension>
E/flutter (11289): #3 AudioService.init (package:audio_service/audio_service.dart:1007:5)
E/flutter (11289): <asynchronous suspension>
E/flutter (11289): #4 _JustAudioBackgroundPlugin.setup (package:just_audio_background/just_audio_background.dart:97:21)
E/flutter (11289): <asynchronous suspension>
E/flutter (11289): #5 JustAudioBackground.init (package:just_audio_background/just_audio_background.dart:53:5)
E/flutter (11289): <asynchronous suspension>
E/flutter (11289): #6 initAudioBackground (package:test_audio_project/custom_code/actions/init_audio_background.dart:13:3)
E/flutter (11289): <asynchronous suspension>
E/flutter (11289): #7 main (package:test_audio_project/main.dart:19:3)
E/flutter (11289): <asynchronous suspension>
E/flutter (11289):
Syncing files to device sdk gphone64 arm64... 60ms
And the app hangs with the loading screen...