Python for Android Tutorial #4 – Debugging

Welcome!

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.

Must read:

Source code

Get updates Follow @aron-bordin
Star it: Star
Contribute: Fork
Download: Download

II - Index

Available tutorials:

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.

Android Studio logcat

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.

Python for Android Source code

Method 3 - adb, buildozer and Kivy Launcher

Please, read about it here: http://kivy.org/docs/guide/android.html#debugging-your-application-on-the-android-platform

That’s it,

See you.

Aron Bordin

Aron Bordin
Computer Science Student and AI researcher. Always coding something fun :)

[Tutorial] Developing Android Background Services

### Welcome!In this post, I'll show you how to develop background services on Android Studio. We'll see two type of services: `Service` a...… Continue reading