= Porting modRana to Android = [[PageOutline]] As there is currently no GTK port for Android and not even any project trying to do this, only the QML GUI is relevant for running modRana on Android. Most of this is based on [http://thp.io/2011/pyside-android/ THP's excellent ''PySide for Android'' work]. [wiki:THPEuroPython2012TalkNotes Notes from THP's EuroPython 2012 talk] == Prerequisites == === Python === Python is needed as modRana is written in Python. The [http://sourceforge.net/projects/pyside-android/files/data_python.tgz/download Python 2.6 binaries provided by THP] can be used. This archive also contains !PySide binaries. To be usable, the a ''/data/python'' folder needs to be created on the Android folder, and the ''bin'' and ''lib'' folders need to be copied inside it (this can be easily done with the ''adb push'' command when the device is connected & in debugging mode). Then according to the THP, the main Python binary needs to be made executable: {{{ $ su # chmod 755 /data/python/bin/python }}} ==== Building Python for Android ==== Based on [http://python-for-android.readthedocs.org/en/latest/prerequisites/ python-for-android documentation], built on Ubuntu 12.10 64-bit. Install prerequisites: {{{ sudo apt-get install build-essential patch git-core ccache ant python-pip python-dev }}} On a 64-bit distro: {{{ sudo apt-get install build-essential patch git-core ccache ant pip python-dev }}} Ensure you have the latest Cython version: {{{ sudo pip install --upgrade cython }}} Python for Android (the Kivi one) seems to build only with NDK-r7, so the NDK in current Necessitas SDK (NDK-r8b) can't be used. Just download the r7 NDK unpack it somewhere and set the NDK path. {{{ wget http://dl.google.com/android/ndk/android-ndk-r7-linux-x86.tar.bz2 tar xvf android-ndk-r7-linux-x86.tar.bz2 }}} The Android SDK from Necessitas can be used, just make sure API 14 is installed. {{{ cd python-for-android export ANDROIDSDK="" export ANDROIDNDK="" export ANDROIDNDKVER=r7 export ANDROIDAPI=14 ./distribute.sh -m "pyjnius kivy" -f }}} === Qt + QML === The Necessitas project provides Qt libriries with QML support. Due to Android lacking proper package management, there is an android application called ''Ministro'' that handles library installation requests from ''Necessitas'' using applications. When an application using Necessitas is started for the first time, it redirects the user to the Google Play store to install Ministro (or Ministro II). Once Ministro is installed and its ''service'' is running, the application calls this service to request the Qt Libraries it needs. It seems that content of this request is governed by the '''libs.xml''' file in the Necessitas application package - if some libs are missing, this fil needs to be modified. There are two Ministro versions: * Ministro - provides Alpha 2 (0.2) libraries * Ministro II - provides Alpha 3 libraries (cca 0.34) The ALpha 2 Qt libraries provided by necessitas are suable, but have a few issues, for example: * text both in Qt widgets and QML is rendered as rectangles '''unleess it is set to italic''' This is more of a technical overview as from the point of view of the Python application, all this (making sure Ministro is installed & requesting Qt Libraries) is handled by the !PySide Launcher and the application does'n need to be even aware of it. === !PySide === To work, !PySide binaries need to be compatible with the installed Python & Qt versions. Compiled !PySide binaries are part of the Python tarball provided by THP. === !PySide Launcher === !PySide programs can't be currently launched from the shell and have to use a special launcher application that makes sure all needed libraires are avalable and provides the application with acces to the screen. There is a !PySide Launcher APK on THPs site, but it doesn't work with !QtDeclarative due to missing dependency on libQtOpenGL. As a result, the !PySide launcher source needs to be slightly modified and a new APK created. ==== Modified Pyside Launcher ==== '''Software prerequisites:''' * ant * Necessitas Qt SDK ===== Modifying the !PySide Launcher project ===== get the source [https://github.com/thp/pyside-launcher-android from Gtihub]: {{{ git clone https://github.com/thp/pyside-launcher-android.git }}} Then in in: ''pyside-launcher-android/android/res/values/libs.xml'' The ''qt_libs'' section should look like this: {{{ QtCore QtGui QtDeclarative QtOpenGL }}} This file is used to request Qt libraries from Ministro - if you need more libraries, add them there. Don't forget to omit the ''lib'' prefix. List of libraries available from Ministro (Alpha 2): http://files.kde.org/necessitas/qt/android/armeabi-v7a/objects/0.21/lib/ ===== Rebuilding the APK ===== First, change in ''pyside-launcher/android/local.properties'' path to the ''sdk.dir'' to poin to the Android SDK inside the Necessitas SDK, for example: {{{ sdk.dir=/home/user/necessitas/android-sdk }}} Then run ant like this inside the ''android'' folder {{{ cd pyside-launcher/android and debug }}} (''adb'' complains about the package created by ''ant release'' due to missing certificates, but likes the package created by ''ant debug'' just fine) If ''ant'' complains about outdated project, update the project using the ''android'' tool, which is normally available in the ''tools'' directory in the Android-sdk. {{{ android update project -p pyside-launcher/android/ }}} === Qt Components === There is an Android port of Qt Components. ==== Qt Components Theme ==== Qt Components need a theme to work correctly. Without a theme, not only would most elements be transparent but also the layout is quite broken. There are multiple sources for a working theme: * taking it from the Qt SDK * from an N9 filesystem * from the Fremantle Qt Components theme package * from Nemo == Updated Prerequisites == While the above mentioned combination works, it could be improved by using more up to date software packages. === Python === As modRana and Mieru run just fine with Python 2.5, Python version is really not a limiting factor. Any Python version that compiles on Android and is compatible with other prerequisites will do. === Qt + QML === The currently used Necessitas Qt version (0.2 -> Alpha 2) is outdated and causes quite a few issues - most being, that all text is rendered as rectangles, unless it is set to be '''itallic'''. As a result, it should be a priority to start using the Necessitas Alpha 3 (0.34+-) as soon as possible. To do this, the following is needed: * a Python distribution compiled for Android * compiling !PySide against this Python version & the Necessitas Qt * an updated !PySide Launcher that uses Ministro II (which provides the Alpha 3 libraries) === !PySide === At least version 1.0.5 should be used, as this is the version that is running Fremantle CSSU, without any issues. Some older version on vanilla PR 1.3 Fremantle is known to cause issues, namely with multiple decorators for a single method. === Qt Components === == FAQ == === error: insufficient permissions for device === First do: {{{adb stop-server}}} Then as root do: {{{adb start-server}}} === Show live log from Android === {{{ adb shell logcat }}} === Necessitas import and plugin paths (Ministro I.) === {{{ /data/data/eu.licentia.necessitas.ministro/files/qt/imports /data/data/eu.licentia.necessitas.ministro/files/qt/plugin }}}