5.19.2015

PTT標題前符號的意思 (轉貼)

【+】 還沒看過的文章,如果已看過 + 就會消失
【~】 就是這篇文章你已經看過,但只要是有新推文,或是原PO修了文,就會以此標記來提醒讀者說「此文章有新推文囉!」或是「此文章已被原PO修過囉!」

【M m】 這是被板主m起來的文章,也就是認為重要,不該系統清除,或者是不讓原PO刪除的標記此標記,差別只在於,大M是未讀,小m是已讀
【=】 就是m文內容有新變更,例如作者修改文章或是有人推文,看完就會變m
【!】 被版主標記起來,而此標記,為「鎖文」,通常是文章具爭議性,鎖起來,防止再戰下去也就是說,表示該篇文章不能推文、競標、回應

【S s】 被版主標記用,這標記通常是待處理、或已處理的文章,要看各板板主怎麼去使用也就是各板用途定義不同,大S是已讀,小s是未讀

 在我的最愛裡文章前的紅勾勾v是指你還沒有看過這個版上的最後一篇文章,如果看完就會消失,但有新文章就會出現

5.13.2015

Google play apk expansion fails to build (轉貼)

5.11.2015

PG4A error: Buildfile: build.xml does not exist!可能解法 (轉貼)

So, we have a complete, working game. We want to port it over to Android. But How? Well, I could rewrite it explicitly in Java, but that seems rather senseless. Instead, I can use a subset of Pygame, get it running, and install it on my phone (an HTC myTouch 4G). Luckily, such a thing already exist - dubbed psg4a - and seems have an active community. The homepage can be found here and the documentation here.

The documentation includes a good deal of information about what to install to get started. For instance, I used:
  • The current Pygame Subset: pgs4a-0.9.4.zip and unzipped it to an arbitrary directory (Drive leter:\pgs4a for example).
  • The Java Development Kit: link to Download page here. I used the newest (at the time), version 7 Update 10.
  • Python, of course (installed prior).
  • Android OEM USB Drivers for Android phone (in order to connect your mobile phone and develop/test directly without using an emulator). Link here.
  • Optionally, I installed the HTC-specific drivers for my phone. I found the package here.

Now, to get down to business.

  1. Check your pgs4a install by running android.py test via the command line (reference here). If successful, you should see the following:

  2. Now follow along with the steps and begin constructing the sample game. Doing so aided me in fixing my installation as I ran into numerous issues (admittedly, some were my fault while others were just hiccups).
  3. Notice that once you create the .py file and launch it, the "game" we run successfully.
  4. Once you get here, and type in either the release or install commands (an aside: typing in android.py build mygame release builds the signed and unsigned .apks whileandroid.py build mygame release install does the former and installs it on the connected device or emulator) you will run into a dreaded error. It will differ, but will end with:

    Buildfile: build.xml does not exist!
    Build failed
  5. Luckily, all of these problems you will encounter are resolved via a couple of fairly easy fixes. It just takes forever and involves a little finagling with the System Properties.

    To get started, first some background: or what is a path variable? When working with Windows there exist an editable/configurable data element known as a PATH environment variable. To familiarize yourself with it, open another command line window and type in echo %PATH%. You will see a long string of directories separated by semicolons.  What does this mean? This is where and how we specify/define the paths in which the executables we want to run, do so within our Windows environment. For instance, for other programs to use Apache Ant (used to build the Java applications associated with Android) - or just ant via the command line, they need to know where it is. We can edit the path to specify that information (do not fret, the procedure below will walk you through the process). But, where is our executable to add to our path?Well...when we installed the Android SDK via android.py it was installed in the pgs4a directory. Specifically, the executables would be found in the bin folder (for instance, D:\pgs4a-0.9.4\apache-ant\bin for me). The executable we need is ant.bat. However, if you were to run ant (double-clicking or command line), you would get a message similar to this:

    D:\pgs4a-0.9.4\apache-ant\bin>ant
    Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre7\lib\tools.jar
    Buildfile: build.xml does not exist!
    Build failed

    So, what can we do? We can fix our PATH variable! To do it, we will need to follow a few steps:

    1. Find the directory you installed the JDK in. We need the path to the java.exe. This is usually found Drive Letter:\Program Files\Java\jdk1.7.0_10\bin
    2. Navigate to My Computer -> Click the Advanced Tab -> Click Environment Variables -> Under System variables look for Path -> Click Edit -> At the end of the string insert a semicolon.
    3. Now paste your directory found in Step #1 directly after the ; (so my Path would be longlistofstring;C:\Program Files\Java\jdk1.7.0_10\bin). To test, open up another command line window and type in javac. This is the Java compiler. You should see a list of options if successful. If you are not you will see:

      'javac' is not recognized as an internal or external command,
      operable program or batch file.
    4. Now again follow Step #2 and add the directory for ant remembering to add the semicolon before the directory (again my Path would look likelonglistofstrings;C:\Program Files\Java\jdk1.7.0_10\bin;D:\pgs4a-0.9.4\apache-ant\bin).
    5. Note, if you have more than one Java instance installed, you may need to uninstall them as usually the SE java executes by default. This the root cause of the 1stmessage stated in the error above (Unable to locate tools.jar...). Yet, we still get the build.xml error! What gives!?!
    6. When we created our new directory we intended it to be an Android project. However, we actually have not setup the Android environment yet. Fortunately, we downloaded the tools when we unpacked the sdk (see here). To test the android tool, in the command prompt simply type in android and press Enter. If you see:

      'android' is not recognized as an internal or external command,
      operable program or batch file.

      Then, we need to...you guessed it! Append it to our Path variable (the last time, I promise). So, my final Path variable would be: longlistofstrings;C:\Program Files\Java\jdk1.7.0_10\bin;D:\pgs4a-0.9.4\apache-ant\bin;D:\pgs4a-0.9.4\android-sdk\tools. Again, Click OK to close both the Environment Variableswindow and the System Properties window, respectively. Lastly, close your command line window and open a new one. At this point we are done editing our Path variable, but, we have a few steps to finish before we have a working build.
  6. Try the android command again. This will open the Android SDK Manager. Launching said manager will search and populate all available updates for the SDK tool set (Under the Tools folder). It is highly recommended you download them (rev. 20 as of this tutorial). I installed the Android SDK Platform-tools additionally (but it is purely optional). Click Install x (x = number of package(s)) package(s)... Accept the License and click Install. Wait patiently. Once the install concludes you may be prompted with a prompt; click OK. Close window.
  7. Instantly, rerun the android command yet again in the command prompt. You should now see all the available Android APIs and subsequent SDK updates (further revisions or iterations on top of the major releases; I initially had SDK rev. 16 installed for an earlier project so your experience may differ). Choose your API of choice. My (older) phone runs API 10 (2.3.3) so naturally, I chose it. A larger majority of retail Android phones run API 8 (2.2) so keep this in mind as Android applications are not backward compatible. They are, however, forward compatible. Note aside, you should see something like this:



    Follow the previous step's instructions to install the packages (this time clicking Accept All). I did not catch it at the time, but under the Extras folder the manager had defaulted to selecting an update for the Google USB Driver. Indeed, in hindsight, it may be possible to avoid manually installing the OEM driver yourself.
  8. Now to deal with our build.xml error...surely. Open a new command line window and type in android list targets. This will list all the available devices, dubbed targets, we want to build our application for. Amongst them (likely to be several), you will see the Intel Atom image you just installed. Choose the target that represents your device. In my case, my target was 1. I then typed in android update project --target x --path D:\pgs4a-0.9.4\Note: x is 1 for me, but may differ for you (of course, path will likely differ too; I included my path just for reference).

    Error: D:\pgs4a-0.9.4\mygame is not a valid project (AndroidManifest.xml not found).
  9. Seriously!?! No big deal. The config file you made (if you do not recall, here) produced the Android Manifest file (albeit outside your mygame directory, in the ps4a parent folder). Simply move that file inside your mygame directory and rerun the command. You will see:

    Updated and renamed default.properties to project.properties
    Updated local.properties
    No project name specified, using Activity name 'PythonActivity'.
    If you wish to change it, edit the first line of build.xml.
    Added file D:\pgs4a-0.9.4\build.xml
    Added file D:\pgs4a-0.9.4\proguard-project.txt

    Hey! That is the build.xml file we have been looking for. Now we can run our build command.

  10. Updating build files.

    Error: Target id 'android-8' is not valid. Use 'android.bat list targets' to get the target ids.

    Nope!
     We need to run the android command and specify that this specific Android API is installed (just for giggles navigate to the android-sdk\platforms sub-folder in the pgs4a directory and verify that android-8 is not there). Run the android command one more time. Select Android 2.2 (API 8) and start the install process; once finished, close the window, and type the build command (android.py build mygame release) one more time. You will see walls of commands and text, ending with:

    release:

    install:
         [echo] Installing D:\pgs4a-0.9.4\bin\mygame-1-release.apk onto default emulator or device...
         [exec]     pkg: /data/local/tmp/mygame-1-release.apk
         [exec] Success
         [exec] 1663 KB/s (2661077 bytes in 1.562s)

    BUILD SUCCESSFUL
    Total time: 20 seconds

    It looks like the build succeeded.

    You did it! The game has been built and installed on your device successfully. Now to test it! Bring up your applications and find the mygame application (it will be the default Pygame icon). Tap it and watch the Pygame splash screen appear and feel your excitement brew. Now watch as the screen flicker and the game crash! Disappointment sets in. Before you lose your patience, know that it is a simple fix. Very simple, I promise and it is one I missed when reading the sample tutorial. In other words, my bad!.
  11. So, what the heck happened!?! Well, luckily (and very much so I might add), the Pygame Subset grants you access to the Android debug output in the form of the adb logcat command. Furthermore, it filters python output showing you exactly what happens when you run your application. To take advantage of this tool, open another command line window from the pgs4a directory and type in android.py logcat. Now, run the installed application again. Analyzing the output I see a mistake that took me a while to catch:

    I/python  (27690): Private directory is /data/data/com.dr.mygame/files
    I/python  (27690): Argument is /data/data/com.dr.mygame/files
    I/python  (27690): Handing off to main.
    I/python  (27690): Traceback (most recent call last):
    I/python  (27690):   File "start.pyx", line 52, in start (jni/../jni/application/src//start.c:1313)
    I/python  (27690): ImportError: No module named main

    Ah, main! That is right! Nothing in my directory is specifically named main.py. So, when the start function tries to hand off the functionality to my game, it has no main function to call. Such a simple mistake that could have been fixed if I had carefully reading the first line here.
  12. To fix this, I simply rename the mygame.py to main.py, right? Well, yes and no. I had an instance (as of this typing, I could not reproduce) where I had to also run configure again to update the AndroidManifest.xml, which updated the build.xml file when I ran the build command again. I also ran into one instance where building would fail to create a signed apk. To remedy this I deleted the keystore and ran configure again. This seemed to solve the issue.
  13. Run the application again. It works!!! Congratulations for sticking with it and uploading a "game" to your Android device. My work, however, has just begun.
  14. Few asides or notes:
    • leave logcat running as you test your application. It is an invaluable tool.
    • reference the Pygame Subset forum here. It is a great resource.
    • ignore the cdrom Import error...pgs4a does.

Ref: https://sites.google.com/site/dustinprinehart/current-projects/float-i-pop/proof-of-concept