= 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 (android-python27) ==== The [http://code.google.com/p/android-python27/ Android-python27] project achieved not only to build Python for Android, generate custom APKs but also to build !PyQt compatible with their build & Qt libraries provided by the Necessitas project. [wiki:androidPython27_Readme README][[BR]] [wiki:androidPython27_qtReadme README - build with PyQt] ===== Building SIP ===== '''error: cannot find -lsupc++''' Install: ==== Building Python for Android (Kivi)==== 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 '''unless 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 are at least three Android ports of Qt Components. The modified Ineans Qt Components:[[BR]] [https://qt.gitorious.org/~martink/qt-components/martinks-ineans-qt-components/commits/android] The koyinings one based on the Symbian Qt Components:[[BR]] [https://gitorious.org/~koying/qt-components/android-qt-components] And the one that is based on !MeeGo Qt Components by Filip Brcic:[[BR]] [https://qt.gitorious.org/~brcha/qt-components/qt-components-android] I've been able to successfully compile both component sets. As my applications are using the !MeeGo based components on Fremantle & Harmattan, I'll start with those. ==== Compiling Qt Components with necessitas ==== The modified Inens Qt components are based on both the Inneans Fremantle component port & Martin Kolmans changes for BB10 support. These components use the familiar Fremantle & Harmattan import syntax: {{{ import com.nokia.meego 1.0 }}} So it is possible to reuse code from Fremantle & Harmattan (and BB10 project using these components) without having to rewrite the import statement. First clone the components and then switch to the ''android'' branch: {{{ git clone git://gitorious.org/~martink/qt-components/martinks-ineans-qt-components.git cd qt-components-android checkout android }}} The export path to the Necessitas Qt libraries to compile against: {{{ export QTDIR=/Android/Qt/482/armeabi export PATH="$QTDIR/bin:$PATH" }}} '''NOTE:''' Check out the Qt version in your Necessitas SDK version, it might not be exactly 482 (Qt 4.8.2) but older or newer. Then configure the components for building: {{{ ./configure -fremantle -no-maliit -make cssu -force-local-theme -mobility -no-xrandr -no-xdamage -nomake examples }}} And build them: {{{ make -j 5 }}} Once the build is finished, the results are available in the ''imports'' folder. Just move it somewhere to your Android device or inside your application package and set the ''QML_IMPORT_PATH'' environmental variable to point where the folder is located. '''Modifineg the components''' For some reason, the source code is present in multiple copies (probably because of of how the SSU/CSSU versions were patched from the upstream Qt Components ?). Anyway, if want your modifications to the source code to take effect once reconfigured & recompiled, edit the files in ''src/fremantle/cssu/''. Modifing the others has no effect on the components that are actually built using the configure options described above. ==== Compiling Brchas Qt Components with Necessitas ==== Clone the android Qt Components Git repository and make sure you are on the android branch: {{{ git clone git://gitorious.org/~brcha/qt-components/qt-components-android.git cd qt-components-android checkout android-master-stable }}} Then add the Necessitas Qt libraries & the Necessitas NDK to your PATH: {{{ export ANDROID_NDK_ROOT=/necessitas/android-ndk export ANDROID_TARGET_ARCH=armeabi export QTDIR=/necessitas/Android/Qt/482/armeabi export PATH="$QTDIR/bin:$PATH" }}} Setting the ANDROID_TARGET_ARCH is optional, it can be set either to ''armeabi'' or to ''armeabiv7'' for some improved (?) ABI with floating point acceleration (?). And configure the Qt components against them. {{{ ./configure --android }}} Then just run make (using -j is fine): {{{ make -j6 }}} After the compilation finishes, the results are inside the ''imports'' folder. ==== Compiling the other Qt Components with Necessitas ==== Compiling the Symbian-based Qt Components (from ~koying) is very similar to the MeeGo based components. {{{ git clone git://gitorious.org/~koying/qt-components/android-qt-components.git cd android-qt-components checkout 1.1-android }}} The environmental variables for the build are the same: {{{ export ANDROID_NDK_ROOT=/necessitas/android-ndk export ANDROID_TARGET_ARCH=armeabi export QTDIR=/necessitas/Android/Qt/482/armeabi export PATH="$QTDIR/bin:$PATH" }}} The configuration step is a bit different. QtMobility needs to be disabled or else the build will fail & there is no --android {{{ ./configure -no-mobility }}} Then: {{{ make -j6 }}} Results are again in in the ''imports'' folder. Even the importa statement is the same: {{{ import com.nokia.android 1.1 }}} ==== 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 }}}