Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle Adding the steps to build CHIP for Android apps. #1688

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions src/android/CHIPTool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,89 @@ a CHIP device

- Connection to the chip device's soft AP will be a manual step until pairing
is implemented.

===========================================

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.

1. Checkout the CHIP repo

2. In commandline / Terminal, 'cd' into the top CHIP directory

3. Run './bootstrap'

4. 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.

5. 'cd' into this newly created directory

6. 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.

7. Then run '../connectedhomeip/configure --host=\$TARGET --with-crypto=mbedtls
--enable-tests=no --enable-shared --with-device-layer=none'

8. Finally 'make'

9. 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.

10. You will also need the "libc++\_shared.so" file in the jniLibs folder. This
file comes packaged with Android NDK and can be found under
$ANDROID_NDK_HOME/sources/cxx-stl/llvm-libc++/libs/$TARGET

(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).