2
votes

I want to get location updates in background when app is minimized. So I created a demo Flutter application with a service in native Android which I can run in foreground to get the continuous location updates for application and it is working fine as my expectation it is updating locations in notifications (for test).

Then I tried to implement same service with actual Flutter application with same service mentioned in manifest file same as demo application but my application is crashing on starting so I can't debug and in addition to that I don't get any error in building.

My main Flutter application is working fine without the location service implementation so only issues is after implementation it causes crashing.

What could be the issue and solution for this problem or how can I find out what is the problem?

I am doing same thing in original Flutter application same as in this dart code of demo application. How can I investigate this problem?

1
I have removed your secondary question - Stack Overflow is quite strict about wanting there to be only one question per post. I suspect the question now is still rather broad, given how much code is in it. Can you put this into version control, and trim away code in order to make a smaller example? Not only would you be more likely to get the help that you need, but perhaps you will find the cause of the error, by narrowing it down to a specific line. - halfer
Application is built and installed on the device as well and just crashing when it try to launch the application on device without any error log and stacktrace. so I could not find it or debug it that's why i thought to add my whole code which will be helpful to see them why it will be crashing yeah i will upload my demo code to github and provide a link of project. Thanks. - Code Runner
That would be still too broad, and I wonder if readers are not likely to try running that code in their development environments. Can you achieve the same crash when the code is cut down in size? - halfer
please if anyone can help me solve this problem. stackoverflow.com/questions/64785847/… - khoutech

1 Answers

0
votes

I am adding my answer regarding the question mentioned above.

in my case, it was not a foreground service which was crashing application but the issue was that As the flutter is growing framework, We get lot of updates & changes. With one of those Flutter update, Flutter updated plugin registration process for app on native side so some plugin with older version dependencies doesn't get registered with app as flutter doesn't support FlutterView(deprecated) anymore.

Note: Always make sure your plugin dependencies are updated to latest version of its dependencies in pubspec.yaml.

For me, My main application and demo application created for foreground was working according to my expectation but when I merge them it was crashing because camera plugin dependency version was too old. Second thing you can do is which can also reduce chances of error due to androidx compatibilty as well. Though, it is not too tough to do in old app as well.

Note : Create new flutter project and move your all dart code to new application.

Please be careful while doing this option.

-- Don't forget to add permissions in manifest files which you are accessing in app.
-- Don't forget to add assets and resources used on native side if you have added or changed.
-- Don't forget to set version according to version of old app.
-- Don't forget to make changes in your gradle files if any of app dependencies use that configurations like minimum sdk, targetSdk, etc... (if it applies in your case) 

If you don't find this useful you can run your android side code in android studio and can find out what is the problem by debugging that code and fix it. Thanks