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

1.24.2015

Photoshop 影像圖層無法複製

試著調整,影像->模式->索引色,改成,RGB色彩。

1.12.2015

Kickstarter

Kickstarter是一間於2009年在美國紐約成立、基於美國人的商業公司,它透過該網站進行公眾集資以提供人們進行創意專案的籌集資金。但人們不能以Kickstarter為投資專案來賺錢。他們規定只能返還實物獎勵或者獨一無二的經驗給資助者,像一本寫著感謝的筆記、客製的T恤、與作家共進晚餐,或者一個新產品的最初體驗。

https://www.kickstarter.com/

11.19.2014

特殊符號的英文讀法(轉貼)

特殊符號的英文讀法


equal sign (=) 
decimal points (.) 
semicolon (;) 
increment (++) operators 
decrement (--) operators 
( ) Parenthesis 
{ } Braces 
[ ] Brackets 
, Comma 
; Semicolon 
' Quote 
@ At 
+  plus 加號;正號 
-  minus 減號;負號 
± plus or minus 正負號 
× is multiplied by 乘號 
÷ is divided by 除號 
= is equal to 等號 
≠ is not equal to 不等號 
≡ is equivalent to 全等於號 
≌ is equal to or approximately equal to 等於或約等於號 
≈ is approximately equal to 約等於號 
< is less than 小於號 
> is more than 大於號 
≮ is not less than 不小於號 
≯ is not more than 不大於號 
≤ is less than or equal to 小於或等於號 
≥ is more than or equal to 大於或等於號 
%  per cent 百分之… 
‰ per mill 千分之… 
∞ infinity 無限大號 
∝ varies as 與…成比例 
√ (square) root 平方根 
∵ since; because 因爲 
∴ hence 所以 
∷ equals, as (proportion) 等於,成比例 
∠ angle 角 
⌒ semicircle 半圓 
⊙ circle 圓 
○ circumference 圓周 
π pi 圓周率 
△ triangle 三角形 
⊥ perpendicular to 垂直於
∪ union of 聯集 
∩ intersection of 交集 
∫ the integral of …的積分 
∑ (sigma) summation of 總和 
° degree 度 
′ minute 分 
〃 second 秒 
℃ Celsius system 攝氏度 
{ open brace, open curly 左大括弧 
} close brace, close curly 右大括弧 
( open parenthesis, open paren 左小括號 
) close parenthesis, close paren 右小括號 
() brakets/ parentheses 括弧 
[ open bracket 左中括號 
] close bracket 右中括號 
[] square brackets 中括號 
. period, dot 句號,點 
 vertical bar, vertical virgule 豎線 
& ampersand, and, reference, ref 和,引用 
* asterisk, multiply, star, pointer 星號,乘號,星,指標 
/ slash, divide, oblique 斜線,斜杠,除號 
// slash-slash, comment 雙斜線,注釋符 
# pound 井號 
\ backslash, sometimes escape 反斜線轉義符,有時表示轉義符或續行符 
~ tilde 波浪符 
. full stop 句號 
, comma 逗號 
: colon 冒號 
; semicolon 分號 
? question mark 問號 
! exclamation mark (英式英語) exclamation point (美式英語) 
' apostrophe 撇號 
- hyphen 連字號 
-- dash 破折號 
... dots/ ellipsis 省略號 
" single quotation marks 單引號 
"" double quotation marks 雙引號 
‖ parallel 雙線號 
& ampersand = and 
~ swung dash 相似 
§ section; division 分節號 
→ arrow 箭號;

9.25.2014

(轉貼)How do I tell what type my shell is

How can I tell what type my shell is? ie, whether it's traditional sh, bash, ksh, csh, zsh etc.
Note that checking $SHELL or $0 won't work because $SHELL isn't set by all shells, so if you start in one shell and then start a different one you may still have the old $SHELL.
$0 only tells you where the shell binary is, but doesn't tell you whether /bin/sh is a real Bourne shell or bash.
I presume that the answer will be "try some features and see what breaks", so if anyone can point me at a script that does that, that'd be great.

Try to locate the shell path using the current shell PID:
ps -p $$
It should work at least with sh, bash and ksh.
share|improve this answer