-
Notifications
You must be signed in to change notification settings - Fork 14
/
setup.sh
146 lines (111 loc) · 4.13 KB
/
setup.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# Luca Anzalone
# -----------------------------------------------------------------------------
# -- DLIB FOR ANDROID
# -----------------------------------------------------------------------------
# Android-cmake path: REPLACE WITH YOUR CMAKE PATH!
AndroidCmake='your-path-to/Android/sdk/cmake/3.10.2.4988404/bin/cmake'
# Android-ndk path: REPLACE WITH YOUR NDK PATH!
NDK="${ANDROID_NDK:-your-path-to/Android/sdk/ndk-bundle}"
TOOLCHAIN="$NDK/build/cmake/android.toolchain.cmake"
# Supported Android ABI: TAKE ONLY WHAT YOU NEED!
ABI=('armeabi-v7a' 'arm64-v8a' 'x86' 'x86_64')
# path to strip tool: REPLACE WITH YOURS, ACCORDING TO OS!!
STRIP_PATH="$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin"
# Declare the array
declare -A STRIP_TOOLS
STRIP_TOOLS=(
['armeabi-v7a']=$STRIP_PATH/arm-linux-androideabi-strip
['arm64-v8a']=$STRIP_PATH/aarch64-linux-android-strip
['x86']=$STRIP_PATH/x86_64-linux-android-strip
['x86_64']=$STRIP_PATH/x86_64-linux-android-strip
)
# Minimum supported sdk: SHOULD BE GREATER THAN 16
MIN_SDK=16
# Android project path: REPLACE WITH YOUR PROJECT PATH!
PROJECT_PATH='your-path-to/android/project'
# Directory for storing native libraries
NATIVE_DIR="$PROJECT_PATH/app/src/main/cppLibs"
# -----------------------------------------------------------------------------
# -- Dlib setup
# -----------------------------------------------------------------------------
# Dlib library path: REPLACE WITH YOUR DLIB PATH!
DLIB_PATH='dlib'
function compile_dlib {
cd $DLIB_PATH
mkdir 'build'
echo '=> Compiling Dlib...'
for abi in "${ABI[@]}"
do
echo
echo "=> Compiling Dlib for ABI: '$abi'..."
mkdir "build/$abi"
cd "build/$abi"
$AndroidCmake -DBUILD_SHARED_LIBS=1 \
-DANDROID_NDK=$NDK \
-DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="-std=c++11 -frtti -fexceptions" \
-DCMAKE_C_FLAGS=-O3 \
-DANDROID_ABI=$abi \
-DANDROID_PLATFORM="android-$MIN_SDK" \
-DANDROID_TOOLCHAIN=clang \
-DANDROID_STL=c++_shared \
-DANDROID_CPP_FEATURES=rtti exceptions \
-DCMAKE_PREFIX_PATH=../../ \
../../
echo "=> Generating the 'dlib/libdlib.so' for ABI: '$abi'..."
$AndroidCmake --build .
echo "=> Stripping libdlib.so for ABI: '$abi'to reduce lib size..."
${STRIP_TOOLS[$abi]} --strip-unneeded dlib/libdlib.so
echo '=> done.'
cd ../../
done
}
function dlib_setup {
echo '=> Making directories for Dlib ...'
mkdir "$NATIVE_DIR/dlib"
echo "=> '$NATIVE_DIR/dlib' created."
mkdir "$NATIVE_DIR/dlib/lib"
echo "=> '$NATIVE_DIR/dlib/lib' created."
mkdir "$NATIVE_DIR/dlib/include"
echo "=> '$NATIVE_DIR/dlib/include' created."
mkdir "$NATIVE_DIR/dlib/include/dlib"
echo "=> '$NATIVE_DIR/dlib/include/dlib' created."
echo "=> Copying Dlib headers..."
cp -v -r "$DLIB_PATH/dlib" "$NATIVE_DIR/dlib/include/dlib"
echo "=> Copying 'libdlib.so' for each ABI..."
for abi in "${ABI[@]}"
do
mkdir "$NATIVE_DIR/dlib/lib/$abi"
cp -v "$DLIB_PATH/build/$abi/dlib/libdlib.so" "$NATIVE_DIR/dlib/lib/$abi"
echo " > Copied libdlib.so for $abi"
done
}
# COMMENT TO DISABLE COMPILATION
compile_dlib
# -----------------------------------------------------------------------------
# -- OpenCV
# -----------------------------------------------------------------------------
# OpenCV library path: REPLACE WITH YOUR OPENCV PATH!
OPENCV_PATH='path-to-your/opencv-4.0.1-android-sdk/sdk/native'
function opencv_setup {
mkdir "$NATIVE_DIR/opencv"
echo "=> Copying 'libopencv_java4.so' for each ABI..."
for abi in "${ABI[@]}"
do
mkdir "$NATIVE_DIR/opencv/$abi"
cp -v "$OPENCV_PATH/libs/$abi/libopencv_java4.so" "$NATIVE_DIR/opencv/$abi"
echos " > Copied libopencv_java4.so for $abi"
done
}
# -----------------------------------------------------------------------------
# -- Project setup
# -----------------------------------------------------------------------------
mkdir $NATIVE_DIR
# COMMENT TO NOT COPY DLIB '.so' FILES
dlib_setup
# COMMENT TO NOT COPY OPENCV '.so' FILES
opencv_setup
echo "=> Project configuration completed."
# -----------------------------------------------------------------------------