From 0c22d2f81c2d6fcc4d63dea40d1e3ac6098542bc Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 23 Oct 2020 15:27:14 -0400 Subject: [PATCH] Copy shared libstdc++ as part of the build step for android. (#3394) * Link statically stdlibc++ for android builds * GN format * Copy libstdcpp automatically * add missing file * whitespace fix * GN format * GN format * Android ABI in ndk seems to be x86_64 rather than x86-64 in the cxx sources * Update abi name to use underscore for x86_64 in the chiptool android readme as well --- build/chip/java/BUILD.gn | 29 +++++++++++++++++++++++++++++ build/config/android_abi.gni | 2 +- src/android/CHIPTool/README.md | 14 ++------------ src/controller/java/BUILD.gn | 5 ++++- src/setup_payload/java/BUILD.gn | 5 ++++- 5 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 build/chip/java/BUILD.gn diff --git a/build/chip/java/BUILD.gn b/build/chip/java/BUILD.gn new file mode 100644 index 00000000000000..a57c64d18470d2 --- /dev/null +++ b/build/chip/java/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/chip.gni") + +import("//build/config/android/config.gni") +import("//build/config/android_abi.gni") + +# Place a copy of the shared c++ support library in the jni output directory +# See: +# https://developer.android.com/ndk/guides/cpp-support +# +# Generally CHIP cannot ensure a single shared library per java application, so a shared +# CPP support library is used +copy("shared_cpplib") { + sources = [ "${android_ndk_root}/sources/cxx-stl/llvm-libc++/libs/${android_abi}/libc++_shared.so" ] + outputs = [ "${root_out_dir}/lib/jni/${android_abi}/libc++_shared.so" ] +} diff --git a/build/config/android_abi.gni b/build/config/android_abi.gni index d2a33759c62f96..d60c1b0f5605ba 100644 --- a/build/config/android_abi.gni +++ b/build/config/android_abi.gni @@ -4,7 +4,7 @@ if (current_os == "android") { } else if (current_cpu == "arm64") { android_abi = "arm64-v8a" } else if (current_cpu == "x64") { - android_abi = "x86-64" + android_abi = "x86_64" } else if (current_cpu == "x86") { android_abi = "x86" } else { diff --git a/src/android/CHIPTool/README.md b/src/android/CHIPTool/README.md index 55354826d6e0b1..88296862b06a37 100644 --- a/src/android/CHIPTool/README.md +++ b/src/android/CHIPTool/README.md @@ -23,7 +23,7 @@ ABIs and corresponding values for `target_cpu` | armeabi-v7a | arm | | arm64-v8a | arm64 | | x86 | x86 | -| x86-64 | x64 | +| x86_64 | x64 | 1. Checkout the CHIP repo @@ -58,14 +58,4 @@ rsync -a out/android_arm64/lib/jni/* src/android/CHIPTool/app/src/main/jniLibs ## JAR and .so libraries will be copy to target directories. ``` -6. 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`, e.g. - - `rsync -a "${ANDROID_NDK_HOME}/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so" src/android/CHIPTool/app/src/main/jniLibs/arm64-v8a/` - - (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). - -7. 'Gradle sync' the Android project and run. +6. 'Gradle sync' the Android project and run. diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index d4281fcd14c357..5b100ce6641d6c 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -38,7 +38,10 @@ shared_library("jni") { android_library("java") { output_name = "CHIPController.jar" - data_deps = [ ":jni" ] + data_deps = [ + ":jni", + "//build/chip/java:shared_cpplib", + ] sources = [ "src/chip/devicecontroller/AndroidChipStack.java", diff --git a/src/setup_payload/java/BUILD.gn b/src/setup_payload/java/BUILD.gn index 88e82eb1e96024..57b21bb8926a91 100644 --- a/src/setup_payload/java/BUILD.gn +++ b/src/setup_payload/java/BUILD.gn @@ -33,7 +33,10 @@ shared_library("jni") { android_library("java") { output_name = "SetupPayloadParser.jar" - data_deps = [ ":jni" ] + data_deps = [ + ":jni", + "//build/chip/java:shared_cpplib", + ] sources = [ "src/chip/setuppayload/OptionalQRCodeInfo.java",