-
Notifications
You must be signed in to change notification settings - Fork 68
/
build_android.sh
executable file
·122 lines (101 loc) · 3.23 KB
/
build_android.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
# This script is only for cross-compilation for Android
# ARCH INDEXES (0 to disable, 1 to enable)
ARCH_ARM_V7A=0
ARCH_ARM64_V8A=1
ARCH_X86=2
ARCH_X86_64=3
# ENABLE ARCH
ENABLED_ARCHITECTURES=(0 1 0 0)
# ARCH ABIs
ANDROID_ABIS=("armeabi-v7a" "arm64-v8a" "x86" "x86_64")
ANDROID_PROCESSORS=("armv7-a" "aarch64" "i686" "x86_64")
ANDROID_ARCHS=("arm" "arm64" "x86" "x86_64")
# USING API LEVEL > 21
export ANDROID_API=21
# Default build type - Release
BUILD_TYPE="Release"
# Handle options
if [ $# -gt 0 ]
then
# Clean up
if [ "$1" = "clean" ]
then
rm -rf build_android
rm -rf output
exit
fi
# Debug type
if [ "$1" = "debug" ]
then
BUILD_TYPE="Debug"
fi
fi
if [[ -z ${ANDROID_NDK_ROOT} ]]
then
echo "ANDROID_NDK_ROOT not defined"
exit 1
fi
if [[ -z ${ANDROID_XCOMPILE_ROOTFS} ]]
then
echo "ANDROID_XCOMPILE_ROOTFS not defined"
exit 1
fi
DETECTED_NDK_VERSION=$(grep -Eo Revision.* ${ANDROID_NDK_ROOT}/source.properties | sed 's/Revision//g;s/=//g;s/ //g')
# Configuration
export SCRIPT_EXEC_MODE=android
export EXACT_PYTHON_TARGET=1
export PYTHON_VERSION=3.9
# Set the output directory
mkdir output
# Generate BMF version
source ./version.sh
for run_arch in {0..3}
do
if [[ ${ENABLED_ARCHITECTURES[$run_arch]} -eq 1 ]]
then
export ANDROID_ARCH=${ANDROID_ARCHS[$run_arch]}
export ANDROID_TARGET_PLATFORM=android-${ANDROID_API}
export ANDROID_ROOTFS_PATH=${ANDROID_XCOMPILE_ROOTFS}/${ANDROID_ARCHS[$run_arch]}/usr
export GLOG_ROOT_PATH=${ANDROID_ROOTFS_PATH}
export FFMPEG_ROOT_PATH=${ANDROID_ROOTFS_PATH}
export Python_LIBRARY=${ANDROID_ROOTFS_PATH}/lib/libpython${PYTHON_VERSION}.a
export Python_INCLUDE_DIRS=${ANDROID_ROOTFS_PATH}/include/python${PYTHON_VERSION}
echo -e "\nBuilding ${ANDROID_ABIS[$run_arch]} on API ${ANDROID_API}\n"
echo $ANDROID_ROOTFS_PATH
echo $Python_LIBRARY
echo $Python_INCLUDE_DIR
# Build
mkdir -p build_android
cd build_android
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DBMF_ENABLE_MOBILE=OFF \
-DBMF_ENABLE_PYTHON=ON \
-DBMF_ENABLE_GLOG=OFF \
-DCMAKE_FIND_ROOT_PATH=${ANDROID_ROOTFS_PATH} \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake \
-DANDROID_STL=c++_shared \
-DANDROID_ABI="${ANDROID_ABIS[$run_arch]}" \
-DBMF_PYENV=${PYTHON_VERSION} \
-DANDROID_PLATFORM=${ANDROID_TARGET_PLATFORM} \
-DBMF_BUILD_VERSION=${BMF_BUILD_VERSION} \
-DBMF_BUILD_COMMIT=${BMF_BUILD_COMMIT} \
-DBMF_USE_MEDIACODEC=OFF ..
#cmake --build .
#ninja
make -j16
mkdir -p ../output/${ANDROID_ABIS[$run_arch]}
rm -rf ../output/${ANDROID_ABIS[$run_arch]}/*
cp -rf output/bmf output/hmp ../output/${ANDROID_ABIS[$run_arch]}/
cd ..
if [ ! -d "3rd_party/bmf_android_python" ]
then
echo "Extracting bmf_android_python"
cd 3rd_party/
tar xzvf bmf_android_python.tar.gz
cd -
fi
cp -r 3rd_party/bmf_android_python/python/* output/${ANDROID_ABIS[$run_arch]}/bmf/
#rm -rf build_android
fi
done