Sunday, November 18, 2012

Pygame Subset For Android


My student recently bought an Android 2.2 smartphone on eBay for $40.  It's quite a good deal.  The phone is unlocked and can run games from GooglePlay as well as custom games.

I spent about an hour today teaching a lesson using Pygame Subset for Android.  Wow, talk about big bang for the buck.  By the end of an hour, my student was running a native Android app on his phone completely from a blank text editor.  The app has working animation, touchscreen interaction, and hard-buttons.

Since I was completely new to Android development, I ran into a small problem building the project with Ant.

When I ran the example build from the Pygame Subset for Android, I got an error message when the script ran Ant.

~/$ android.py build mygame install release

 

Initially, I spent some time trying to create a build.xml file.   This led to a dead end.

The solution is to look at the Target id, android-8.

In the android-sdk directory, you need to have the android-8 platform listed in the platforms directory.


ubuntu-desktop:~/Documents/python/pgs4a-0.9.4/android-sdk$ ls platforms/
android-17  android-8
ubuntu-desktop:~/Documents/python/pgs4a-0.9.4/android-sdk$ 

If you don't have this platform, and you probably won't by default, run the android program within the android-sdk/tools directory.

The reason this wasn't immediately obvious to me is that the error message for the missing android-8 target was at the top of the screen output and the build.xml error message was at the bottom.  I should have read the error messages closely, starting at the top of the output.

run
  $ ./android --help 

for help or

  $ ./android update sdk 

to install API-8, Android 2.2 platform support.








7 comments:

  1. Okay, awesome post. But how do I set this thing so it uses the later API's? Is there a setting txt file?

    ReplyDelete
    Replies
    1. I haven't tried this, but you may want to Google on ant.properties:

      Target_ID – corresponds to the Android platform library version used for building. The list of available libraries can be seen by executing the command “android list targets”

      I think that the android tools will create the ant.properties file for you. See my project.properties below and note the "target=android-8" line

      Good luck. this pgs4a stuff is super fun. very rewarding games for minimal effort.

      $ less project.properties

      # This file is automatically generated by Android Tools.
      # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
      #
      # This file must be checked in Version Control Systems.
      #
      # To customize properties used by the Ant build system edit
      # "ant.properties", and override values to adapt the script to your
      # project structure.
      #
      # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
      #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

      # Project target.
      target=android-8
      project.properties (END)

      Delete
    2. I took your advice, unfortunately, I cannot, by all means get it to work. I settled back to just the default api. But here's the super crazy part: when I compile it, it just gets to the point where it says "there was a problem with ant"
      "the build failed"
      No further errors were listed, not even at the beginning was there a "build.xml cannot be found?"

      Do you have any tutorials that you followed that is very friendly to kids? I would very much appreciate it if you gave me a link.

      Delete
    3. Oh, and I'm using windows by the way. However, I can use kubuntu if I wanted to though.

      Delete
  2. Norton, wow sorry to hear about your problem. If you post the error messages to this forum, you may be able to get some additional ideas:

    http://pygame.renpy.org/forum/

    I've been planning to make more tutorials on installing Pygame Subset for Android in the future. I think this is a tricky part.

    When I was in Hawaii on vacation a few months ago, my son used a MacBook for his lessons and we ran into a problem with the build because of the key signatures. I was able to help him out and get it to work, but it took a while.

    I've only been using the 2.2 API since it meets my needs. Remember that pgs4a can only handle a subset of Android and Pygame calls.

    In the meantime, definitely check out the forum and post the output of the build there. Hopefully, there is more information on the problem with Ant. I

    Unfortunately, I don't have any experience with Windows.

    ReplyDelete
  3. Hello Craig,
    I have just started with Pgs4a and got my first simple app running on AVD,
    Furthermore, I am looking for tutorials related to open an url in ur android device via code written in pygame/python.
    and also
    opening up messaging with some body text through codes.

    Any Help or idea??
    thanks for ur wonerfull tutorials..

    ReplyDelete
  4. You can change Android API changing local.properties and adding the following line:
    target=android-17

    ReplyDelete