This directory contains an Android Studio project for CHIPTool.
CHIPTool features: Scan a CHIP QR code and display payload information to the user Send echo requests to the CHIP echo server Send on/off cluster requests to a CHIP device
===========================================
Steps to build CHIP for Android apps
Pre-conditions: Have Android NDK downloaded to your machine. Set $ANDROID_NDK_HOME environment variable to point to the NDK package is downloaded.
Checkout the CHIP repo
In commandline / Terminal, ‘cd’ into the top CHIP directory
Run ‘./bootstrap’
Exit out of the checked out CHIP repo directory and using ‘mkdir [some-dir]’ create a new empty one where you want the generated output files to go.
‘cd’ into this newly created directory
Export the following variables
ABIs that can be used as TARGET:
ABI | Triple |
---|---|
armeabi-v7a | armv7a-linux-androideabi |
arm64-v8a | aarch64-linux-android |
x86 | i686-linux-android |
x86-64 | x86_64-linux-android |
NDK OS Variants:
NDK OS Variant | Host Tag |
---|---|
macOS | darwin-x86_64 |
Linux | linux-x86_64 |
32-bit Windows | windows |
64-bit Windows | windows-x86_64 |
OS_VARIANT=darwin-x86_64 // Specify OS variant corresponding to system export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$OS_VARIANT export TARGET=aarch64-linux-android // Use desired ABI export API=21 export AR=$TOOLCHAIN/bin/$TARGET-ar export AS=$TOOLCHAIN/bin/$TARGET-as export CC=$TOOLCHAIN/bin/$TARGET$API-clang export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++ export LD=$TOOLCHAIN/bin/$TARGET-ld export RANLIB=$TOOLCHAIN/bin/$TARGET-ranlib export STRIP=$TOOLCHAIN/bin/$TARGET-strip export JNI_INCLUDE_DIRS=$ANDROID_NDK_HOME/sysroot/usr/include
Note: Regardless of where JAVA_HOME points, always use the JNI headers from the Android NDK, and only include the top-most directory (include), not the system directory (include/linux). Because the NDK mixes the JNI headers in with the linux headers, listing the system directory in the -I flags will result in strange compilation errors. And unlike the standard Java jni.h, the jni.h that comes with the Android NDK does not depend on any system-specific JNI header files (e.g. jni_md.h). Thus only the top-level include directory is needed.
Then run ‘../connectedhomeip/configure --host=$TARGET --with-crypto=mbedtls --enable-tests=no --enable-shared --with-device-layer=none’
Finally ‘make’
You should see the generated SetupPayloadParser.jar under src/setup_payload/java and libSetupPayloadParser.so under src/setup_payload/java/.libs folders in the output directory.
Drop the .jar in the libs folder in the Android project.
Drop the .so in the ABI-specific jniLibs folder in the Android project, eg. jniLibs/arm64-v8a
‘Gradle sync’ the Android project and run.
(Eventually hoping to not have to include this .so, but that needs some more tweaking of the Android automake build rules. Include it in the interim to be able to build the Android app).