Skip to content

Build fails: ProxyLifecycleProvider override error - 'lifecycle' overrides nothing due to LifecycleOwner API mismatch #90

@9jorgeLuis

Description

@9jorgeLuis

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

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

  1. Create a Flutter project
  2. Add background_location_tracker: ^1.6.0 as a dependency
  3. Ensure your project uses AndroidX and compileSdk 35
  4. Run flutter run or build the app
  5. 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions