ros2-java / ros2_android_examples

Example Android apps for the ROS2 Java bindings
Apache License 2.0
36 stars 5 forks source link

Building examples out-of-workspace #8

Open ghost opened 6 years ago

ghost commented 6 years ago

How can these examples (or, indeed, any project that uses ros2_android) be built without existing within the ros2_android workspace?

I have ament_java and ros2_android built in their own directories, as per the instructions here: https://github.com/esteve/ros2_java

Having sourced {ament_java|ros2_android}/install/local_setup.bash, I then want to build these examples.

I've tried:

My guess is that I'm supposed to be copying these examples into the ros2_android workspace, and building the lot. But I really don't want to embed my project in the directory structure of one of its dependencies, that feels very backwards.

Edit: To answer the obvious question, yes the correct version of ament (the one from ament_java) is being run

ghost commented 6 years ago

It seems to be a problem with ament not parsing the package.xml properly.

For example, if the main workspace has been built in ~/3rdparty/ros2_android, and we have a directory ~/ros2_listener_android containing src/ros2_listener_android/... then

cd ~/ros2_listener
ament build --directory ../3rdparty/ros2_android --ament-gradle-args -Pament.android_stl=gnustl_shared -Pament.android_abi=armeabi-v7 -Pament.android_ndk=/home/johnmark/Android/Skd/ndk-bundle --

will try and run the underlying gradle command

/opt/gradle/gradle-4.8/bin/gradle -Pament.source_space=/home/johnmark/ros2_listener_android/src/ros2_listener_android -Pament.build_space=/home/johnmark/ros2_listener_android/build/ros2_listener_android -Pament.install_space=/home/johnmark/ros2_listener_android/install -Pament.dependencies= -Pament.build_tests=False -Pament.package_manifest.name=ros2_listener_android -Pament.exec_dependency_paths_in_workspace= -Pament.gradle_recursive_dependencies=False -Pament.gradle_isolated=False --directory ../3rdparty/ros2_android -Pament.android_stl=gnustl_shared -Pament.android_abi=armeabi-v7 -Pament.android_ndk=/home/johnmark/Android/Skd/ndk-bundle -Pament.android_variant=release assemble --stacktrace'

which fails with

> Task :copyNativeLibs FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':copyNativeLibs'.
> path may not be null or empty string. path=''

Note how the android.dependencies and android.exec_dependency_paths_in_workspace arguments given to gradle are empty.

Compare that to running

cd ~/ros2_android
ament build --only-packages ros2_listener_android --ament-gradle-args -Pament.android_stl=gnustl_shared -Pament.android_abi=armeabi-v7 -Pament.android_ndk=/home/johnmark/Android/Skd/ndk-bundle --

where the android.dependencies and android.exec_dependency_paths_in_workspace are filled in with the correct list of paths from ~/ros2_android.

If I manually pass in those same arguments when building in ~/ros2_listener_android then the build works, but it would (clearly) be much nicer if those arguments were inferred for me by ament.

ghost commented 6 years ago

Reproducible example: https://gist.github.com/johnmarkwayve/5764dc0f24f71e54a4f85dd9fecd615c