-
Notifications
You must be signed in to change notification settings - Fork 55
Description
Describe the bug
When trying to build my Flutter project using background_location_tracker version 1.6.0, I encounter the following compilation error:
e: file:///Users/user/.pub-cache/hosted/pub.dev/background_location_tracker-1.6.0/android/src/main/kotlin/com/icapps/background_location_tracker/BackgroundLocationTrackerPlugin.kt:98:13
Class 'BackgroundLocationTrackerPlugin.ProxyLifecycleProvider' is not abstract and does not implement abstract member: fun getLifecycle(): Lifecycle
e: file:///Users/user/.pub-cache/hosted/pub.dev/background_location_tracker-1.6.0/android/src/main/kotlin/com/icapps/background_location_tracker/BackgroundLocationTrackerPlugin.kt:99:9
'lifecycle' overrides nothing.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':background_location_tracker:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
> Compilation error. See log for more details
Root cause
This error occurs because ProxyLifecycleProvider in the plugin uses:
override val lifecycle = LifecycleRegistry(this)This syntax requires the modern LifecycleOwner API, which defines:
val lifecycle: LifecycleHowever, in older versions of androidx.lifecycle (e.g. 2.2.0 and below), the interface instead defines:
fun getLifecycle(): LifecycleTherefore, Kotlin throws a compilation error because val lifecycle doesn't override anything in the older interface.
Steps to reproduce
- Create a Flutter project
- Add
background_location_tracker: ^1.6.0as a dependency - Ensure your project uses AndroidX and compileSdk 35
- Run
flutter runor build the app - Observe the compilation error
Possible solutions
- Explicitly declare modern lifecycle dependencies (e.g.
androidx.lifecycle:lifecycle-runtime-ktx:2.6.2) inside the plugin’sbuild.gradle. - Adjust the plugin code to support older lifecycle APIs, or clearly document that a minimum lifecycle version is required.
- Document this issue for developers who might experience conflicts with older lifecycle versions brought in transitively by other dependencies.
Environment
- background_location_tracker: 1.6.0
- Kotlin: 1.9.10
- Gradle plugin: 8.3.2
- compileSdkVersion: 35
- Flutter version: 3.22.3
Additional context
Even after forcing newer lifecycle versions in my app’s build.gradle, the plugin still fails to compile because its own build.gradle does not explicitly declare modern lifecycle dependencies. It relies on whatever version is resolved transitively in the app's build environment.
Please advise on the best way to resolve this or consider updating the plugin to declare explicit lifecycle dependencies compatible with the newer API.
Thanks for maintaining this plugin!