如何使用 arm-linux-androideabi 编译器为Android编译并构建 iotivity-lite (https://github.com/iotivity/iotivity-constrained)?我对 Makefile 的更改和设置感兴趣。
答案 0 :(得分:1)
在Makefile中以自述格式提供了有关构建Android Iotivity-lite的说明。
转到[iotivity-lite]/port/android/Makefile
从该制作文件:
Port for native Android compilation (without Java).
Tested NDK versions:
API Android version
19 4.4
21 5.0
23 6.0
24 7.0
API version 24 is closest to regular Linux so far.
With API 24 the Android port is almost identical to the Linux port
except for the removal of the unsupported pthread_cancel and that
the IP adapter assures that interfaces have multicast and broadcast
enabled to avoid 3G/4G/5G interfaces.
It is expected that higher versions then API 24 should work without any
further modifications.
Testing compilations on non-rooted Android phones:
- Enable USB debugging on your phone.
- Install ADB or Android Studio
- adb start-server
Your phone should query now if you trust the computer. Hit OK.
- adb push simpleclient /data/local/tmp/
Most likely your phone gives you in /data/local some more permissions
Non-rooted devices are a bit restrictive what you can do in the file system.
- adb shell
- cd /data/local/tmp
- chmod 755 simpleclient
It was observed that the file has read-write permissions only after the upload
on Android 7.
- In a different terminal window start simpleserver on your developer box.
- ./simpleclient
- Kill client with Ctrl-C or Ctrl-\
- exit
- *** DISABLE USB debugging!!! *** (security issue if left on)
Note: On regular Android phones the server versions will not be found
(ie. simpleserver will not be discovered). But the clients
should work.
Download NDK: https://developer.android.com/ndk/downloads/index.html
Unzip downloaded package.
Choose architecture and API level.
cd <NDK>/build/tools
./make_standalone_toolchain.py --arch <architecture> --api <level> --install-dir <path>
For example: ./make_standalone_toolchain.py --arch arm --api 23 --install-dir ~/android-arm-23
This makefile uses then the NDK in <install-dir>.
For further setup see: https://developer.android.com/ndk/guides/standalone_toolchain.html
Either set ANDROID_API and ANDROID_BASE in this makefile
or invoke like this: make NDK_HOME=/opt/android-ndk ANDROID_API=24
下载NDK之后,请确保您运行make_standalone_toolchain.py
脚本。
要为arm构建调试版本,我最终运行以下命令。
make NDK_HOME=~/Android/android-arm-23/ ANDROID_API=23 DYNAMIC=1 TCP=1 SECURE=1 DEBUG=1
构建说明仅限于构建必须使用adb shell运行的C代码。
在撰写本文时,有一个单独的分支正在使用JNI向Java公开IoTivity-lite。这是swig分支。
有一个自述文件,其中包含构建Java API的说明以及一些示例程序。
README instructions for swig branch
swig分支仍在积极开发中,但应该足够稳定以满足您的需求。