Emerson MX

Developer Journal

Difficulties in Building a Pygame Game for Android

Recently, I was taking an Android course and got the urge to port a game I had made in Python to Android. It wasn't difficult to find articles on the subject, but one common theme was that to run Python on Android, you needed Buildozer. And so, my saga began.

I spent two days wrestling with Buildozer to generate an APK. On the first day, I decided to create a simple example to test the build. After encountering several errors, I realized it would be easier to run Buildozer in Docker. Luckily, there was already a Dockerfile in the Buildozer project for this purpose. With a few adaptations, I had it up and running on my machine.

The next step was configuring Buildozer for the build, which led me to dive deep into Python for Android (p4a). After spending a lot of time running builds, reading documentation, and analyzing error logs, I concluded that it would be better to create a p4a recipe for pygame-ce and see how it worked.

In the end, the pygame-ce recipe worked, and the errors stopped. The next step was to see if the generated APK would run on Android. So, I opened the Android emulator, installed the APK, and... nothing. The game opened and then immediately closed. Checking the Logcat, I realized I needed to tweak the Buildozer configuration to generate an APK for x86_64 and also set the correct SDK version. After doing that, I reinstalled the APK, and the game finally opened! 🤲

After all this struggle, I decided to share the knowledge I gained with the Pygame community. However, I also concluded that it might not be worth porting my Python game to Android 🙁.