build_libwebrtc_android.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash -eu
  2. if [ ! -e "$(pwd)/depot_tools" ]
  3. then
  4. git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git
  5. fi
  6. export COMMAND_DIR=$(cd $(dirname $0); pwd)
  7. export PATH="$(pwd)/depot_tools:$PATH"
  8. export WEBRTC_VERSION=4515
  9. export OUTPUT_DIR="$(pwd)/out"
  10. export ARTIFACTS_DIR="$(pwd)/artifacts"
  11. if [ ! -e "$(pwd)/src" ]
  12. then
  13. fetch --nohooks webrtc_android
  14. cd src
  15. sudo sh -c 'echo 127.0.1.1 $(hostname) >> /etc/hosts'
  16. sudo git config --system core.longpaths true
  17. git checkout "refs/remotes/branch-heads/$WEBRTC_VERSION"
  18. cd ..
  19. gclient sync -f
  20. fi
  21. # add jsoncpp
  22. patch -N "src/BUILD.gn" < "$COMMAND_DIR/patches/add_jsoncpp.patch"
  23. mkdir -p "$ARTIFACTS_DIR/lib"
  24. for target_cpu in "arm64"
  25. do
  26. mkdir -p "$ARTIFACTS_DIR/lib/${target_cpu}"
  27. for is_debug in "true" "false"
  28. do
  29. # generate ninja files
  30. gn gen "$OUTPUT_DIR" --root="src" \
  31. --args="is_debug=${is_debug} \
  32. target_os=\"android\" \
  33. target_cpu=\"${target_cpu}\" \
  34. rtc_use_h264=false \
  35. rtc_include_tests=false \
  36. rtc_build_examples=false \
  37. is_component_build=false \
  38. use_rtti=true \
  39. use_custom_libcxx=false"
  40. # build static library
  41. ninja -C "$OUTPUT_DIR" webrtc
  42. filename="libwebrtc.a"
  43. if [ $is_debug = "true" ]; then
  44. filename="libwebrtcd.a"
  45. fi
  46. # copy static library
  47. cp "$OUTPUT_DIR/obj/libwebrtc.a" "$ARTIFACTS_DIR/lib/${target_cpu}/${filename}"
  48. done
  49. done
  50. pushd src
  51. for is_debug in "true" "false"
  52. do
  53. python tools_webrtc/android/build_aar.py \
  54. --build-dir $OUTPUT_DIR \
  55. --output $OUTPUT_DIR/libwebrtc.aar \
  56. --arch arm64-v8a \
  57. --extra-gn-args "is_debug=${is_debug} \
  58. rtc_use_h264=false \
  59. rtc_include_tests=false \
  60. rtc_build_examples=false \
  61. is_component_build=false \
  62. use_rtti=true \
  63. use_custom_libcxx=false"
  64. filename="libwebrtc.aar"
  65. if [ $is_debug = "true" ]; then
  66. filename="libwebrtc-debug.aar"
  67. fi
  68. # copy aar
  69. cp "$OUTPUT_DIR/libwebrtc.aar" "$ARTIFACTS_DIR/lib/${filename}"
  70. done
  71. popd
  72. # fix error when generate license
  73. patch -N "./src/tools_webrtc/libs/generate_licenses.py" < \
  74. "$COMMAND_DIR/patches/generate_licenses.patch"
  75. python "./src/tools_webrtc/libs/generate_licenses.py" \
  76. --target //:default "$OUTPUT_DIR" "$OUTPUT_DIR"
  77. cd src
  78. find . -name "*.h" -print | cpio -pd "$ARTIFACTS_DIR/include"
  79. cp "$OUTPUT_DIR/LICENSE.md" "$ARTIFACTS_DIR"
  80. # create zip
  81. cd "$ARTIFACTS_DIR"
  82. zip -r webrtc-android.zip lib include LICENSE.md