Build From Source - Android

前提条件

设置编译环境

此章节解释了如何设置可用于开发适用于 AllJoyn™ 的 Android 应用程序的编译环境。此章节包含以下主题:

NOTE: 此章节描述的设置过程需要指定的工具版本。

安装 Android SDK

Android 软件开发包 (SDK) 为开发 Android 应用程序以及 Android 设备发送/接收应用程序提供了必备的工具。'adb'工具被用于:

对于 v15.04版本的 AllJoyn, 可由以下地址下载 r20 或更晚版本的 Android SDK:

http://developer.android.com/sdk/index.html

新版本的 Android SDK 会兼容早起版本的 AllJoyn. 如果您需要新版本的 Android SDK 请参阅对应 AllJoyn 版本的说明文档。

安装 SDK 的步骤如下:

http://developer.android.com/sdk/installing/index.html

安装 SDK 需要在您的系统中预装特定的软件包。详细信息请参见以下链接:

http://developer.android.com/sdk/requirements.html

在 SDK 安装完毕后,您必须安装您希望使用的 Android 平台支持包。参见:

http://developer.android.com/sdk/installing/adding-packages.html

AllJoyn v15.04版本架构使用16到22 levels 的 Android API. 注意,安装这些软件包会花费一些时间。

安装 Android NDK

Android 原生开发工具包(NDK)使开发者可以建造可由 Android(Java)应用程序调用的 Jave 原生库(JNI Libraries). 只有编写 Java 原生库时才会需 要 Android NDK. Android NDK 不要求使用 Android Java 绑定,但搭建 AllJoyn 则要求此绑定。

Android NDK 中的主要工具是'ndk-build',用来搭建 JNI 应用程序的原生库。

如需在15.04版本的 AllJoyn 上运行 Android JNI 应用程序,可以从 http://developer.android.com/tools/sdk/ndk/index.html 安装 9d 以及任意之前版 本的 NDK.

安装 NDK 可参考下载页中的指导。

为了顺利运行,NDK 要求以下软件包已预先安装到您的系统:

更多信息请参阅 NDK 的下载页。

Android IDEs

Android 集成开发环境的指导和下载可由如下链接获得:

http://developer.android.com/sdk/installing/index.html

下载 OpenSSL 头文件以及库(可选)

The AllJoyn framework optionally uses the OpenSSL crypto library. AllJoyn 15.04 and later have built-in crypto functions, but may be built with OpenSSL if needed.

If you build AllJoyn in the OpenSSL configuration, the prebuilt libcrypto library is needed to link AllJoyn applications. It can be downloaded directly from the Android device or emulator into the lib folder of the AllJoyn distribution. Attach the device (or launch the Android emulator), then run the following commands:

cd <alljoyn_dir>/lib
adb pull /system/lib/libcrypto.so libcrypto.so

The above command means:

adb pull

The library can also be built from the Android source repository. For details on building the Android source tree, see the Android source repository web site:

http://source.android.com/source/building.html

IMPORTANT: Be sure you pull the libcrypto.so library from the version of Android you are building for.

Building AllJoyn from Source for Android

For most developers, the SDK package available to download from https://allseenalliance.org/developers/download is sufficient for developing Android applications using AllJoyn. However, if you wish to obtain and compile AllJoyn from source, follow the directions in this section.

To compile AllJoyn from source, the following items are required:

Instructions for obtaining the Android SDK, Android NDK, and IDEs are in Setting Up the Programming Environment.

The Android source

The Android source (http://source.android.com) is required for building Android targets using OpenSSL. Google has detailed instructions for downloading and building Android source.

For a list of system requirements and instructions for obtaining the required tools, see http://source.android.com/source/initializing.html

For instructions on obtaining the Android Source Tree, see http://source.android.com/source/downloading.html

When running the repo init command specify the branch name for the Android release you are targeting. Branch names are listed at http://source.android.com/source/build-numbers.html#source-code-tags-and-builds

For instructions on building and running the build source, see http://source.android.com/source/building.html

Obtaining the AllJoyn source

If you followed the instructions in The Android source, you should have the repo tool and git installed on your system. Enter the following commands to get the AllJoyn source:

$ mkdir $HOME/alljoyn # for example
$ cd $HOME/alljoyn
$ repo init -u git://github.com/alljoyn/manifest.git
$ repo sync
$ repo start master --all

Building the AllJoyn framework for Android

At this point. you have all of the files and programs required to build the AllJoyn framework for Android. The following commands assume you have installed the Android NDK at /usr/local/android-ndk-r9d, you have downloaded and built the Android source, and it is located in $HOME/android-platform.

Use the following commands to build the AllJoyn framework for Android using builtin crypto:

$ export JAVA_HOME="/usr/lib/jvm/java-6-sun" # or java-5-sun
$ export CLASSPATH="/usr/share/java/junit.jar"
$ scons OS=android CPU=arm CRYPTO=builtin ANDROID_NDK=/usr/local/android-ndk-r9b
   ANDROID_SRC=$HOME/android-platform WS=off

To build using OpenSSL crypto functions:

$ export JAVA_HOME="/usr/lib/jvm/java-6-sun" # or java-5-sun
$ export CLASSPATH="/usr/share/java/junit.jar"
$ scons OS=android CPU=arm CRYPTO=openssl ANDROID_NDK=/usr/local/android-ndk-r9b
   ANDROID_SRC=$HOME/android-platform WS=off

It is possible to specify that the AllJoyn framework uses additional tools during the build process. For example, the AllJoyn framework can use Uncrustify to check white space compliance and Doxygen for producing API documentation for the C++ APIs. See Configuring the Build Environment (Linux Platform) for detailed instructions for installing these two tools.