BlueGit

ict rusty-teams

Files

rusty-teams / vendor / webrtc-sys / libwebrtc / build_android.sh

build_android.sh

build_android.sh 5.1 KiB Download Raw
1#!/bin/bash
2# Exit immediately if any command fails. This ensures CI properly reports build
3# failures instead of continuing to create empty/broken artifacts.
4set -e
5
6# Copyright 2023 LiveKit, Inc.
7#
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19
20
21arch=""
22profile="release"
23
24while [ "$#" -gt 0 ]; do
25 case "$1" in
26 --arch)
27 arch="$2"
28 if [ "$arch" != "arm" ] && [ "$arch" != "x64" ] && [ "$arch" != "arm64" ]; then
29 echo "Error: Invalid value for --arch. Must be 'arm', 'x64' or 'arm64'."
30 exit 1
31 fi
32 shift 2
33 ;;
34 --profile)
35 profile="$2"
36 if [ "$profile" != "debug" ] && [ "$profile" != "release" ]; then
37 echo "Error: Invalid value for --profile. Must be 'debug' or 'release'."
38 exit 1
39 fi
40 shift 2
41 ;;
42 *)
43 echo "Error: Unknown argument '$1'"
44 exit 1
45 ;;
46 esac
47done
48
49if [ -z "$arch" ]; then
50 echo "Error: --arch must be set."
51 exit 1
52fi
53
54echo "Building LiveKit WebRTC - Android"
55echo "Arch: $arch"
56echo "Profile: $profile"
57
58if [ ! -e "$(pwd)/depot_tools" ]
59then
60 git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git
61fi
62
63export COMMAND_DIR=$(cd $(dirname $0); pwd)
64export PATH="$(pwd)/depot_tools:$PATH"
65export OUTPUT_DIR="$(pwd)/src/out-$arch-$profile"
66export ARTIFACTS_DIR="$(pwd)/android-$arch-$profile"
67
68if [ ! -e "$(pwd)/src" ]
69then
70 gclient sync -D --no-history
71fi
72
73source "$COMMAND_DIR/apply_patch.sh"
74
75cd src
76apply_patch "$COMMAND_DIR/patches/add_licenses.patch"
77apply_patch "$COMMAND_DIR/patches/fix_license_json_parsing.patch"
78apply_patch "$COMMAND_DIR/patches/ssl_verify_callback_with_native_handle.patch"
79apply_patch "$COMMAND_DIR/patches/add_deps.patch"
80apply_patch "$COMMAND_DIR/patches/android_use_libunwind.patch"
81apply_patch "$COMMAND_DIR/patches/external_audio_source.patch"
82# livekit prefixed jni
83apply_patch "$COMMAND_DIR/patches/jni_prefix.patch"
84
85cd third_party/libyuv
86apply_patch "$COMMAND_DIR/patches/disable_sme_for_libyuv.patch"
87
88cd ../../..
89
90mkdir -p "$ARTIFACTS_DIR/lib"
91
92debug="false"
93if [ "$profile" = "debug" ]; then
94 debug="true"
95fi
96
97# Note: use_clang_modules=false is required to avoid C++ module compilation issues.
98# Without this flag, the build may fail partway through, resulting in missing
99# artifacts like libwebrtc.jar.
100args="is_debug=$debug \
101 is_java_debug=$debug \
102 target_os=\"android\" \
103 target_cpu=\"$arch\" \
104 rtc_enable_protobuf=false \
105 treat_warnings_as_errors=false \
106 rtc_include_tests=false \
107 rtc_build_tools=false \
108 rtc_build_examples=false \
109 rtc_libvpx_build_vp9=false \
110 is_component_build=false \
111 enable_stripping=true \
112 rtc_use_h264=false \
113 rtc_use_h265=true \
114 rtc_use_pipewire=false \
115 symbol_level=0 \
116 enable_iterator_debugging=false \
117 android_package_prefix=\"livekit\" \
118 use_custom_libcxx=false \
119 use_clang_modules=false \
120 use_rtti=true"
121
122if [ "$debug" = "true" ]; then
123 args="${args} is_asan=true is_lsan=true";
124fi
125
126# generate ninja files
127gn gen "$OUTPUT_DIR" --root="src" --args="${args}"
128
129# build shared library
130autoninja -C "$OUTPUT_DIR" :default \
131 sdk/android:native_api \
132 sdk/android:libwebrtc \
133 sdk/android:libjingle_peerconnection_so
134
135# make libwebrtc.a
136# don't include nasm
137ar -rc "$ARTIFACTS_DIR/lib/libwebrtc.a" `find "$OUTPUT_DIR/obj" -name '*.o' -not -path "*/third_party/nasm/*"`
138
139# License generation is optional - may fail with some Python versions
140# Use vpython3 from depot_tools for consistent Python version
141vpython3 "./src/tools_webrtc/libs/generate_licenses.py" \
142 --target :default "$OUTPUT_DIR" "$OUTPUT_DIR" || echo "Warning: License generation failed (non-critical)"
143
144cp "$OUTPUT_DIR/obj/webrtc.ninja" "$ARTIFACTS_DIR"
145cp "$OUTPUT_DIR/libjingle_peerconnection_so.so" "$ARTIFACTS_DIR/lib"
146cp "$OUTPUT_DIR/args.gn" "$ARTIFACTS_DIR"
147
148cp "$OUTPUT_DIR/LICENSE.md" "$ARTIFACTS_DIR"
149
150mkdir -p "$COMMAND_DIR/prefixed-jni/libs"
151cp "$OUTPUT_DIR/lib.java/sdk/android/libwebrtc.jar" "$COMMAND_DIR/prefixed-jni/libs/classes.jar"
152# Upstream compiles the Android Java sources with --release 21 since m150 (class file
153# major version 65). Consumers on Android Gradle Plugin 7.x (e.g. Unity 2022.3) reject
154# those class files. Stamp them back to Java 17 (major 61) before shadowing, like
155# webrtc-sdk/android does for its Maven artifacts.
156python3 "$COMMAND_DIR/tools/downgrade_android_class_version.py" "$COMMAND_DIR/prefixed-jni/libs/classes.jar"
157cd "$COMMAND_DIR/prefixed-jni" && ./gradlew shadowJar
158cp "$COMMAND_DIR/prefixed-jni/build/libs/prefixed-jni-all.jar" "$ARTIFACTS_DIR/libwebrtc.jar"
159
160cd ..
161
162cp "src/sdk/android/AndroidManifest.xml" "$ARTIFACTS_DIR"
163
164cd src
165find . -name "*.h" -print | cpio -pd "$ARTIFACTS_DIR/include"
166find . -name "*.inc" -print | cpio -pd "$ARTIFACTS_DIR/include"