基本要求
为Android构建核心OpenDDS主机库,您需要:
- 一个同时支持OpenDDS和Android NDK的开发系统。
- Windows和Linux已经过测试,但macOS也应该可以工作。
- Android原生开发工具包(NDK)r18或更高。您可以从android.com单独下载,也可以使用Android Studio附带的SDK管理器。如果您使用SDK管理器,它位于$SDK/ndk-bundle.
- 我们将假定您对OpenDDS和Android开发有一定的了解,但是将假定更多的OpenDDS知识将比Android知识更多。
- Windows用户应该看到“在Windows上构建”对于他们可能需要额外的要求。
除此之外,使用可选依赖项构建OpenDDS也有在各自章节中列出的附加要求。
这个“在Android应用程序中使用OpenDDS”部分假设使用Android Studio,不过,如果稍加调整,在使用androidsdk时也能正常工作。
在Windows上构建
如果使用的是Windows Subsystem for Linux(WSL)、Docker或其他任何工具像这样,当你完成了指南,你可以复制结果从虚拟环境到Windows的库以及它们可以在其中使用的库Android Studio将在Linux上使用。你也可以跳过剩下的本节及任何Windows用户:通知。
如果你想在没有WSL或Docker的Windows平台上构建Android的OpenDDS,跟随Windows用户:通知。
除了OpenDDS和Android NDK,您还需要以下内容软件:
-
- 为Android构建OpenDDS及其依赖项需要通常在Unix系统上提供的实用程序。本指南将使用MSYS2,它提供了许多这样的工具。从安装MSYS2官方网站https://www.msys2.org把它设置好。
- 按照msys2.org网站上的所有安装/更新步骤操作。
-
使用visualstudio生成OpenDDS主机工具
最后,由于ACE的gnuacemake脚本在Windows上不能正确处理这些路径。这个指NDK、toolchain、MSYS2、JDK、OpenDDS源代码、OpenDDS主机工具等。路径中不能包含任何空格。
Building OpenDDS for Android
As Android targets multiple architectures and has many versions, an architecture and minimum API version to use will have to be decided. As of writing this page lists Android version numbers and their corresponding API versions. You will have to do a separate build for each architecture if you want to build OpenDDS for multiple architectures.
A standalone toolchain is required and can be generated by using $NDK/build/tools/make_standalone_toolchain.py
. For example, to create a toolchain for 32-bit ARM Android 7.0 "Nougat" and later:
$NDK/build/tools/make_standalone_toolchain.py --arch arm --api 24 --install-dir $TOOLCHAIN
Windows Users: Android NDK includes Python in prebuilt\windows-x86_64\bin
for 64-bit Windows NDKs. For the example above, assuming %NDK%
is the location of the NDK and %TOOLCHAIN%
is the desired location of the toolchain, run this command instead:
%NDK%\prebuilt\windows-x86_64\bin\python.exe %NDK%\build\tools\make_standalone_toolchain.py --arch arm --api 24 --install-dir %TOOLCHAIN%
Once a toolchain is obtained, OpenDDS can be configured to cross compile for Android by passing --target=android
and --macros=ANDROID_ABI=<ARCH>
to the OpenDDS configure script. The --arch
argument for make_standalone_toolchain.py
and --macros=ANDROID_ABI=<ARCH>
argument for the configure script must match according to this table:
--arch | ANDROID_ABI | $ABI_PREFIX | Description |
---|---|---|---|
arm | armeabi-v7a | arm-linux-androideabi | 32-bit ARM |
arm | armeabi-v7a-with-neon | arm-linux-androideabi | 32-bit ARM with NEON |
arm64 | arm64-v8a | aarch64-linux-android | 64-bit ARM |
x86 | x86 | i686-linux-android | 32-bit x86 |
x86_64 | x86_64 | x86_64-linux-android | 64-bit x86 |
For example, to build OpenDDS with the toolchain generated in the previous example, we can use armeabi-v7a
1.
NOTE: If you want to use Java or DDS Security, read those sections before configuring and building OpenDDS.
./configure --doc-group --target=android --macros=ANDROID_ABI=armeabi-v7a PATH=$PATH:$TOOLCHAIN/bin make # Pass -j/--jobs with an appropriate value or this'll take a while...
Windows Users: The commands for this are similar with these exceptions:
-
--host-tools
with the location of the OpenDDS host tools that were built using Visual Studio must be passed toconfigure
. -
In addition to the Android toolchain, you will also need MSYS2 utilities in your
%PATH%
. -
Make sure these commands in a new Visual Studio command prompt that is different from where you configured the host tools.
configure --doc-group --target=android --macros=ANDROID_ABI=armeabi-v7a --host-tools=%HOST_DDS% set PATH=%PATH%;%TOOLCHAIN%\bin;C:\msys64\usr\bin ren %ACE_ROOT%\VERSION VERSION.txt ren %TAO_ROOT%\VERSION VERSION.txt make REM Pass -j/--jobs with an appropriate value or this'll take a while...