Python for Android Tutorial #4 – Debugging
This is the fourth post about mobile development with Python.
It’s a short tutorial, just to help you to understand and learn how to work with Python for Mobile.
In this post you will see how export your Kivy project to Android Studio, use the logcat and debug your application.
I - About the Tutorials
I’ll show you how to use each mobile API, like compass, camera, sensors, sound, and others. After the API, we will start to test some Python libs, as PyGame and OpenCV. I’m using Android with buildozer, but major part are compatible with iOS as well.
|Get updates||Follow @aron-bordin|
II - Index
- Tutorial #1 - Accelerometer
- Tutorial #2 - Camera
- Tutorial #3 - Kivy Designer
- Tutorial #4 - Debug
- Tutorial #5 - Android and iOS game with Python
- Tutorial #6 - Reading and saving user data
- Tutorial #7 - Use Android classes with PyJNIus
III - About this tutorial
This is a really short tutorial, we’ll have no code on it.
Some users experienced some difficult to find errors with Kivy applications. Sometimes it’s not possible to test the app on your desktop, so may not be so easy to fix bugs on the code.
Here you’ll see how to open your project with Android Studio to debug it. Unfortunately it’s not possible to set breakpoints in your Python code, but using Android Studio can be easier to find errors.
Method 1 - Using the logcat
First, build and run your project in your Android device. Open the Android Studio and the logcat panel.
In this window, you check which line you are getting errors, filter the output by log levels and more.
Method 2 - Debugging the Java code
Assuming that you already have a buildozer project running and Android Studio installed, open you Android Studio and click in the menu File -> Import Project.
Navigate to your kivy project, then open the folder located at .buildozer/android/platform/python-for-android/dist/[project name]/
Just make sure to click on the button to see hidden folders. Just click next and finish. Now you can just run you app on Android, and you get any error, it will be displayed in the logcat. You can open some Java files related to your project and if necessary, debug them.
Method 3 - adb, buildozer and Kivy Launcher