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:
However, in older versions of androidx.lifecycle (e.g. 2.2.0 and below), the interface instead defines:
fun getLifecycle(): Lifecycle
Therefore, 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.0 as a dependency
- Ensure your project uses AndroidX and compileSdk 35
- Run
flutter run or 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’s build.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!
Describe the bug
When trying to build my Flutter project using
background_location_trackerversion 1.6.0, I encounter the following compilation error:Root cause
This error occurs because
ProxyLifecycleProviderin the plugin uses:This syntax requires the modern
LifecycleOwnerAPI, which defines:However, in older versions of
androidx.lifecycle(e.g. 2.2.0 and below), the interface instead defines:Therefore, Kotlin throws a compilation error because
val lifecycledoesn't override anything in the older interface.Steps to reproduce
background_location_tracker: ^1.6.0as a dependencyflutter runor build the appPossible solutions
androidx.lifecycle:lifecycle-runtime-ktx:2.6.2) inside the plugin’sbuild.gradle.Environment
Additional context
Even after forcing newer lifecycle versions in my app’s build.gradle, the plugin still fails to compile because its own
build.gradledoes 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!