Native code debugging and external library awareness in Android Studio

683 views
Skip to first unread message

Edmund Tam

unread,
Mar 27, 2018, 10:43:47 AM3/27/18
to Flutter Dev
Hi,

I just started exploring the platform channel feature of Flutter. After successfully retrieving the remaining battery level, I wanted to go further to integrate an external library. To be specific, I wanted to integrate the PayPal (now Braintree) SDK to native code and call it from Flutter. I only tried doing this on Android, I thought it would be less difficult as I could use the same IDE (Android Studio) to write and test the code on both sides.

So I added the dependency to build.gradle and added some code to MainActivity.java. Then I experienced two issues:

1) The SDK I added in build.gradle can be downloaded successfully. However, Android Studio seems not aware of the new external dependency, thus I could not take advantage of code hinting nor import completion, as the symbols of the SDK library could not be resolved. This makes development painful. I would like to know if it is just me or a known issue - I am actually quite surprised when I found no similar report of this issue.

2) I am unable to set breakpoints on native (Java) code. This is understandable, as it's now Flutter who is running the game. But still it's inconvenient. I would like to know if there's a way to debug native code on a Flutter application. Now I can only think of creating a separate native project, write (and debug) the code, and copy it back to Flutter when done.

Thanks again.

Edmund

Edmund Tam

unread,
Mar 27, 2018, 11:44:21 PM3/27/18
to Flutter Dev
Sorry for answering myself, but I just found the answer. To edit native code in Android Studio, just open the Flutter project, right click the android directory, and select Flutter -> Open Android module in Android Studio. Then the project will be switched to Android development mode, and type hinting and breakpoint debugging will work for Java code in this code.

Edmund

Edmund Tam於 2018年3月27日星期二 UTC+8下午10時43分47秒寫道:

Andreas Sumerauer

unread,
Oct 16, 2018, 9:01:56 AM10/16/18
to Flutter Dev
Thanks so much. You saved my day!

Prasath Babu

unread,
Aug 27, 2019, 7:44:08 AM8/27/19
to Flutter Development (flutter-dev)

Hi Edmund,

Here i facing same issue, kindly help me on this if you got solution for issue 1.
Reply all
Reply to author
Forward
0 new messages