PySide for AndroidIf you want to write GUI applications for Android using Python, you did not really have many options, apart from generating and displaying HTML with SL4A. Until now. Combining the power of three projects, PySide for Android lets you write Qt or QML UIs for Android - all in pure Python. The projects on which PySide for Android builds upon are:
TODO
Mostly following the instructions of the Py4A project.
We need the Desktop build to run the API Extractor, Generatorrunner and Shiboken.
We need this to build the bindings, libpyside and libshiboken natively for Android.
This is the C++ launcher that will include libpyside, libshiboken, libpython and will set everything up and finally load the main.py from the SD card (or any other script).
libpyside and the PySide binding modules have a shared library dependency on libshiboken.
However, the dependency is not on the .so library itself, so the linker does
not find it. To fix this, we have to patch the name of the libshiboken dependency in
libpyside and also in all binding modules.
Our PySide build is not compatible with the Qt libraries downloaded by Ministro, so we have to take the Qt libraries from the Necessitas SDK, strip them (otherwise they are huge and will not fit into your device's memory) and copy them over the files downloaded by Ministro. At least the Qt libraries and the Android platform plugin need to be replaced.
I haven't been able to force the Necessitas Qt Creator to include extra shared libraries
in the APK, so we'll have to "inject" these libraries manually into the Android project
and then rebuild the Android project using ant on the command line (if we
try to do it using Qt Creator, it will overwrite the libs.xml and remove the libraries).
After building PySideLauncher this way, we have an APK that includes libpython, libshiboken and libpyside - ready for deployment (the Python libraries, Qt libraries and PySide binding modules are installed directly to the system, and are not shipped with the APK).
/data/python/main.py file on the SD cardImportant: If you are using PySideLauncher to launch your application, you must have a main.py file on your SD card, because that is what PySideLauncher opens. If you don't have a main.py file on your SD card (or your main.py fails for some reason), PySideLauncher will not show anything. In that case, please try the example main.py to check if you have everything installed correctly, and if this works, then try modifying the main.py file and/or load your code there. The way the example main.py is structured is so that any errors that you get are written to the SD card, which helps in debugging (right now, errors are not logged in logcat).
host$ adb shell $ su # mkdir /data/python ^D^D host$ adb push bin /data/python/bin host$ adb push lib /data/python/lib host$ adb shell $ su # chmod 755 /data/python/bin/python # LD_LIBRARY_PATH=/data/python/lib/ data/python/bin/python Python 2.6.2 (r262:71600, Jul 4 2011, 13:24:39) [GCC 4.4.3] on linux-armv7l Type "help", "copyright", "credits" or "license" for more information. >>> ^D^D^D host$ adb push main.py /sdcard/main.py host$ adb install PySideLauncher-debug.apk (... click the PySide icon and install Ministro from Market ...) (... make sure Ministro downloads the Qt libraries ...) (... click the PySide icon again and it should display "Hello from PySide Cool!" ...)
It turns out that as of 2012-02-10 (and probably a bit earlier too) you don't need to extract the PySide-compatible Qt libraries from the SDK - the Ministro libraries are now up to date and can be used with the PySide modules :)
If you do not want to build everything yourself, here are prebuilt binaries for you to get started:
Here are some files required to build everything from source (make sure to fix the paths in the file to point to the correct location):