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

App is crashing after updating targetsdkversion to 34 #479

Open
leadsmanager opened this issue Sep 2, 2024 · 6 comments
Open

App is crashing after updating targetsdkversion to 34 #479

leadsmanager opened this issue Sep 2, 2024 · 6 comments

Comments

@leadsmanager
Copy link

E/AndroidRuntime(27349): FATAL EXCEPTION: main
E/AndroidRuntime(27349): Process: com.leads.manager, PID: 27349
E/AndroidRuntime(27349): android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{1c421a4 u0 com.leads.manager/id.flutter.flutter_background_service.BackgroundService}
E/AndroidRuntime(27349): at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2292)
E/AndroidRuntime(27349): at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2263)
E/AndroidRuntime(27349): at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
E/AndroidRuntime(27349): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2561)
E/AndroidRuntime(27349): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(27349): at android.os.Looper.loopOnce(Looper.java:257)
E/AndroidRuntime(27349): at android.os.Looper.loop(Looper.java:368)
E/AndroidRuntime(27349): at android.app.ActivityThread.main(ActivityThread.java:8839)
E/AndroidRuntime(27349): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(27349): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572)
E/AndroidRuntime(27349): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
E/AndroidRuntime(27349): Caused by: android.app.StackTrace: Last startServiceCommon() call for this service was made here
E/AndroidRuntime(27349): at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1992)
E/AndroidRuntime(27349): at android.app.ContextImpl.startForegroundService(ContextImpl.java:1936)
E/AndroidRuntime(27349): at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:840)
E/AndroidRuntime(27349): at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java:1128)
E/AndroidRuntime(27349): at androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:700)
E/AndroidRuntime(27349): at id.flutter.flutter_background_service.FlutterBackgroundServicePlugin.start(FlutterBackgroundServicePlugin.java:83)
E/AndroidRuntime(27349): at id.flutter.flutter_background_service.FlutterBackgroundServicePlugin.onMethodCall(FlutterBackgroundServicePlugin.java:127)
E/AndroidRuntime(27349): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/AndroidRuntime(27349): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/AndroidRuntime(27349): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/AndroidRuntime(27349): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/AndroidRuntime(27349): at android.os.Handler.handleCallback(Handler.java:958)
E/AndroidRuntime(27349): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(27349): ... 6 more

@pratikcronabit
Copy link

pratikcronabit commented Sep 18, 2024

I have one solution.

1)- Please make sure your project already use the version of gradle tools below:

in android/build.gradle classpath 'com.android.tools.build:gradle:7.4.2'
in android/build.gradle ext.kotlin_version = '1.8.10'
in android/gradle/wrapper/gradle-wrapper.properties distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip

2)- Add the corresponding permission to your android/app/src/main/AndroidManifest.xml file:

Add Permission

<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_..." />

Ex.. :-, if you picked 'location', use 'android.permission.FOREGROUND_SERVICE_LOCATION' ............Read more https://developer.android.com/about/versions/14/changes/fgs-types-required

    <service
        android:name="id.flutter.flutter_background_service.BackgroundService"
        android:foregroundServiceType="WhatForegroundServiceTypeDoYouWant"
    />

That is work for me.
Thanks.

@daviddagan
Copy link

it didnt work for me and i did all you asked, I do trying to fetch GPS from Gelocatoer plugin in foreground tho

@qafoori
Copy link

qafoori commented Sep 28, 2024

any updates to this? same here

@DriesVandb
Copy link

We are experiencing the same issue. We even commented all code in the task to exclude any issues with the code.

@AnkitSuda
Copy link

Make sure you declare permissions as specified in https://developer.android.com/develop/background-work/services/fg-service-types. Declaring correct permission fixed this issue in my app.

example: if you use foregroundServiceType="specialUse" you must declare this permission in manifest
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />

@zamargab
Copy link

zamargab commented Oct 25, 2024

For anyone havving this issue, follow this steps.

Add to Android Manifest.

 <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />

<service
        android:name="id.flutter.flutter_background_service.BackgroundService"
        android:foregroundServiceType="specialUse"
    />
when configuring the package, add .
` foregroundServiceTypes: [AndroidForegroundType.specialUse],`

Example below.


 await service.configure(
    androidConfiguration: AndroidConfiguration(
      // this will be executed when app is in foreground or background in separated isolate
      onStart: onStart,
      // auto start service
      autoStart: false,
      isForegroundMode: true,
      foregroundServiceTypes: [AndroidForegroundType.specialUse],
      // foregroundServiceTypes: [AndroidForegroundType.specialUse],
      notificationChannelId: 'my_foreground',
      initialNotificationTitle: 'AWESOME SERVICE',
      initialNotificationContent: 'Initializing',
      foregroundServiceNotificationId: 888,
    ),
    iosConfiguration: IosConfiguration(
      // auto start service
      autoStart: false,

      // this will be executed when app is in foreground in separated isolate
      onForeground: onStart,

      // you have to enable background fetch capability on xcode project
      onBackground: onIosBackground,
    ),
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants