Marble/AndroidCompiling: Difference between revisions
Earthwings (talk | contribs) (add release mode, remove obsolete cmake options) |
No edit summary |
||
(30 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
This page presents how to compile Marble for Android, using the Android SDK, Android NDK and Qt for Android, and how to deploy it to your device. Additional, more detailled instructions can be found in the [https://community.kde.org/Android Community Wiki] also. | |||
This page | |||
=== Prerequisites === | === Prerequisites === | ||
Line 7: | Line 5: | ||
You will need the following tools: | You will need the following tools: | ||
# Android SDK - It can be downloaded from here: http://developer.android.com/sdk/index.html | # Android SDK - It can be downloaded from here: http://developer.android.com/sdk/index.html | ||
{{Note|The SDK contains binary 32 bit tools that are required to create the Marble package. If you're running a 64 bit system, install | {{Note|The SDK contains binary 32 bit tools that are required to create the Marble package. If you're running a 64 bit system, install the 32 bit versions of libgcc, zlib and libc to be able to run them.}} | ||
# Android NDK - You can download it from here: https://developer.android.com/ndk/ | # Android NDK - You can download it from here: https://developer.android.com/ndk/downloads/ | ||
# Qt with support for Android devices. Download the best one for you: https://www.qt.io/download-open-source/#section-2 and install it, but be sure that the Android support is installed too (for example you have to check in to install it in the online installer). | # Qt with support for Android devices. Download the best one for you: https://www.qt.io/download-open-source/#section-2 and install it, but be sure that the Android support is installed too (for example you have to check in to install it in the online installer). | ||
# CMake - Usually you should be able to install it from your repository. | # CMake - Usually you should be able to install it from your repository. | ||
Line 17: | Line 15: | ||
#<syntaxhighlight lang="bash">/path_where_you_installed_the_sdk/tools/android sdk</syntaxhighlight> | #<syntaxhighlight lang="bash">/path_where_you_installed_the_sdk/tools/android sdk</syntaxhighlight> | ||
Make sure to install the | Make sure to install the platform version 22. | ||
{{Note|The latest Android build tools won't work with Qt and you will get errors regarding the generation of build.xml . Hence, download the SDK Tools version r25.2.5 and replace the "tools" folder in your Android SDK root folder with it.}} | |||
=== Getting the Marble Source Code === | === Getting the Marble Source Code === | ||
Line 34: | Line 29: | ||
First, you should change your working directory to Marble's source directory: | First, you should change your working directory to Marble's source directory: | ||
<syntaxhighlight lang="bash">cd ~/marble/sources</syntaxhighlight> | <syntaxhighlight lang="bash">cd ~/marble/sources</syntaxhighlight> | ||
Then the toolchain | Then the toolchain has to be cloned from its git repository: | ||
<syntaxhighlight lang="bash">git clone | <syntaxhighlight lang="bash">git clone git://anongit.kde.org/extra-cmake-modules</syntaxhighlight> | ||
We will use this to compile Marble and pack it as an apk. | We will use this to compile Marble and pack it as an apk. | ||
=== Setting your | === Setting your ENV variables === | ||
You have to add the following | You have to add the following environment variables: | ||
Android NDK: | Android NDK: | ||
<syntaxhighlight lang="bash">export | <syntaxhighlight lang="bash">export ANDROID_NDK_ROOT=/path_to_your_NDK_install | ||
# sadly extra-cmake-modules uses another variable name than Marble, which also needs to be set: | |||
export ANDROID_NDK=$ANDROID_NDK_ROOT</syntaxhighlight> | |||
Android SDK: | Android SDK: | ||
<syntaxhighlight lang="bash">export | <syntaxhighlight lang="bash">export ANDROID_SDK_ROOT=/path_to_your_SDK_install</syntaxhighlight> | ||
Ant: | Ant: | ||
You can get the path to the binary with: | You can get the path to the binary with: | ||
<syntaxhighlight lang="bash">whereis ant</syntaxhighlight> | <syntaxhighlight lang="bash">whereis ant</syntaxhighlight> | ||
After you know the path: | After you know the path (note that this must be an executable file, not a directory): | ||
<syntaxhighlight lang="bash">export ANT=/ | <syntaxhighlight lang="bash">export ANT=/path/to/ant</syntaxhighlight> | ||
Java: | Java: | ||
Line 58: | Line 55: | ||
For example, if you installed Qt in /opt/Qt you have to set the following on a 64 bit system: | For example, if you installed Qt in /opt/Qt you have to set the following on a 64 bit system: | ||
<syntaxhighlight lang="bash">export Qt5_android=/opt/Qt/5.4/android_armv7</syntaxhighlight> | <syntaxhighlight lang="bash">export Qt5_android=/opt/Qt/5.4/android_armv7</syntaxhighlight> | ||
Also specify the location of extra-cmake-modules (replace /path/to/extra-cmake-modules below with the folder where you cloned extra-cmake-modules to in the step above): | |||
<syntaxhighlight lang="bash">export ECM=/path/to/extra-cmake-modules</syntaxhighlight> | |||
And you also need to specify your target platform ( | And you also need to specify your target platform (at least 22, but after the build the package will be backward compatible): | ||
<syntaxhighlight lang="bash">export ANDROID_PLATFORM=android- | <syntaxhighlight lang="bash">export ANDROID_PLATFORM=android-22</syntaxhighlight> | ||
=== Setting up | === Setting up Kirigami === | ||
You will also need to get Kirigami, which you can get here: https://github.com/KDE/kirigami | |||
<syntaxhighlight lang="bash"> | After cloning the source code change your working directory to the Kirigami's source directory: | ||
<syntaxhighlight lang="bash">cd path/to/kirigami</syntaxhighlight> | |||
Then create a build folder and navigate to it: | |||
<syntaxhighlight lang="bash">mkdir build | |||
cd build</syntaxhighlight> | |||
After that we need to configure the project using Cmake: | |||
<syntaxhighlight lang="bash">cmake .. -DCMAKE_TOOLCHAIN_FILE=${ECM}/toolchain/Android.cmake -DCMAKE_PREFIX_PATH=${Qt5_android} -DCMAKE_INSTALL_PREFIX=~/marble/export -DECM_DIR=/usr/local/share/ECM/cmake </syntaxhighlight> | |||
Then you install the files using: | |||
<syntaxhighlight lang="bash">make | |||
make install</syntaxhighlight> | |||
This should install all the files required by Kirigami in ~/marble/export or whichever other path you passed in the <code>-DCMAKE_INSTALL_PREFIX</code> option to Cmake. | |||
=== Compiling Marble === | === Compiling Marble === | ||
Line 74: | Line 81: | ||
Than change your working directory to it: | Than change your working directory to it: | ||
<syntaxhighlight lang="bash">cd ~/marble/build</syntaxhighlight> | <syntaxhighlight lang="bash">cd ~/marble/build</syntaxhighlight> | ||
Then the project | Then the project has to be configured with Cmake. First we will build the libraries and the plugins, after that we will build the app. | ||
First, run the following command: | First, run the following command: | ||
<syntaxhighlight lang="bash">cmake -DCMAKE_TOOLCHAIN_FILE= | <syntaxhighlight lang="bash">cmake -DECM_ADDITIONAL_FIND_ROOT_PATH=${Qt5_android} -DCMAKE_TOOLCHAIN_FILE="${ECM}/toolchain/Android.cmake" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../export ../sources/ | ||
</syntaxhighlight> | </syntaxhighlight> | ||
This will generate the needed Makefile for compiling. | This will generate the needed Makefile for compiling. Start the build process with the following command: | ||
<syntaxhighlight lang="bash">make</syntaxhighlight> | <syntaxhighlight lang="bash">make install/strip</syntaxhighlight> | ||
After | |||
< | === Generating the Android Application Package (APK) === | ||
Now | After the build successfully finished, the files have been installed to {{Path|1=../export}} or whichever other path you passed in the <code>-DCMAKE_INSTALL_PREFIX</code> option to cmake. Now run the Python script {{Path|1=src/apps/marble-maps/create-apk.py}} to generate the Android package: | ||
<syntaxhighlight lang="bash">~/marble/sources/src/apps/marble-maps/create-apk.py --target MarbleMaps.apk ../export | |||
<syntaxhighlight lang="bash"> | </syntaxhighlight> | ||
</ | |||
< | The script provides a number of parameters. Typical usage is as follows: | ||
* Testing directly on a connected device: <code>create-apk.py --reinstall /path/to/marble/export</code> | |||
* Creating an .apk locally: <code>create-apk.py --target MarbleMaps.apk /path/to/marble/export</code> | |||
* Creating a signed package for release: <code>create-apk.py --target MarbleMaps.apk --keystore /path/to/Marble.keystore /path/to/marble/export</code>. You'll be prompted for the required passwords (unless you pass them using the <code>--storepass</code> option). | |||
All parameters of {{Path|1=create-apk.py}} can be shown with its <code>--help</code> switch: | |||
{{Output|1=<nowiki> | |||
usage: create-apk.py [-h] [--target TARGET] [--keystore KEYSTORE] | |||
[--storepass STOREPASS] [--release] [--install] | |||
[--reinstall] | |||
directory | |||
Create an Android application package (APK) for Marble Maps | |||
positional arguments: | |||
directory The directory where the Android build is installed to | |||
optional arguments: | |||
-h, --help show this help message and exit | |||
--target TARGET Target filename (or directory) for the .apk package | |||
--keystore KEYSTORE Keystore file for signing the package | |||
--storepass STOREPASS | |||
Keystore password for signing the package | |||
--release Build a release package | |||
--install Install the package to a connected device | |||
(uninstalling it before, if needed) | |||
--reinstall Install the package to a connected device (keeping | |||
previous data intact, if any) | |||
</nowiki>}} |
Latest revision as of 23:53, 14 December 2018
This page presents how to compile Marble for Android, using the Android SDK, Android NDK and Qt for Android, and how to deploy it to your device. Additional, more detailled instructions can be found in the Community Wiki also.
Prerequisites
You will need the following tools:
- Android SDK - It can be downloaded from here: http://developer.android.com/sdk/index.html
- Android NDK - You can download it from here: https://developer.android.com/ndk/downloads/
- Qt with support for Android devices. Download the best one for you: https://www.qt.io/download-open-source/#section-2 and install it, but be sure that the Android support is installed too (for example you have to check in to install it in the online installer).
- CMake - Usually you should be able to install it from your repository.
- Java Development Kit - For example you can install openjdk, usually it should be in your repository.
- Ant - This should be available from the repositories too.
Some Android platforms will be needed, you should install them with the Android SDK's package manager. It can be started with:
/path_where_you_installed_the_sdk/tools/android sdk
Make sure to install the platform version 22.
Getting the Marble Source Code
- Start a terminal
- We download the source code by cloning the developer repository with the following command:
git clone git://anongit.kde.org/marble ~/marble/sources
After you run the git clone command (shown above), all the Marble source files and considerable resource files will be found in a folder called marble in your home directory.
Getting the CMake toolchain for Android
First, you should change your working directory to Marble's source directory:
cd ~/marble/sources
Then the toolchain has to be cloned from its git repository:
git clone git://anongit.kde.org/extra-cmake-modules
We will use this to compile Marble and pack it as an apk.
Setting your ENV variables
You have to add the following environment variables:
Android NDK:
export ANDROID_NDK_ROOT=/path_to_your_NDK_install
# sadly extra-cmake-modules uses another variable name than Marble, which also needs to be set:
export ANDROID_NDK=$ANDROID_NDK_ROOT
Android SDK:
export ANDROID_SDK_ROOT=/path_to_your_SDK_install
Ant:
You can get the path to the binary with:
whereis ant
After you know the path (note that this must be an executable file, not a directory):
export ANT=/path/to/ant
Java:
Path to your Java installation, for example:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk
Qt:
For example, if you installed Qt in /opt/Qt you have to set the following on a 64 bit system:
export Qt5_android=/opt/Qt/5.4/android_armv7
Also specify the location of extra-cmake-modules (replace /path/to/extra-cmake-modules below with the folder where you cloned extra-cmake-modules to in the step above):
export ECM=/path/to/extra-cmake-modules
And you also need to specify your target platform (at least 22, but after the build the package will be backward compatible):
export ANDROID_PLATFORM=android-22
Setting up Kirigami
You will also need to get Kirigami, which you can get here: https://github.com/KDE/kirigami After cloning the source code change your working directory to the Kirigami's source directory:
cd path/to/kirigami
Then create a build folder and navigate to it:
mkdir build
cd build
After that we need to configure the project using Cmake:
cmake .. -DCMAKE_TOOLCHAIN_FILE=${ECM}/toolchain/Android.cmake -DCMAKE_PREFIX_PATH=${Qt5_android} -DCMAKE_INSTALL_PREFIX=~/marble/export -DECM_DIR=/usr/local/share/ECM/cmake
Then you install the files using:
make
make install
This should install all the files required by Kirigami in ~/marble/export or whichever other path you passed in the -DCMAKE_INSTALL_PREFIX
option to Cmake.
Compiling Marble
First of all, create a build directory in marble's source dir:
mkdir ~/marble/build
Than change your working directory to it:
cd ~/marble/build
Then the project has to be configured with Cmake. First we will build the libraries and the plugins, after that we will build the app.
First, run the following command:
cmake -DECM_ADDITIONAL_FIND_ROOT_PATH=${Qt5_android} -DCMAKE_TOOLCHAIN_FILE="${ECM}/toolchain/Android.cmake" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../export ../sources/
This will generate the needed Makefile for compiling. Start the build process with the following command:
make install/strip
Generating the Android Application Package (APK)
After the build successfully finished, the files have been installed to ../export or whichever other path you passed in the -DCMAKE_INSTALL_PREFIX
option to cmake. Now run the Python script src/apps/marble-maps/create-apk.py to generate the Android package:
~/marble/sources/src/apps/marble-maps/create-apk.py --target MarbleMaps.apk ../export
The script provides a number of parameters. Typical usage is as follows:
- Testing directly on a connected device:
create-apk.py --reinstall /path/to/marble/export
- Creating an .apk locally:
create-apk.py --target MarbleMaps.apk /path/to/marble/export
- Creating a signed package for release:
create-apk.py --target MarbleMaps.apk --keystore /path/to/Marble.keystore /path/to/marble/export
. You'll be prompted for the required passwords (unless you pass them using the--storepass
option).
All parameters of create-apk.py can be shown with its --help
switch:
usage: create-apk.py [-h] [--target TARGET] [--keystore KEYSTORE] [--storepass STOREPASS] [--release] [--install] [--reinstall] directory Create an Android application package (APK) for Marble Maps positional arguments: directory The directory where the Android build is installed to optional arguments: -h, --help show this help message and exit --target TARGET Target filename (or directory) for the .apk package --keystore KEYSTORE Keystore file for signing the package --storepass STOREPASS Keystore password for signing the package --release Build a release package --install Install the package to a connected device (uninstalling it before, if needed) --reinstall Install the package to a connected device (keeping previous data intact, if any)