Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
majmalmdt opened this issue Aug 29, 2024 · 4 comments

Comments

@majmalmdt
Copy link

majmalmdt commented Aug 29, 2024

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
Copy link
Contributor

@Jeferson505
Copy link
Contributor

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

@Jeferson505
Copy link
Contributor

Jeferson505 commented Sep 5, 2024

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants