gn_android_example.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) 2020 Project CHIP Authors
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. set -e
  18. # Build script for GN examples GitHub workflow.
  19. source "$(dirname "$0")/../../scripts/activate.sh"
  20. GN_ARGS=()
  21. EXAMPLE_DIR=$1
  22. shift
  23. OUTPUT_DIR=$1
  24. shift
  25. NINJA_ARGS=()
  26. for arg; do
  27. case $arg in
  28. -v)
  29. NINJA_ARGS+=(-v)
  30. ;;
  31. *=*)
  32. GN_ARGS+=("$arg")
  33. ;;
  34. *import*)
  35. GN_ARGS+=("$arg")
  36. ;;
  37. *)
  38. echo >&2 "invalid argument: $arg"
  39. exit 2
  40. ;;
  41. esac
  42. done
  43. set -x
  44. env
  45. if [ -z "$ANDROID_HOME" ]; then
  46. echo "ANDROID_HOME not set!"
  47. exit 1
  48. fi
  49. if [ -z "$ANDROID_NDK_HOME" ]; then
  50. echo "ANDROID_NDK_HOME not set!"
  51. exit 1
  52. fi
  53. if [ -z "$TARGET_CPU" ]; then
  54. echo "TARGET_CPU not set! Candidates: arm, arm64, x86 and x64."
  55. exit 1
  56. fi
  57. python3 "$(dirname "$0")"/../../third_party/android_deps/set_up_android_deps.py
  58. gn gen --check --fail-on-unused-args --root="$EXAMPLE_DIR" "$OUTPUT_DIR" --args="target_os=\"android\" target_cpu=\"$TARGET_CPU\" android_ndk_root=\"$ANDROID_NDK_HOME\" android_sdk_root=\"$ANDROID_HOME\" ${GN_ARGS[*]}"
  59. ninja -C "$OUTPUT_DIR" "${NINJA_ARGS[@]}"
  60. cp -rf "$OUTPUT_DIR/lib/jni/." "$EXAMPLE_DIR/App/app/libs/jniLibs/"
  61. cp -f "$OUTPUT_DIR/lib/third_party/connectedhomeip/src/platform/android/AndroidPlatform.jar" "$EXAMPLE_DIR/App/app/libs/"
  62. cp -f "$OUTPUT_DIR/lib/third_party/connectedhomeip/src/app/server/java/CHIPAppServer.jar" "$EXAMPLE_DIR/App/app/libs/"
  63. cp -f "$OUTPUT_DIR/lib/third_party/connectedhomeip/src/setup_payload/java/SetupPayloadParser.jar" "$EXAMPLE_DIR/App/app/libs/"
  64. cp -f "$OUTPUT_DIR/lib/TvApp.jar" "$EXAMPLE_DIR/App/app/libs/"