Difference between revisions of "Android development"

From Navit's Wiki
Jump to: navigation, search
(With gradle: fix for missing bitmaps)
(14 intermediate revisions by 4 users not shown)
Line 27: Line 27:
 
</pre>
 
</pre>
 
</code>
 
</code>
 +
Double-check the version numbers in the paths and adapt if required. If you are running a 64-bit version of the NDK, replace <tt>linux-x86</tt> with <tt>linux-x86_64</tt>.
 
* Prepare Android SDK:  
 
* Prepare Android SDK:  
 
** run android in command line - this will show a GUI for preparing Android SDK
 
** run android in command line - this will show a GUI for preparing Android SDK
Line 32: Line 33:
  
 
===Compiling===
 
===Compiling===
Assuming you've followed the previous steps, you're probably setup to start compiling. Using [[CMake|CMake]] is the recommended way of compiling Navit for Android. Ensure that:
+
 
 +
'''We have recently switched from CMake to gradle for the Android build. CMake is no longer supported for the Android build, see the section on gradle for details.'''
 +
 
 +
Assuming you've followed the previous steps, you're probably setup to start compiling. <del>Using [[CMake|CMake]] is the recommended way of compiling Navit for Android.</del> Ensure that:
 
* You have a java-jdk installed on your system. On Ubuntu:
 
* You have a java-jdk installed on your system. On Ubuntu:
 
  sudo apt-get install openjdk-6-jdk
 
  sudo apt-get install openjdk-6-jdk
 +
When multiple version of java are installed
 +
update-java-alternatives -s java-1.6.0-openjdk-i386
 
* On Ubuntu, ensure that ant1.8 is installed:
 
* On Ubuntu, ensure that ant1.8 is installed:
 
  sudo apt-get install ant1.8
 
  sudo apt-get install ant1.8
Line 50: Line 56:
 
  cd ~/src/android-build
 
  cd ~/src/android-build
 
* Run CMake (ensure that you're in the build directory when you do this!):
 
* Run CMake (ensure that you're in the build directory when you do this!):
<code>
+
cmake -DCMAKE_TOOLCHAIN_FILE=$SOURCE_PATH/Toolchain/arm-eabi.cmake -DCACHE_SIZE="(20*1024*1024)" -DAVOID_FLOAT=1 -DANDROID_PERMISSIONS="CAMERA" -DANDROID_API_VERSION=8 -DXSLT_PROCESSOR=/usr/bin/saxonb-xslt $SOURCE_PATH
<pre style="white-space: pre-wrap;">
 
cmake -DCMAKE_TOOLCHAIN_FILE=$SOURCE_PATH/Toolchain/arm-eabi.cmake -DCACHE_SIZE="(20*1024*1024)" -DAVOID_FLOAT=1 -DANDROID_PERMISSIONS="CAMERA" -DANDROID_API_VERSION=8 -DXSLT_PROCESSOR=/usr/bin/saxonb-xslt $SOURCE_PATH
 
</pre>
 
</code>
 
 
* Build the apk package:
 
* Build the apk package:
 
  make
 
  make
Line 65: Line 67:
 
* Later, to reinstall already installed Navit app run:
 
* Later, to reinstall already installed Navit app run:
 
  adb install -r navit/android/bin/Navit-debug.apk
 
  adb install -r navit/android/bin/Navit-debug.apk
 
==== With autotools ====
 
 
* Run ./autogen.sh from the navit dir.
 
cd ~/src/navit-svn/
 
./autogen.sh
 
* Make sure you have
 
** $ANDROID_NDK pointing to your ndk installation
 
** $ANDROID_API_LVL set to 4
 
** $ANDROID_NDK/toolchains/arm-eabi-*/prebuilt/linux-x86/bin in your $PATH
 
** $ANDROID_PLATFORM set to $ANDROID_NDK/platforms/android-$ANDROID_API_LVL/arch-arm
 
* Run something like
 
./configure \
 
PKG_CONFIG=arm-eabi-pkgconfig \
 
RANLIB=arm-eabi-ranlib \
 
AR=arm-eabi-ar \
 
CC="arm-eabi-gcc -L$ANDROID_PLATFORM/usr/lib -L. -I$ANDROID_PLATFORM/usr/include" \
 
CXX=arm-eabi-g++ \
 
--host=arm-eabi-linux_android \
 
--enable-avoid-float \
 
--enable-avoid-unaligned \
 
--enable-cache-size=20971520 \
 
--enable-svg2png-scaling=8,16,32,48,64,96 \
 
--enable-svg2png-scaling-nav=59 \
 
--enable-svg2png-scaling-flag=32 \
 
--with-xslts=android,plugin_menu,pedestrian_button,pedestrian \
 
--with-saxon=saxonb-xslt \
 
--enable-transformation-roll \
 
--enable-plugin-pedestrian \
 
--with-android-permissions=CAMERA \
 
--with-android-project="android-$ANDROID_API_LVL"
 
* Run make
 
* cd navit
 
* Run make apkg
 
The result is in android/bin as Navit-debug.apk
 
 
'''Even easier''' is it to use this [http://trac.navit-project.org/attachment/ticket/863/android_build.sh hopefully foolproof build script]. Since r4507, it is part of navit. From the navit-main-directory, call it with '''./contrib/android_build.sh'''. Good luck!
 
  
 
==== With cmake on Windows ====
 
==== With cmake on Windows ====
Line 111: Line 76:
 
* create a build dir (i.e. "mkdir android-build")
 
* create a build dir (i.e. "mkdir android-build")
 
* run from build dir ( replace $SOURCE_PATH):
 
* run from build dir ( replace $SOURCE_PATH):
<code>
+
cmake -DCMAKE_TOOLCHAIN_FILE=$SOURCE_PATH/Toolchain/arm-eabi.cmake -DCACHE_SIZE="(20*1024*1024)" -DAVOID_FLOAT=1 -DANDROID_PERMISSIONS="CAMERA" $SOURCE_PATH -G "MinGW Makefiles"
<pre style="white-space: pre-wrap;">
 
cmake -DCMAKE_TOOLCHAIN_FILE=$SOURCE_PATH/Toolchain/arm-eabi.cmake -DCACHE_SIZE="(20*1024*1024)" -DAVOID_FLOAT=1 -DANDROID_PERMISSIONS="CAMERA" $SOURCE_PATH -G "MinGW Makefiles"
 
</pre>
 
</code>
 
 
* run MinGW32-make
 
* run MinGW32-make
 
* run MinGW32-make apkg
 
* run MinGW32-make apkg
Line 121: Line 82:
 
** copy navit/android/bin/Navit-debug.apk to your device (i.e. sd-card) and run it from there or
 
** copy navit/android/bin/Navit-debug.apk to your device (i.e. sd-card) and run it from there or
 
** if debug bridge (adb) is enabled run adb install navit/android/bin/Navit-debug.apk
 
** if debug bridge (adb) is enabled run adb install navit/android/bin/Navit-debug.apk
 +
 +
==== With gradle ====
 +
 +
'''Note: this section is still under construction and may not yet be accurate!'''
 +
 +
These setup instructions are for a machine that does not have Android Studio installed. If you have Android Studio, some of them may not be necessary (or can be accomplished in a different way).
 +
 +
* Make sure you have the following Android SDK components installed (if not, install them using Android SDK Manager):
 +
** Android SDK Platform-tools, version 25.0.3 or later
 +
** Android SDK Build-tools, version 27.0.3
 +
* Make sure you have the <code>ANDROID_HOME</code> environment variable set and pointing to your Android SDK dir. On Linux, this can be accomplished by adding the following line at the bottom of your ''.bashrc'' file in your home dir:
 +
 +
: <code>export ANDROID_HOME="$HOME/bin/android-sdk-linux_86"</code> (use the actual path to your SDK install here)
 +
 +
: You need to enter the command in your current shell as well in order for it to take effect there as well.
 +
 +
* On Ubuntu 18.04 or later (or if your default JRE is Java 9 or later), edit ''$ANDROID_HOME/tools/bin/sdkmanager''. Change line #31 to read:
 +
 +
: <code>DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'</code>
 +
 +
* Now run <code>$ANDROID_HOME/tools/bin/sdkmanager "cmake;3.6.4111459"</code> and accept the license agreement. (If the package is not found, run <code>$ANDROID_HOME/tools/bin/sdkmanager --list | grep cmake</code> and install the cmake version reported there.)
 +
* Make sure you have NDK version 12 or later (if you don’t, install it with <code>$ANDROID_HOME/tools/bin/sdkmanager "ndk-bundle"</code>.)
 +
* If you did '''not''' install NDK through ''sdkmanager'', make sure you have the <code>ANDROID_NDK_HOME</code> environment variable set and pointing to your Android NDK dir. (If not, add it as described above.)
 +
* Change to the Navit source dir and run <code>./gradlew build</code>.
 +
 +
So far, two issues have been observed with the build:
 +
* Building <code>vehicle/gpsd</code> and <code>map/garmin</code> fails on Android. As a workaround, edit ''CMakeLists.txt'' , inserting the following two lines in the <code>if(ANDROID)</code> block (around line 710):
 +
set_with_reason(vehicle/gpsd "Android detected" FALSE)
 +
set_with_reason(map/garmin "Android detected" FALSE)
 +
* Bitmap resources are missing from the APK. A workaround is described [https://github.com/navit-gps/navit/pull/553#issuecomment-406881461 here]—integration of these steps into gradle is being worked on.
 +
 +
== Testing an alternative build ==
 +
 +
If you want to try an alternative build (e.g. Jan's builds with alternative routing) you can do it by :
 +
* enable unsigned apk installation ( [http://www.tomsguide.com/faq/id-2326514/download-install-android-apps-unidentified-developer.html example guide] )
 +
* installing an alternative apk ( e.g. [https://circle-artifacts.com/gh/jandegr/navit/292/artifacts/0/tmp/circle-artifacts.MZk9Slb/navit-96b3160a2e51dffb54e3aa74c17ce3683c52828e-debug.apk an APK from CircleCI] )
 +
* you will probably need an alternative map to match the application requirements ( such as [https://circle-artifacts.com/gh/jandegr/navit/265/artifacts/0/tmp/circle-artifacts.WJkkT78/BNLFR.bin this one] )
  
 
[[Category:Ports]]
 
[[Category:Ports]]
 
[[Category:Development]]
 
[[Category:Development]]
 
[[Category:Android]]
 
[[Category:Android]]

Revision as of 22:17, 22 July 2018

Developing for Android

Pre-requisites

For Navit

  • Ensure that your system has the correct dependencies installed to build Navit.
  • Checkout the latest copy of Navit from svn. The instructions on this page assume you have checked-out a copy to ~/src/navit-svn/

cd ~/src
svn co  svn://svn.code.sf.net/p/navit/code/trunk/navit navit-svn

For Android

path-to-sdk/tools
path-to-sdk/platform-tools
path-to-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin
  • On Ubuntu you can accomplish this using the following command (assuming the SDK and NDK have been unzipped to ~/src):

export ANDROID_NDK=~/src/android-ndk-r8
export ANDROID_SDK=~/src/android-sdk-linux
export PATH=$PATH:$ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools

Double-check the version numbers in the paths and adapt if required. If you are running a 64-bit version of the NDK, replace linux-x86 with linux-x86_64.

  • Prepare Android SDK:
    • run android in command line - this will show a GUI for preparing Android SDK
    • select Android 2.2 (API 8) and click 'Install N packages...' button - this will download SDK packages that support API 8

Compiling

We have recently switched from CMake to gradle for the Android build. CMake is no longer supported for the Android build, see the section on gradle for details.

Assuming you've followed the previous steps, you're probably setup to start compiling. Using CMake is the recommended way of compiling Navit for Android. Ensure that:

  • You have a java-jdk installed on your system. On Ubuntu:
sudo apt-get install openjdk-6-jdk

When multiple version of java are installed

update-java-alternatives -s java-1.6.0-openjdk-i386
  • On Ubuntu, ensure that ant1.8 is installed:
sudo apt-get install ant1.8
  • Make sure that you have saxonb-xslt installed:
sudo apt-get install libsaxonb-java

With cmake

  • Ensure that you have CMake 2.8 installed.
  • Create a build directory - this will be the directory into which the Android version of Navit will be built. Assume we've made one in ~/src as follows:
cd ~/src
mkdir android-build
  • Optional: Add a SOURCE_PATH environment variable to your system, pointing to the directory in which you checked out a copy of Navit. You can leave out this step, but make sure you change $SOURCE_PATH in the next steps to the actual path of the directory.
export SOURCE_PATH=~/src/navit-svn
  • Step into the build directory:
cd ~/src/android-build
  • Run CMake (ensure that you're in the build directory when you do this!):
cmake -DCMAKE_TOOLCHAIN_FILE=$SOURCE_PATH/Toolchain/arm-eabi.cmake -DCACHE_SIZE="(20*1024*1024)" -DAVOID_FLOAT=1 -DANDROID_PERMISSIONS="CAMERA" -DANDROID_API_VERSION=8 -DXSLT_PROCESSOR=/usr/bin/saxonb-xslt $SOURCE_PATH
  • Build the apk package:
make
make apkg
  • The previous commands have now created a package called Navit-debug.apk in the following directory:
~/src/android-build/navit/android/bin
  • Copy the package to your device (i.e. sd-card) and run it from there (through a file-manager, for example), or
  • If debug bridge (adb) is enabled run:
adb install navit/android/bin/Navit-debug.apk
  • Later, to reinstall already installed Navit app run:
adb install -r navit/android/bin/Navit-debug.apk

With cmake on Windows

  • install CMake 2.8 if you haven't already, add folder with exe to PATH
  • install MinGW or use MinGW included in the git windows folder (e.g. C:\msysgit\mingw\), add folder with exe to PATH
  • install saxon .NET version from http://sourceforge.net/projects/saxon/files/Saxon-HE/9.3/SaxonHE9-3-0-4N-setup.exe/download,
  • rename transform.exe to saxon.exe, add folder with exe to PATH
  • create a build dir (i.e. "mkdir android-build")
  • run from build dir ( replace $SOURCE_PATH):
cmake -DCMAKE_TOOLCHAIN_FILE=$SOURCE_PATH/Toolchain/arm-eabi.cmake -DCACHE_SIZE="(20*1024*1024)" -DAVOID_FLOAT=1 -DANDROID_PERMISSIONS="CAMERA" $SOURCE_PATH -G "MinGW Makefiles"
  • run MinGW32-make
  • run MinGW32-make apkg
  • install Navit-debug.apk (in <build path>/navit/android/bin) to your device
    • copy navit/android/bin/Navit-debug.apk to your device (i.e. sd-card) and run it from there or
    • if debug bridge (adb) is enabled run adb install navit/android/bin/Navit-debug.apk

With gradle

Note: this section is still under construction and may not yet be accurate!

These setup instructions are for a machine that does not have Android Studio installed. If you have Android Studio, some of them may not be necessary (or can be accomplished in a different way).

  • Make sure you have the following Android SDK components installed (if not, install them using Android SDK Manager):
    • Android SDK Platform-tools, version 25.0.3 or later
    • Android SDK Build-tools, version 27.0.3
  • Make sure you have the ANDROID_HOME environment variable set and pointing to your Android SDK dir. On Linux, this can be accomplished by adding the following line at the bottom of your .bashrc file in your home dir:
export ANDROID_HOME="$HOME/bin/android-sdk-linux_86" (use the actual path to your SDK install here)
You need to enter the command in your current shell as well in order for it to take effect there as well.
  • On Ubuntu 18.04 or later (or if your default JRE is Java 9 or later), edit $ANDROID_HOME/tools/bin/sdkmanager. Change line #31 to read:
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
  • Now run $ANDROID_HOME/tools/bin/sdkmanager "cmake;3.6.4111459" and accept the license agreement. (If the package is not found, run $ANDROID_HOME/tools/bin/sdkmanager --list | grep cmake and install the cmake version reported there.)
  • Make sure you have NDK version 12 or later (if you don’t, install it with $ANDROID_HOME/tools/bin/sdkmanager "ndk-bundle".)
  • If you did not install NDK through sdkmanager, make sure you have the ANDROID_NDK_HOME environment variable set and pointing to your Android NDK dir. (If not, add it as described above.)
  • Change to the Navit source dir and run ./gradlew build.

So far, two issues have been observed with the build:

  • Building vehicle/gpsd and map/garmin fails on Android. As a workaround, edit CMakeLists.txt , inserting the following two lines in the if(ANDROID) block (around line 710):
set_with_reason(vehicle/gpsd "Android detected" FALSE)
set_with_reason(map/garmin "Android detected" FALSE)
  • Bitmap resources are missing from the APK. A workaround is described here—integration of these steps into gradle is being worked on.

Testing an alternative build

If you want to try an alternative build (e.g. Jan's builds with alternative routing) you can do it by :

  • enable unsigned apk installation ( example guide )
  • installing an alternative apk ( e.g. an APK from CircleCI )
  • you will probably need an alternative map to match the application requirements ( such as this one )