I’m using flutter_background_service: ^5.0.7
along with geolocator: ^11.0.0
to start a background service and track the user location.
on android 14 I’m the application crashed when its attempting to start the service
i have included the required permissions and follows the flutter_background_service: ^5.0.7
documentation but still nothing.
the exception that I’m encountering
E/AndroidRuntime(20806): FATAL EXCEPTION: main
E/AndroidRuntime(20806): Process: com.example.procss, PID: 20806
E/AndroidRuntime(20806): java.lang.RuntimeException: Unable to create service id.flutter.flutter_background_service.BackgroundService: java.lang.IllegalArgumentException: foregroundServiceType 0x00000008 is not a subset of foregroundServiceType attribute 0x00000000 in service element of manifest file
E/AndroidRuntime(20806): at android.app.ActivityThread.handleCreateService(ActivityThread.java:5111)
E/AndroidRuntime(20806): at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
E/AndroidRuntime(20806): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2506)
E/AndroidRuntime(20806): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(20806): at android.os.Looper.loopOnce(Looper.java:230)
E/AndroidRuntime(20806): at android.os.Looper.loop(Looper.java:319)
E/AndroidRuntime(20806): at android.app.ActivityThread.main(ActivityThread.java:8893)
E/AndroidRuntime(20806): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(20806): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
E/AndroidRuntime(20806): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
E/AndroidRuntime(20806): Caused by: java.lang.IllegalArgumentException: foregroundServiceType 0x00000008 is not a subset of foregroundServiceType attribute 0x00000000 in service element of manifest file
E/AndroidRuntime(20806): at android.os.Parcel.createExceptionOrNull(Parcel.java:3073)
E/AndroidRuntime(20806): at android.os.Parcel.createException(Parcel.java:3053)
E/AndroidRuntime(20806): at android.os.Parcel.readException(Parcel.java:3036)
E/AndroidRuntime(20806): at android.os.Parcel.readException(Parcel.java:2978)
E/AndroidRuntime(20806): at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7214)
E/AndroidRuntime(20806): at android.app.Service.startForeground(Service.java:862)
E/AndroidRuntime(20806): at androidx.core.app.ServiceCompat$Api34Impl.startForeground(ServiceCompat.java:241)
E/AndroidRuntime(20806): at androidx.core.app.ServiceCompat.startForeground(ServiceCompat.java:172)
E/AndroidRuntime(20806): at id.flutter.flutter_background_service.BackgroundService.updateNotificationInfo(BackgroundService.java:175)
E/AndroidRuntime(20806): at id.flutter.flutter_background_service.BackgroundService.onCreate(BackgroundService.java:107)
E/AndroidRuntime(20806): at android.app.ActivityThread.handleCreateService(ActivityThread.java:5098)
E/AndroidRuntime(20806): ... 9 more
E/AndroidRuntime(20806): Caused by: android.os.RemoteException: Remote stack trace:
E/AndroidRuntime(20806): at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:2171)
E/AndroidRuntime(20806): at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1785)
E/AndroidRuntime(20806): at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:15850)
E/AndroidRuntime(20806): at android.app.IActivityManager$Stub.onTransact$setServiceForeground$(IActivityManager.java:11873)
E/AndroidRuntime(20806): at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3499)
E/AndroidRuntime(20806):
here is my permissions and the service in the manifest file:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<service
android:name=".flutter_background_service.BackgroundService"
android:foregroundServiceType="location"
/>
also i have updated my android/build.gradle file :
ext.kotlin_version = '1.8.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
gradle-wrapper.properties
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip
and finally main.dart
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,
initialNotificationTitle: 'Background Service',
initialNotificationContent: 'Location Service Running',
///specifiying the service type
foregroundServiceType: AndroidForegroundType.location,
foregroundServiceNotificationId: 888
),
iosConfiguration: IosConfiguration(
// auto start service
autoStart: false,
// this will be executed when app is in foreground in separated isolate
onForeground: onStart,
///Todo
// you have to enable background fetch capability on xcode project
//onBackground: onIosBackground,
),
); ````