Issue
I'm building a flutter app which uses a third party plugin.
The plugin has a bug in its android java code.
The problem is that I'm having trouble finding documentation on how to setup a development environment to debug the plugin from within my app.
I should note that the original developer can't reproduce the bug and hence I need to get it running within my app.
The instructions I've found so far involve having to build an apk, but this is time consuming and seems like its shouldn't be necessary.
I'm an experience java and dart programmer so I'm not having trouble with the basics (i.e. I have Android studio and vs code running and I can debug the plugin using its own sample code).
This is the process I have so far:
git clone the plugin to my local system.
Within my application add an override in my apps pubspec.yaml to
import the plugin from my local system.
dependency_overrides:
flutter_sound:
path: ../flutter_sound
Build my app so we can open in android studio.
Note: I had to delete my .pub-cache/hosted folder and then run
'flutter pub get' as some older (unused?) packages seem to stop
the build. I also ensure that I had the latest packages for
every package I was using.
flutter build apk
In android studio
Import my app project
- open the android project contained with my app project folder.
e.g.
~/git/app/android
Wait for the gradle build to complete.
Start the android studio debugger and select a simulator.
Open the 'Android Monitor' tab at the bottom of Android Studio.
Solution
So I managed to get this working.
There may be some steps superfluous to the process but I've included them all here as I've not had time to go back and work out which ones aren't required.
Note: a plugin is always contained within a dart 'package'.
git clone the third party package (flutter_sound in this example) to your local system.
Within your application's pubspec.yaml add an override to import the package from your local system.
dependency_overrides:
flutter_sound:
path: ../flutter_sound
Update your dependencies:
pub upgrade
Build your app so we can open in android studio.
Within the apps project root dir (where your pubspec.yaml is located) run:
flutter build apk
From android studio
Import your app project
Wait for the gradle build to complete (this took a couple of minutes).
Find the 'android' folder within your application project (from within the Project panel in studio).
Right click the android folder. Select 'Flutter -> Open Android module in Android Studio'
When prompted tell Android Studio to open the Android Module in a new window.
Wait for the gradle build to complete.
Start the android studio debugger and select a emulator.
Open the 'Android Monitor' tab at the bottom of Android Studio.
You should now be able to set break points in your java code.
Good luck.
Answered By - Brett Sutton
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.