flutter_background_service icon indicating copy to clipboard operation
flutter_background_service copied to clipboard

`flutter_background_service_android` threw an error

Open Ellynnn opened this issue 1 year ago • 34 comments

Whenever I build the app, I keep getting the below line in my debug console.

flutter_background_service_android threw an error: Exception: This class should only be used in the main isolate (UI App). The app may not function as expected until you remove this plugin from pubspec.yaml

I tried removing the flutter_background_service_android package from the dependency but the same line of message still prompts. However, the app is still able to build. Can I know how to fix this?

Ellynnn avatar Oct 30 '23 04:10 Ellynnn

I had the same issue and i fixed with downgrade flutter_background_service_android to version 6.0.1.

flutter pub downgrade flutter_background_service_android

I know it is a temporary solution but better than nothing :)

ff225 avatar Oct 30 '23 13:10 ff225

Preveously it was working , but now I got same issue.

pradhansoubhagya avatar Nov 01 '23 13:11 pradhansoubhagya

I have the same problem.

Info:

flutter_background_service: ^5.0.2

bool isServiceRunning = await FlutterBackgroundService().isRunning();

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method isServiceRunning on channel id.flutter/background_service/android/method) #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:308:7) <asynchronous suspension> #1 FlutterBackgroundServiceAndroid.isServiceRunning (package:flutter_background_service_android/flutter_background_service_android.dart:114:18) <asynchronous suspension> #2 GeneralAppController.startBackgroundService (package:sample_project/app/general_app_controller.dart:130:29) <asynchronous suspension>

bahman2000 avatar Nov 05 '23 12:11 bahman2000

Same here, any updates?

AbdullahAli1993 avatar Nov 08 '23 08:11 AbdullahAli1993

@ekasetiawans same issue, any updates?

0xharkirat avatar Dec 06 '23 11:12 0xharkirat

Everyone please check pr #392 . I have proposed a solution. Cheers, Thanks.

0xharkirat avatar Dec 06 '23 12:12 0xharkirat

Its might you are accesing method from the background service isolate that only available for main isolate. For example, you starting service, from the onStart method or any api calls to the FlutterBakcgroundService class directly. You should only call apis that available for serviceInstance.

ekasetiawans avatar Dec 06 '23 17:12 ekasetiawans

But I am just running the main.dart given in package example. Still getting the same exception.

0xharkirat avatar Dec 06 '23 22:12 0xharkirat

But I am just running the main.dart given in package example. Still getting the same exception.

I have re-checked it's the example project run normally in my side.

ekasetiawans avatar Dec 07 '23 01:12 ekasetiawans

But I am just running the main.dart given in package example. Still getting the same exception.

I also have this error :

Launching lib/main.dart on Nexus 5 in debug mode...
✓  Built build/app/outputs/flutter-apk/app-debug.apk.
V/BackgroundService(26354): Starting flutter engine for background service
V/BackgroundService(26354): Service already running, using existing service
I/flutter (26354): `flutter_background_service_android` threw an error: Exception: This class should only be used in the main isolate (UI App). The app may not function as expected until you remove this plugin from pubspec.yaml

BehroozBvk avatar Dec 09 '23 10:12 BehroozBvk

Same issue

liasica avatar Dec 10 '23 09:12 liasica

same issue

daewookoh avatar Dec 12 '23 08:12 daewookoh

same here

a1ssat avatar Dec 13 '23 13:12 a1ssat

same issue, any workaround?

diegohzea avatar Dec 14 '23 01:12 diegohzea

same issue

hendyandrianto avatar Dec 15 '23 13:12 hendyandrianto

same issue

maftuh-sangiba avatar Dec 16 '23 15:12 maftuh-sangiba

same issue

cs-hyunseo avatar Dec 22 '23 04:12 cs-hyunseo

same issue

amotalles avatar Dec 24 '23 20:12 amotalles

same issue flutter_background_service_android` threw an error: This class should only be used in the main isolate (UI App). The app may not function as expected until you remove this plugin from pubspec.yaml

AwaisQazii avatar Dec 29 '23 11:12 AwaisQazii

same issue as @AwaisQazii on android 12

Ianmuhia avatar Dec 29 '23 13:12 Ianmuhia

same issue

elbeekk avatar Dec 30 '23 21:12 elbeekk

@pragma('vm:entry-point') void onStart(ServiceInstance service) async { // Only available for flutter 3.0.0 and later DartPluginRegistrant.ensureInitialized(); <<---remove this code, will not throw exceptions

// For flutter prior to version 3.0.0 // We have to register the plugin manually

SharedPreferences preferences = await SharedPreferences.getInstance(); ... }

seems run twice?

yanllllk avatar Jan 03 '24 05:01 yanllllk

I got same issue on 5.0.5

MunibullahShah avatar Jan 08 '24 14:01 MunibullahShah

I have the same issue. @yanllllk's solution seems to work but I'm not sure if it's safe to use?

ktkk avatar Jan 15 '24 10:01 ktkk

same issue flutter_background_service_android` threw an error: This class should only be used in the main isolate (UI App). The app may not function as expected until you remove this plugin from pubspec.yaml

AvidanGC avatar Jan 18 '24 07:01 AvidanGC

I am facing the same issue but when I try to Turn On the "Manage Notification" manually, It is showing me that notification as well as it is updating the data based on the interval.

Take a look it it can help you. I don't know whether I'll get any issues in the future or not.

Update: As suggested by @yanllllk I've removed that line and it's not showing that warning anymore in logs.

pratik-7span avatar Jan 18 '24 11:01 pratik-7span

same issue and soultion?

omarmaamoun179 avatar Jan 22 '24 01:01 omarmaamoun179

i have the same issue

pishguy avatar Jan 29 '24 22:01 pishguy

Just add two lines to your pubspec.yaml file:

flutter_background_service: any flutter_background_service_android: "6.0.1"

This worked for me. I know this simply downgrades the flutter_background_service_android package and adjusts flutter_background_service accordingly. However, until this issue is fixed in the future, this solution should suffice.

PriyanshuNatani avatar Mar 20 '24 09:03 PriyanshuNatani

It is breaking the background service in 6.2.3. App no longer works in the background after throwing this error Exception: This class should only be used in the main isolate (UI App)

Device - Pixel 6a

vinz-mehra avatar Jun 19 '24 20:06 vinz-mehra