
Only Linux cross-compilation to Android is supported.

Prerequisites:
- Install Android NDK and Android SDK
- Install Qt 5.7+ for Android under your home directory to be writable. Unfortunately, there is a Qt bug
  (https://bugreports.qt.io/browse/QTBUG-54666) what can be fixed by only patching one cmake config file.
  The build files will comment the problematic line.
- Get KStars source code from Github or KDE
- Some tools are needed for the compilation: sudo apt-get install dos2unix ccache

Set the following environmental variables before building:

export QT_ANDROID=Qt SDK for Android target (e.g. /opt/Qt/5.9.2/android_armv7"}
export CMAKE_ANDROID_NDK=Android NDK path
export ANDROID_SDK_ROOT=Android SDK path
export ANDROID_API_LEVEL=Android API level (currently the minimum is 17)

If you want to generate signed release package set the following variables:

export ANDROID_KEYSTORE=your_keystore_file
export ANDROID_KEYSTORE_ALIAS=your_keystore_alias
export KSTARS_ROOT=KStars Path (e.g. /home/jasem/Projects/kstars)

First build the KF5 dependencies separately:

- Make a build directory in a separate location form source (e.g. /home/jasem/build/kstars-android):

- Run build_kf5.sh and verify that the script builds everything without any problem.

$KSTARS_ROOT/packaging/android/build_kf5.sh

When KF5 are ready, build KStars Lite for Android:

- Install Eigen3, git and other dependencies
- Configure out-of-source build (MinSizeRel build type is recommended for Android):

cmake -B. -H$KSTARS_ROOT -DBUILD_KSTARS_LITE=ON -DCMAKE_TOOLCHAIN_FILE=$CMAKE_ANDROID_NDK/build/cmake/android.toolchain.cmake \
      -DEIGEN3_INCLUDE_DIR=/usr/include/eigen3/ -DCMAKE_INSTALL_PREFIX=$(pwd)/android/export -DCMAKE_BUILD_TYPE=MinSizeRel \
      -DECM_DIR=/usr/share/ECM/cmake/ -DCMAKE_PREFIX_PATH=$QT_ANDROID \
      -DCMAKE_AR=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar

- Compile:

make -j4

- Download and convert the translations:

make convert_translations_to_android

If the above command dies with the error message:

releaseme/lib/releaseme/l10n.rb:195:in `verify_pot': l10n pot appears to be a variable. cannot resolve $potfile.pot (RuntimeError)

...then comment out this line in the Ruby script and the execution will be fine next time.


- Install:

make -j4 install

- Qt does not work with the newest SDK Tools, you must use v25 as suggested here:
  https://stackoverflow.com/questions/42754878/qt-creator-wont-list-any-available-android-build-sdks/42811774#42811774

  Basically, download https://dl.google.com/android/repository/tools_r25.2.5-linux.zip and replace the ANDROID_SDK_DIR/tools directory or
  just use the Android SDK download tool to use this version.

- Generate the Android debug package:

make create-apk-debug-kstars

- Install the Android debug package to your phone:

make install-apk-debug-kstars

- Generate the Android release package:

make create-apk-release-kstars

- To sign a release package:

make sign-apk-kstars

- The debug package location: android/kstars_build_apk/bin/QtApp-debug.apk
  Manual installation: adb install android/kstars_build_apk/bin/QtApp-debug.apk
- The release package location: android/kstars_build_apk/bin/kstars-release-signed.apk
  Manual installation: adb install android/kstars_build_apk/bin/kstars-signed.apk
