Skip to content

Commit 97feedc

Browse files
qh-huangesteve
authored andcommitted
update README.md for Android build on OSX (#40)
1 parent 7f28063 commit 97feedc

1 file changed

Lines changed: 45 additions & 14 deletions

File tree

README.md

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ Make sure you have Gradle 3.2 (or later) installed. Ubuntu 16.04 ships with Grad
7474
$ sudo add-apt-repository ppa:cwchien/gradle
7575
$ sudo apt install -y gradle
7676
```
77+
For OSX, use homebrew command to install gradle:
78+
79+
```
80+
$ brew install gradle
81+
```
82+
83+
For OSX users, there some compatibily issues have been reported between gradle 3.x and Java 9. Currently only the combination of Gradle 3.x + Java 8 has been tested successfully. Make sure to use install and use Java 8 for the building process:
84+
85+
```
86+
$ brew tap caskroom/versions
87+
$ brew cask install java8
88+
$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/1.8.0.jdk/Contents/Home
89+
```
7790

7891
> Note: On Windows, you may use `choco install -y gradle`
7992
@@ -102,36 +115,54 @@ The Android setup is slightly more complex, you'll need the SDK and NDK installe
102115

103116
Make sure to download at least the SDK for Android Lollipop (or greater), the examples require the API level 21 at least and NDK 14.
104117

105-
You may download the Android NDK from [the official](https://developer.android.com/ndk/downloads/index.html) website, let's assume you've downloaded 15c (the latest stable version as of 2017-11-07) and you unpack it to `~/android_ndk`
118+
You may download the Android NDK from [the official](https://developer.android.com/ndk/downloads/index.html) website, let's assume you've downloaded 16b (the latest stable version as of 2018-04-28) and you unpack it to `~/android_ndk`
106119

107120
We'll also need to have the [Android SDK](https://developer.android.com/studio/#downloads) installed, for example, in `~/android_sdk` and set the `ANDROID_HOME` environment variable pointing to it.
108121

109122
Although the `ros2_java_android.repos` file contains all the repositories for the Android bindings to compile, we'll have to disable certain packages (`python_cmake_module`, `rosidl_generator_py`, `test_msgs`) that are included the repositories and that we either don't need or can't cross-compile properly (e.g. the Python generator)
110123

111124
```
112-
export ANDROID_HOME=$HOME/android_sdk
113-
mkdir -p ~/ros2_android_ws/src
114-
cd ~/ros2_android_ws
125+
# define paths
126+
ROOT_DIR = ${HOME}
127+
AMENT_WORKSPACE=${ROOT_DIR}/ament_ws
128+
ROS2_ANDROID_WORKSPACE=${ROOT_DIR}/ros2_android_ws
129+
130+
# pull and build ament
131+
mkdir -p ${AMENT_WORKSPACE}/src
132+
cd ${AMENT_WORKSPACE}
133+
wget https://raw.githubusercontent.com/esteve/ament_java/master/ament_java.repos
134+
vcs import ${AMENT_WORKSPACE}/src < ament_java.repos
135+
src/ament/ament_tools/scripts/ament.py build --symlink-install --isolated
136+
137+
# android build configuration
138+
export PYTHON3_EXEC="$( which python3 )"
139+
export ANDROID_ABI=armeabi-v7a
140+
export ANDROID_NATIVE_API_LEVEL=android-21
141+
export ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-clang
142+
143+
# pull and build ros2 for android
144+
mkdir -p ${ROS2_ANDROID_WORKSPACE}/src
145+
cd ${ROS2_ANDROID_WORKSPACE}
115146
wget https://raw.githubusercontent.com/esteve/ros2_java/master/ros2_java_android.repos
116-
vcs import ~/ros2_android_ws/src < ros2_java_android.repos
117-
. ~/ament_ws/install_isolated/local_setup.sh
147+
vcs import ${ROS2_ANDROID_WORKSPACE}/src < ros2_java_android.repos
148+
source ${AMENT_WORKSPACE}/install_isolated/local_setup.sh
118149
ament build --isolated --skip-packages test_msgs \
119150
--cmake-args \
120-
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
121-
-DCMAKE_TOOLCHAIN_FILE=$HOME/android_ndk/android-ndk-r15c/build/cmake/android.toolchain.cmake \
151+
-DPYTHON_EXECUTABLE=${PYTHON3_EXEC} \
152+
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
122153
-DANDROID_FUNCTION_LEVEL_LINKING=OFF \
123-
-DANDROID_NATIVE_API_LEVEL=android-21 \
124-
-DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-clang \
154+
-DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_API_LEVEL} \
155+
-DANDROID_TOOLCHAIN_NAME=${ANDROID_TOOLCHAIN_NAME} \
125156
-DANDROID_STL=gnustl_shared \
126-
-DANDROID_ABI=armeabi-v7a \
127-
-DANDROID_NDK=$HOME/android_ndk/android-ndk-r15c \
157+
-DANDROID_ABI=${ANDROID_ABI} \
158+
-DANDROID_NDK=${ANDROID_NDK} \
128159
-DTHIRDPARTY=ON \
129160
-DCOMPILE_EXAMPLES=OFF \
130-
-DCMAKE_FIND_ROOT_PATH="$HOME/ament_ws/install_isolated;$HOME/ros2_android_ws/install_isolated" \
161+
-DCMAKE_FIND_ROOT_PATH="$AMENT_WORKSPACE/install_isolated;$ROS2_ANDROID_WORKSPACE/install_isolated" \
131162
-- \
132163
--parallel \
133164
--ament-gradle-args \
134-
-Pament.android_stl=gnustl_shared -Pament.android_abi=armeabi-v7a -Pament.android_ndk=$HOME/android_ndk/android-ndk-r15c --
165+
-Pament.android_stl=gnustl_shared -Pament.android_abi=$ANDROID_ABI -Pament.android_ndk=$ANDROID_NDK --
135166
```
136167

137168
You can find more information about the Android examples at https://github.com/esteve/ros2_android_examples

0 commit comments

Comments
 (0)