Skip to content

Commit

Permalink
Copy shared libstdc++ as part of the build step for android. (#3394)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
andy31415 authored and pull[bot] committed Nov 30, 2020
1 parent 9a995a4 commit 0c22d2f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
29 changes: 29 additions & 0 deletions build/chip/java/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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" ]
}
2 changes: 1 addition & 1 deletion build/config/android_abi.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 2 additions & 12 deletions src/android/CHIPTool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
5 changes: 4 additions & 1 deletion src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion src/setup_payload/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0c22d2f

Please sign in to comment.