Sunday, September 21, 2014

Pygame on Android - What to Do When Your Android App Dies Soon After Startup

You can use adb to get console error messages and print statement output from your pygame app on Android phones.  One of the most frustrating thing for beginners to pygame on Android is when the app runs fine on their desktop, but dies soon after startup on their Android phone.  Usually, you click on the app, the splash screen comes up, then the Android app silently dies.  Unless you're using adb, corrently you could be stuck.

With the usb cable connected between your phone and desktop, run 

adb logcat |grep python

Here's the output I got today.

I/python  (  580): 
Opening APK '/data/app/org.pychildren.surfsc-2.apk'I/python  (  580): 
Traceback (most recent call last):I/python  (  580):   
File "main.py", line 323, in <module>I/python  (  580):     
main()I/python  (  580):   
File "main.py", line 296, in mainI/python  (  580):     
pprint.pprint(weather.w_dict)I/python  (  580): 
NameError: global name 'pprint' is not definedI/python  (  580): 
Python for android ended.I/ActivityManager( 7163): Process org.pychildren.surfsc:python (pid 580) has died.

It is clear that there's a problem with the pprint.pprint statement that I was using to display the Python dictionary of weather data.  It even gives me the line number in my source code.  I simply commented out the line and the app started working again on my Android phone.



I've added basic weather information to my version.  My son's version has a cleaner interface and better colors.


No comments:

Post a Comment