ekasetiawans / flutter_background_service

261 stars 180 forks source link

`flutter_background_service_android` threw an error #375

Open Ellynnn opened 10 months ago

Ellynnn commented 10 months ago

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?

ff225 commented 10 months ago

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 :)

pradhansoubhagya commented 10 months ago

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

bahman2000 commented 9 months ago

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)

#1 FlutterBackgroundServiceAndroid.isServiceRunning (package:flutter_background_service_android/flutter_background_service_android.dart:114:18) #2 GeneralAppController.startBackgroundService (package:sample_project/app/general_app_controller.dart:130:29) `
AbdullahAli1993 commented 9 months ago

Same here, any updates?

0xharkirat commented 8 months ago

@ekasetiawans same issue, any updates?

0xharkirat commented 8 months ago

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

ekasetiawans commented 8 months ago

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.

0xharkirat commented 8 months ago

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

ekasetiawans commented 8 months ago

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.

BehroozBvk commented 8 months ago

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
liasica commented 8 months ago

Same issue

daewookoh commented 8 months ago

same issue

a1ssat commented 8 months ago

same here

diegohzea commented 8 months ago

same issue, any workaround?

hendyandrianto commented 8 months ago

same issue

maftuh-sangiba commented 8 months ago

same issue

cs-hyunseo commented 8 months ago

same issue

amotalles commented 8 months ago

same issue

AwaisQazii commented 8 months ago

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

Ianmuhia commented 8 months ago

same issue as @AwaisQazii on android 12

elbeekk commented 8 months ago

same issue

yanllllk commented 7 months ago

@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?

MunibullahShah commented 7 months ago

I got same issue on 5.0.5

ktkk commented 7 months ago

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

AvidanGC commented 7 months ago

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

pratik-7span commented 7 months ago

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.

omarmaamoun179 commented 7 months ago

same issue and soultion?

pishguy commented 7 months ago

i have the same issue

PriyanshuNatani commented 5 months ago

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.

vinz-mehra commented 2 months ago

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

TarunPal3551 commented 2 months ago

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

[✓] Flutter (Channel stable, 3.19.4, on macOS 14.4.1 23E224 darwin-x64, locale en-IN) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [!] Xcode - develop for iOS and macOS ✗ Xcode installation is incomplete; a full installation is necessary for iOS and macOS development. Download at: https://developer.apple.com/xcode/ Or install Xcode via the App Store. Once installed, run: sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer sudo xcodebuild -runFirstLaunch [✓] Chrome - develop for the web [✓] Android Studio (version 2023.3) [✓] VS Code (version 1.89.1) [✓] Connected device (3 available) [✓] Network resources

jhoneferreiradev commented 1 month ago

@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?

Me ajudou! Obrigado @yanllllk !

shinewanna commented 1 week ago

same issue