Permalink
Browse files

docs: improve android things docs

Signed-off-by: Nicolas Oliver <dario.n.oliver@intel.com>
  • Loading branch information...
dnoliver committed Oct 6, 2017
1 parent b5efa0e commit e7b51f3b668cfcb39a732daae8247a9bc34a135e
Showing with 74 additions and 15 deletions.
  1. +2 −1 .gitignore
  2. +28 −7 docs/building.md
  3. +43 −6 scripts/build-android.sh
  4. +1 −1 src/peripheralman/CMakeLists.txt
View
@@ -1,4 +1,5 @@
build/
install/
# Object files
*.o
@@ -25,4 +26,4 @@ npm-debug.log
.scannerwork/
# Visual Studio Code
.vscode/
.vscode/
View
@@ -152,6 +152,7 @@ tar caf mraa.tar.bz2 cov-int
~~~~~~~~~~~~~
## Building Java bindings
Have JAVA_HOME set to JDK install directory. Most distributions set this from `/etc/profile.d/`
and have a way of switching between alternatives. We support both OpenJDK and Oracle's JDK.
On Arch Linux with OpenJDK 8 you'll have to set this yourself like this:
@@ -191,17 +192,37 @@ cmake -DRPM=ON -DCMAKE_INSTALL_PREFIX=/usr ..
## Building for the Android Things Peripheralmanager Client
Requirements:
* Android [Things Native Library](https://github.com/androidthings/native-libandroidthings)
* Android NDK >= 14b
* [Android Things Native Library](https://github.com/androidthings/native-libandroidthings) >= 0.5.1
* [Android NDK](https://developer.android.com/ndk/downloads/index.html) >= 14b
The [Things Native Library](https://github.com/androidthings/native-libandroidthings) contains a CMake find_package module
[FindAndroidThings.cmake](https://github.com/androidthings/native-libandroidthings/blob/master/FindAndroidThings.cmake). Make sure the directory containing this module is
added to the CMAKE_MODULE_PATH.
The [Android NDK](https://developer.android.com/ndk/downloads/index.html) contains a CMake find_package module
`FindAndroidThings.cmake`. Make sure the directory containing this module is
added to the `CMAKE_MODULE_PATH`.
### NDK r14b
### Android NDK r14b
~~~~~~~~~~~~~{.sh}
cmake -DBUILDSWIG=OFF -DBUILDARCH=PERIPHERALMAN -DANDROID_TOOLCHAIN_NAME=x86-i686 -DCMAKE_TOOLCHAIN_FILE=/path/to/android-ndk-r14b/build/cmake/android.toolchain.cmake -DCMAKE_MODULE_PATH=/path/to/native-libandroidthings ..
NDK_HOME="/path/to/android-ndk-r14b"
ANDROIDTHINGS_NATIVE_LIB="/path/to/native-libandroidthings-0.5.1-devpreview"
cmake -DBUILDSWIG=ON \
-DBUILDSWIGPYTHON=OFF \
-DBUILDSWIGNODE=OFF \
-DBUILDSWIGJAVA=ON \
-DANDROID_COMPILER_FLAGS_CXX='-std=c++11' \
-DANDROID_PIE=1 \
-DANDROID_PLATFORM=android-24 \
-DANDROID_STL_FORCE_FEATURES=ON \
-DANDROID_STL=c++_shared \
-DANDROID_TOOLCHAIN_NAME=x86-i686 \
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
-DCMAKE_FIND_ROOT_PATH=$NDK_HOME/platforms/android-24/arch-x86/ \
-DCMAKE_MODULE_PATH=$ANDROIDTHINGS_NATIVE_LIB \
-DCMAKE_TOOLCHAIN_FILE=$NDK_HOME/build/cmake/android.toolchain.cmake \
-DBUILDARCH=PERIPHERALMAN \
..
~~~~~~~~~~~~~
## Building with Docker
View
@@ -1,7 +1,44 @@
#!/usr/bin/env bash
PKG_CONFIG_LIBDIR=$NDK_HOME/platforms/android-24/arch-x86/usr/lib
#
# The script is used to build .aar packages for Mraa modules.
#
# Author: Nicolas Oliver <dario.n.oliver@intel.com>
#
# All environment variables used are passed from docker-compose.
# Those environment variables can also be declared in the host,
# and this script can be used to build .aar packages without using
# docker-compose.
#
# Environment variables:
# - NDK_HOME - Path to Android NDK install folder. i.e. /opt/android-ndk-r14b/
# - ANDROIDTHINGS_NATIVE_LIB - Path to Android Things library install folder. i.e /opt/native-libandroidthings-0.5.1-devpreview/
# - JAVA_HOME - Path to Java install folder. i.e. /usr/lib/jvm/java-8-openjdk-amd64/
#
set -e
# Check required environment variables and exit if they are not set
function check_environment {
VAR_NAME=$1
VAR_VALUE=$2
# Check required parameters
VAR_NAME=${VAR_NAME:?value not provided}
# Chek if variable is set
if [ -z "${VAR_VALUE}" ]; then
echo "Required environment variable ${VAR_NAME} is not defined. Exiting..."
exit 1;
else
echo "Required environment variable ${VAR_NAME} is set."
fi
}
# Check for required environment variables
check_environment "NDK_HOME" ${NDK_HOME}
check_environment "ANDROIDTHINGS_NATIVE_LIB" ${ANDROIDTHINGS_NATIVE_LIB}
check_environment "JAVA_HOME" ${JAVA_HOME}
PKG_CONFIG_LIBDIR="$NDK_HOME/platforms/android-24/arch-x86/usr/lib"
PKG_CONFIG_SYSROOT_DIR=""
export PKG_CONFIG_LIBDIR
# Run cmake
cmake \
@@ -11,6 +48,7 @@ cmake \
-DANDROID_STL_FORCE_FEATURES=on \
-DANDROID_STL=c++_shared \
-DANDROID_TOOLCHAIN_NAME=x86-i686 \
-DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
@@ -50,7 +88,7 @@ make -Cbuild install
# Anotate the .java src from doxygen
echo src/mraa.i > build/swig.i.list
# TODO: install doxy port tool
#doxyport \
#../doxy/doxyport \
# build/swig.i.list \
# -s api,api/mraa \
# -d build/src/java \
@@ -61,7 +99,6 @@ echo src/mraa.i > build/swig.i.list
# Copy the STL implementation into the build/src directory
cp $NDK_HOME/sources/cxx-stl/llvm-libc++/libs/x86/libc++_shared.so build/src/
# Template for res/values/values.xml in aar
values_xml='<?xml version="1.0" encoding="utf-8"?><resources><string name="app_name">XXX_LIBRARY</string></resources>'
@@ -122,10 +159,10 @@ jar cf $PKG_BUNDLE_DIR/$LIB_NAME-$VERSION-javadoc.jar $LIB_NAME-javadoc/*
jar cf $PKG_BUNDLE_DIR/$LIB_NAME-$VERSION-sources.jar src/java/*.java
# HACK - mraa pom file groupId is io.mraa (AT is io.mraa.at)
perl -p -i -e 's/(groupId>)(.*?)(<\/groupId)/\1io.mraa.at\3/' src/java/$LIB_NAME-$VERSION.pom
perl -p -i.bak -e 's/(groupId>)(.*?)(<\/groupId)/\1io.mraa.at\3/' src/java/$LIB_NAME-$VERSION.pom
# HACK - mraa pom file packaging is 'jar' (convert this to 'aar')
perl -p -i -e 's/(packaging>)(.*?)(<\/packaging)/\1aar\3/' src/java/$LIB_NAME-$VERSION.pom
perl -p -i.bak -e 's/(packaging>)(.*?)(<\/packaging)/\1aar\3/' src/java/$LIB_NAME-$VERSION.pom
# Copy pom file
cp src/java/$LIB_NAME-$VERSION.pom $PKG_BUNDLE_DIR
@@ -1,3 +1,3 @@
message (INFO " - Adding Peripheral Manager platform")
message (STATUS "INFO - Adding Peripheral Manager platform")
set (mraa_LIB_PLAT_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO}
${mraa_LIB_PERIPHERALMAN_SRCS_NOAUTO} PARENT_SCOPE)

0 comments on commit e7b51f3

Please sign in to comment.