The plugin does not yet support the android embedding v2, which is now part of flutter stable as of 2.5.0 afaik.
This prompts a warning when building an app that has this lib as dependency.
I had issues opening the project using android studio, due to issues with environment and .idea files. I thus created a new plugin using the latest version flutter cli (stable 2.5.0), compared it to the plugin and accordingly changed the files (mostly build.gradle files and the .idea files). With the changed files it is now possible to open the project as recommended by the official guide, by opening the `/background_location/example/android/build.gradle file.
Implementing FlutterPlugin
The new FlutterPlugin interface requires methods for when the plugin is attached/detached from the FlutterEngine. This replaces the old registerWith(registrar) functionality, as the FlutterBinding received when attaching, contains the applicationContext and messenger, that was previously obtained from the registrar.
The guide recommends maintaining backwards compatibility to the v1 embedding, by leaving the registerWith method and use a private function which can be used by both onAttachedToEngine and registerWith. I took some inspiration from other similar libraries and did this by moving the code inside the BackgroundLocationPlugin to a seperate class called BackgroundLocationService.
Implementing ActivityAware
The ActivityAware interface requires methods for when an activity is attached/detached for various reasons and is also the starting point for doing UI related stuff, such as asking/checking for permissions. On detachment, the LocationUpdateService ~ ForegroundService, if running, is stopped.
Some refactoring
Most of the other changes are just small refactorings:
Moving logic from the plugin class to a seperate service class
Updating the preference login in Utils.kt to not use deprecated functionalities
Updating the various Manifests, to comply with signal v2 embedding
Fix a typo in the repo from backgeound to background
Add some documentation to methods and fields
I am by no means a Kotlin or Native Android expert, so please excuse me, if I made some egregious style/code guideline mistakes :)
edit: Also, if you could check that everything still works as you intended it, would be nice. I did test it on my device, and it seemed to work.
This is PR is a fix for #113
Reason
The plugin does not yet support the android embedding v2, which is now part of flutter stable as of 2.5.0 afaik. This prompts a warning when building an app that has this lib as dependency.
What was done
I followed the guide from the offical flutter website and also the guide for upgrading pre 1.12 projects.
Refactoring .idea files
I had issues opening the project using android studio, due to issues with environment and .idea files. I thus created a new plugin using the latest version flutter cli (stable 2.5.0), compared it to the plugin and accordingly changed the files (mostly build.gradle files and the .idea files). With the changed files it is now possible to open the project as recommended by the official guide, by opening the `/background_location/example/android/build.gradle file.
Implementing
FlutterPlugin
The new
FlutterPlugin
interface requires methods for when the plugin is attached/detached from theFlutterEngine
. This replaces the oldregisterWith(registrar)
functionality, as theFlutterBinding
received when attaching, contains the applicationContext and messenger, that was previously obtained from the registrar.The guide recommends maintaining backwards compatibility to the v1 embedding, by leaving the
registerWith
method and use a private function which can be used by bothonAttachedToEngine
andregisterWith
. I took some inspiration from other similar libraries and did this by moving the code inside theBackgroundLocationPlugin
to a seperate class calledBackgroundLocationService
.Implementing
ActivityAware
The
ActivityAware
interface requires methods for when an activity is attached/detached for various reasons and is also the starting point for doing UI related stuff, such as asking/checking for permissions. On detachment, theLocationUpdateService
~ ForegroundService, if running, is stopped.Some refactoring
Most of the other changes are just small refactorings:
Utils.kt
to not use deprecated functionalitiesbackgeound
tobackground
I am by no means a Kotlin or Native Android expert, so please excuse me, if I made some egregious style/code guideline mistakes :)
edit: Also, if you could check that everything still works as you intended it, would be nice. I did test it on my device, and it seemed to work.