Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic android app with ros master selection #100

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2230114
Using wstool to download libraries instead of custom script.
Jan 2, 2019
46def10
Removing download auxiliary functions.
Jan 2, 2019
6d8323a
Renaming ndk.rosinstall --> ros.rosinstall.
Jan 2, 2019
90c2ef2
Renaming scripts for consistency.
Jan 2, 2019
514317a
Merge branch 'kinetic' into jubeira/wstool_libs
Jan 2, 2019
bcccc21
Applying all patches in source_patches folder; no need of listing the…
Jan 2, 2019
a195fe6
Clearer format when logging with rosconsole. Some other nits modified
ivanpauno Jan 7, 2019
adbe36c
Merge pull request #77 from Intermodalics/jubeira/wstool_libs
Jan 7, 2019
5c65f45
Merge branch 'kinetic' into jubeira/automatic_patches
Jan 7, 2019
ec542ce
Corrected extra colon when logging with rosconsole
ivanpauno Jan 7, 2019
8736cdf
Merge pull request #82 from Intermodalics/fix/rosconsole-logging-format
ivanpauno Jan 7, 2019
a0ce17c
Pluginlib support always enabled; removing flag.
Jan 8, 2019
74bb4b6
Moving patches one level up; replacing toolchain patch for a cmake fi…
Jan 8, 2019
a7d8834
Merge pull request #79 from Intermodalics/jubeira/automatic_patches
Jan 8, 2019
2c755cd
docker: use cmake 3.6.4111459 provided by the Android SDK
meyerj Jan 10, 2019
0666975
get_system_dependencies: fix permission errors when copying rospkg to…
meyerj Jan 10, 2019
c784b53
Fix for toolchain flags.
Jan 10, 2019
25d86b2
Merge pull request #88 from Intermodalics/fix/copying-rospkg-on-secon…
meyerj Jan 10, 2019
0a8cc65
Merge pull request #86 from Intermodalics/docker/use-android-sdk-cmake
meyerj Jan 10, 2019
14e9d60
Fix standalone usage of build_catkin_workspace.sh
meyerj Jan 10, 2019
f6ab480
Merge pull request #89 from Intermodalics/fix/build_catkin_workspace-…
Jan 11, 2019
c034ca5
Removing unnecessary code in android toolchain cmake.
Jan 11, 2019
bb73ee8
Fixing default workdir and command in dockerfile.
Jan 11, 2019
b295e0b
Merge pull request #87 from Intermodalics/fix/toolchain_flags_fix
meyerj Jan 11, 2019
11f4d35
Merge pull request #90 from Intermodalics/fix/dockerfile_default_command
meyerj Jan 11, 2019
0604ee5
docker/run.sh: apply extra arguments to docker run instead of bash
meyerj Jan 16, 2019
b7dcd19
pluginlib_helper: also include implicit (indirect) dependencies
meyerj Jan 16, 2019
a121628
ros.rosinstall: uncomment many Python packages because other packages…
meyerj Jan 16, 2019
5186239
docker: fix CMD syntax that requires double quotes
meyerj Jan 16, 2019
684bdc8
docker: split command line at double dash and forward remainings argu…
meyerj Jan 16, 2019
b4f3e1d
Ignoring packages that are required by pluginlib support build, but a…
Jan 17, 2019
0a1f092
Revert "Ignoring packages that are required by pluginlib support buil…
Jan 17, 2019
1ed3b4a
Patches for python_orocos_kdl and tf2_py: don't do anything but insta…
Jan 17, 2019
a292437
Adjusting patches for tf2_py and python_orocos_kdl.
Jan 18, 2019
96aea07
Fixing issue with rosinstall file for tf2.
Jan 18, 2019
000fb17
Adding catkin as buildtool for python_orocos_kdl.
Jan 18, 2019
61f965b
patches: fixed linking to SDL library in map_server
meyerj Jan 22, 2019
7c809a1
ros.rosinstall: fixed yaml syntax error (introduced in a121628ca059be…
meyerj Jan 22, 2019
469bee0
Merge pull request #95 from Intermodalics/fix-map_server-linking
meyerj Jan 22, 2019
1f2871d
Merge pull request #94 from Intermodalics/fix/pluginlib-find-implicit…
meyerj Jan 22, 2019
a039aef
Merge pull request #92 from Intermodalics/docker-run-with-arguments
meyerj Jan 22, 2019
5081322
Merge branch 'kinetic' into catkinizing-all-the-examples
ivanpauno Jan 22, 2019
7714039
Basic app to connect to ros master
ivanpauno Jan 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions android.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
return()
endif(ANDROID_NDK_TOOLCHAIN_INCLUDED)
include($ENV{ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake)

## Build without debug symbols in Release mode and add RelWithDebInfo mode.
foreach(_var ANDROID_COMPILER_FLAGS CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_ASM_FLAGS)
string(REPLACE "-g " "" ${_var} "${${_var}}")
set(${_var}_DEBUG "-g ${${_var}_DEBUG}")
set(${_var}_RELWITHDEBINFO "-g ${${_var}_RELEASE}")
endforeach()
unset(_var)

if(ANDROID_TOOLCHAIN STREQUAL clang)
list(APPEND ANDROID_COMPILER_FLAGS_RELWITHDEBINFO -fno-limit-debug-info)
endif()
25 changes: 25 additions & 0 deletions apply_patches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Abort script on any failures
set -e

my_loc="$(cd "$(dirname $0)" && pwd)"
source $my_loc/config.sh
source $my_loc/utils.sh

if [ $# != 2 ] || [ $1 == '-h' ] || [ $1 == '--help' ]; then
echo "Usage: $0 patch_prefix output_prefix"
echo " example: $0 /home/user/ros_android/patches /home/user/my_workspace/output"
exit 1
fi

patch_prefix=$1
output_prefix=$2

echo
echo -e '\e[34mApplying patches.\e[39m'
echo

for patch_file in $patch_prefix/*.patch; do
apply_patch $patch_file -d $output_prefix
done
2 changes: 1 addition & 1 deletion build_cpp.sh → build_catkin_workspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ if [ "$WORKSPACE" = "" ]; then
exit 1
fi

: ${RBA_TOOLCHAIN:=$ANDROID_NDK/build/cmake/android.toolchain.cmake}
: ${RBA_TOOLCHAIN:=$my_loc/android.toolchain.cmake}

# get the prefix path
prefix=$(cd $PREFIX_PATH && pwd)
Expand Down
4 changes: 0 additions & 4 deletions config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ export ANDROID_PLATFORM=android-24
# Enable this value for debug build
#CMAKE_BUILD_TYPE=Debug
CMAKE_BUILD_TYPE=Release

# Enable this if you need to use pluginlib in Android.
# The plugins will be statically linked
use_pluginlib=1
289 changes: 43 additions & 246 deletions do_everything.sh

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build.sh
Dockerfile
.dockerignore
README.md
run.sh
14 changes: 6 additions & 8 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ RUN apt-get update && apt-get install -y openjdk-8-jdk
RUN wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
RUN unzip sdk-tools-linux-4333796.zip -d /opt/android/sdk
RUN yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses
RUN $ANDROID_HOME/tools/bin/sdkmanager "build-tools;26.0.2" "platform-tools" "platforms;android-26" --sdk_root=/opt/android/sdk
ENV PATH /opt/android/sdk/tools:/opt/android/sdk/platform-tools:$PATH

# Install CMake 3.6
WORKDIR /opt
RUN wget https://cmake.org/files/v3.6/cmake-3.6.3-Linux-x86_64.sh && chmod +x cmake-3.6.3-Linux-x86_64.sh
RUN yes | sh '/opt/cmake-3.6.3-Linux-x86_64.sh'
RUN ln -s /opt/cmake-3.6.3-Linux-x86_64/bin/* -t /usr/local/bin
RUN $ANDROID_HOME/tools/bin/sdkmanager "build-tools;26.0.2" "platform-tools" "platforms;android-26" "cmake;3.6.4111459" --sdk_root=/opt/android/sdk
ENV PATH /opt/android/sdk/tools:/opt/android/sdk/platform-tools:/opt/android/sdk/cmake/3.6.4111459/bin:$PATH

# Install Python libraries
RUN apt-get install python-lxml -y
Expand All @@ -46,3 +40,7 @@ ENV PATH /usr/lib/ccache:$PATH

# Clear entrypoint (do not source /opt/ros/kinetic)
ENTRYPOINT []

VOLUME /opt/ros_android
WORKDIR /opt/ros_android
CMD ["bash"]
2 changes: 1 addition & 1 deletion docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
IMAGE=android_ndk

pushd "$( dirname "${BASH_SOURCE[0]}" )"
docker build -t ${IMAGE} .
docker build -t ${IMAGE} "$@" .
popd
32 changes: 26 additions & 6 deletions docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@ SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
REPO_ROOT=$SCRIPTPATH/../
IMAGE=android_ndk

if [ "$#" == 0 ]; then
EXTRA_ARGS="bash"
else
EXTRA_ARGS="bash -c \"$@\""
fi
DOCKEROPTS=()
while [ $# -gt 0 ]; do
case "$1" in
--help)
# print usage
echo "Usage: $0 [DOCKER OPTIONS] [-- [COMMAND]]"
echo
echo "Docker options:"
docker run --help | tail -n +7
exit 0
;;
--)
# end-of-options: all arguments after the -- will be interpreted as a command to run inside the container.
shift
break
;;
*)
# collect docker options
DOCKEROPTS+=("$1")
shift
;;
esac
done

set -x
docker run \
-v ${REPO_ROOT}:/opt/ros_android \
--privileged \
-it \
${IMAGE} "${EXTRA_ARGS}"
"${DOCKEROPTS[@]}" \
${IMAGE} "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@ project(hello_ros)

find_package(catkin REQUIRED COMPONENTS roscpp std_msgs rosconsole)

include_directories(${catkin_INCLUDE_DIRS})
include_directories(include ${catkin_INCLUDE_DIRS})

# build native_app_glue as a static lib
set(${CMAKE_C_FLAGS}, "${CMAKE_C_FLAGS}")
add_library(native_app_glue STATIC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
# set(${CMAKE_C_FLAGS}, "${CMAKE_C_FLAGS}")
# add_library(native_app_glue STATIC
# ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

# now build app's shared lib
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -Wall -Werror")

# Export ANativeActivity_onCreate(),
# Refer to: https://github.com/android-ndk/ndk/issues/381.
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
# set(CMAKE_SHARED_LINKER_FLAGS
# "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")

add_library(native-activity SHARED main.cpp)
add_library(native-activity SHARED src/main/jni/com_ros_example_hello_ros_MainActivity_RosThread.cpp src/main/cpp/main.cpp src/main/cpp/main_thread.cpp)

target_include_directories(native-activity PRIVATE
${ANDROID_NDK}/sources/android/native_app_glue)
# target_include_directories(native-activity PRIVATE
# ${ANDROID_NDK}/sources/android/native_app_glue)

# add lib dependencies
target_link_libraries(native-activity
android
native_app_glue
# native_app_glue
${catkin_LIBRARIES}
log
# log
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 28

defaultConfig {
applicationId = 'com.example.hello_ros'
applicationId = 'com.ros.example.hello_ros'
minSdkVersion 24
targetSdkVersion 24
externalNativeBuild {
Expand Down Expand Up @@ -32,7 +32,7 @@ android {
}
externalNativeBuild {
cmake {
path 'src/main/cpp/CMakeLists.txt'
path 'CMakeLists.txt'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef __ROS_ANDROID_MAIN_THREAD_H__
#define __ROS_ANDROID_MAIN_THREAD_H__

#include <memory>
#include <mutex>
#include <string>

namespace ros_android {
class MainThread {
public:
MainThread();
explicit MainThread(std::string);
virtual ~MainThread() = 0;

typedef std::shared_ptr<MainThread> Ptr;
static Ptr Instance(void);

virtual void run() = 0;
virtual void stop() = 0;
bool check_ros_master(std::string master_ip, std::string my_ip);
private:
std::string node_name;

static std::mutex s_instance_mutex;
static Ptr s_instance;
};
} // namespace ros_android

#define MY_ROS_ANDROID_MAIN_THREAD(class_name) \
ros_android::MainThread::Ptr ros_android::MainThread::Instance() { \
Ptr instance = s_instance; \
if (!instance) { \
std::lock_guard<std::mutex> lock(s_instance_mutex); \
if (!s_instance) { \
instance = s_instance = std::make_shared<class_name>(); \
} \
} \
return instance; \
}
#endif // #ifndef __ROS_ANDROID_MAIN_THREAD_H__
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hello_ros"
package="com.ros.example.hello_ros"
android:versionCode="1"
android:versionName="1.0">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

<!-- This .apk has no Java code itself, so set hasCode to false. -->
<application
android:allowBackup="false"
android:fullBackupContent="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:hasCode="false">
android:hasCode="true">

<!-- Our activity is the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. -->
<activity android:name="android.app.NativeActivity"
<activity android:name="com.ros.example.hello_ros.MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"
android:value="native-activity"/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand All @@ -33,4 +26,3 @@
</application>

</manifest>
<!-- END_INCLUDE(manifest) -->
Loading