icapps / flutter-background-location-tracker

Flutter background location tracker plugin. (Android / iOS)
MIT License
31 stars 32 forks source link

Error: Cannot Access 'lifecycle': Private in 'ProxyLifecycleProvider' in background_location_tracker Plugin #77

Open majmalmdt opened 2 months ago

majmalmdt commented 2 months ago

I encountered multiple errors while trying to build my Flutter project using the background_location_tracker plugin. The errors are related to accessing and overriding the lifecycle property and method within the plugin's Kotlin code.

Steps to Reproduce:

Add the background_location_tracker plugin to the pubspec.yaml file. Attempt to build the Flutter project. Observe the build errors related to the lifecycle property in the BackgroundLocationTrackerPlugin.kt file.

Error Messages:

e: file:///C:/Users/majma/AppData/Local/Pub/Cache/hosted/pub.dev/background_location_tracker-1.4.3/android/src/main/kotlin/com/icapps/background_location_tracker/BackgroundLocationTrackerPlugin.kt:90:50 Cannot access 'lifecycle': it is private in 'ProxyLifecycleProvider'

e: file:///C:/Users/majma/AppData/Local/Pub/Cache/hosted/pub.dev/background_location_tracker-1.4.3/android/src/main/kotlin/com/icapps/background_location_tracker/BackgroundLocationTrackerPlugin.kt:115:9 Cannot weaken access privilege 'public' for 'lifecycle' in 'LifecycleOwner'

e: file:///C:/Users/majma/AppData/Local/Pub/Cache/hosted/pub.dev/background_location_tracker-1.4.3/android/src/main/kotlin/com/icapps/background_location_tracker/BackgroundLocationTrackerPlugin.kt:115:21 'lifecycle' hides member of supertype 'LifecycleOwner' and needs 'override' modifier

e: file:///C:/Users/majma/AppData/Local/Pub/Cache/hosted/pub.dev/background_location_tracker-1.4.3/android/src/main/kotlin/com/icapps/background_location_tracker/BackgroundLocationTrackerPlugin.kt:167:9 'getLifecycle' overrides nothing

Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Environment:

Flutter Version: [Your Flutter version] Dart Version: [Your Dart version] Plugin Version: background_location_tracker 1.4.3 Android SDK Version: [Your Android SDK version] Kotlin Version: [Your Kotlin version] Possible Causes and Suggestions:

Private Access to lifecycle:

The lifecycle property in ProxyLifecycleProvider is private, leading to access errors. Access Modifier Conflict:

The code is trying to change the access modifier of lifecycle from public, which is not allowed. Missing override Modifier:

The lifecycle property needs an override modifier when overriding a superclass member. getLifecycle Method:

The getLifecycle() method seems to be incorrectly marked as override without a matching method in the superclass. Suggested Fixes:

Verify the correct access level of the lifecycle property and ensure that the override keyword is used where necessary. Make sure the plugin is compatible with the current versions of Flutter, Dart, and AndroidX. Update the plugin if a newer version is available that addresses these issues. Consider refactoring the Kotlin code to properly handle the lifecycle property. Additional Context:

The errors started appearing after upgrading to the latest version of Flutter and AndroidX. If the plugin is outdated or incompatible with the new versions, a fix or update may be necessary.

Jeferson505 commented 1 month ago

Same here!

@vanlooverenkoen @DimmyMaenhout @NicolaVerbeeck @jorre127 @ikbendewilliam @virtualmarc @ashwin-dailype @resfandiari

@jeroentrappers @JasperVercammen

Any of you guys knows how to fix it?

Jeferson505 commented 1 month ago

@majmalmdt I made a possible solution on my fork. I'm doing tests right now and after that I'll do a PR.

Jeferson505 commented 1 month ago

Feel free to look the code's modifications and try it if you want. The example project is not running. There is an issue related with the flutter_local_notifications plugin I ignored. However, is possible to try it on others projects changing the plugin's import on pubspec.yaml file this way:

background_location_tracker:
    your/path/to/the/flutter-background-location-tracker

My fork can be accessed here

ashwinkey04 commented 1 week ago

Thanks @Jeferson505, your fork works perfectly fine for me. If it is okay with you letting others mention your fork directly in their project, then they could use this in their pubspec

dependencies:
  background_location_tracker:
    git:
      url: https://github.com/jeferson505/flutter-background-location-tracker.git