-
Notifications
You must be signed in to change notification settings - Fork 866
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compiling instructions for android (#278)
* Add compiling instructions for android
- Loading branch information
1 parent
a6a5853
commit 7ddab84
Showing
6 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Establishing a Build Environment | ||
## Installing the Android NDK | ||
The Android NDK is required to build native modules for Android. | ||
Download the appropriate NDK archive from the following site: [Download the Android NDK](https://developer.android.com/ndk/downloads/index.html) | ||
To install the Android NDK, simply expand the archive in the folder where you want to install it. | ||
## Creating the Toolchain | ||
Run ```mktoolchains``` script to prepare standalone toolchains for all supported architectures. Refer to [NDK docs](https://developer.android.com/ndk/guides/standalone_toolchain.html) for details. | ||
## Working with Clang and libc++ | ||
GNU compilers and gnustl will be removed from NDK starting Q3 2018, so we will use clang and libc++. | ||
## OpenSSL | ||
Google removed openssl from Android 7+. You must build openssl libs by yourself. | ||
# Build SRT for Android | ||
Run ```/bin/bash mkall```. Libraries will be installed to ```./target-architecture/lib```. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
openssl_ver=1.0.2n | ||
srt_branch=dev | ||
|
||
BASE_DIR=$(readlink -f $0 | xargs dirname) | ||
|
||
wget -N https://www.openssl.org/source/openssl-$openssl_ver.tar.gz | ||
|
||
if [ ! -d $BASE_DIR/srt ]; then | ||
git clone https://github.com/Haivision/srt srt | ||
git -C $BASE_DIR/srt checkout -b $srt_branch origin/$srt_branch | ||
fi | ||
|
||
declare -A target_hosts | ||
target_hosts=( | ||
[arm]=arm-linux-androideabi | ||
[arm64]=aarch64-linux-android | ||
[x86]=i686-linux-android | ||
[x86_64]=x86_64-linux-android | ||
) | ||
|
||
declare -A sysroots | ||
sysroots=( | ||
[arm]=$BASE_DIR/armeabi-v7a | ||
[arm64]=$BASE_DIR/arm64-v8a | ||
[x86]=$BASE_DIR/x86 | ||
[x86_64]=$BASE_DIR/x86_64 | ||
) | ||
|
||
for arch in arm arm64 x86 x86_64; do | ||
rm -rf $BASE_DIR/openssl-$openssl_ver | ||
tar xf $BASE_DIR/openssl-$openssl_ver.tar.gz | ||
$BASE_DIR/mkssl -t $BASE_DIR/android-toolchain-$arch -h ${target_hosts[$arch]} -s $BASE_DIR/openssl-$openssl_ver -i ${sysroots[$arch]} | ||
|
||
git -C $BASE_DIR/srt clean -fd | ||
$BASE_DIR/mksrt -t $BASE_DIR/android-toolchain-$arch -h ${target_hosts[$arch]} -s $BASE_DIR/srt -i ${sysroots[$arch]} | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
source prepare_build | ||
|
||
./configure --CMAKE_PREFIX_PATH=$install_dir --CMAKE_INSTALL_PREFIX=$install_dir | ||
make | ||
make install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
source prepare_build | ||
|
||
./Configure android --openssldir=$install_dir | ||
# OpenSSL (1.0.2) adds -mandroid to the compile flags. This flag is not recognized by clang. | ||
sed -i 's/-mandroid//g' Makefile | ||
make | ||
make install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
BASE_DIR=$(readlink -f $0 | xargs dirname) | ||
|
||
export PATH=$PATH:/opt/android-ndk-r16b/build/tools | ||
|
||
for arch in arm arm64 x86 x86_64; do | ||
make_standalone_toolchain.py -v --arch $arch --api 21 --stl=libc++ --install-dir=$BASE_DIR/android-toolchain-$arch | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
while getopts t:h:s:i: option | ||
do | ||
case "${option}" | ||
in | ||
t) toolchain_dir=${OPTARG};; | ||
h) target_host=${OPTARG};; | ||
s) src_dir=${OPTARG};; | ||
i) install_dir=$OPTARG;; | ||
esac | ||
done | ||
|
||
# Add the standalone toolchain to the search path. | ||
export PATH=$PATH:$toolchain_dir/bin | ||
|
||
# Tell configure what tools to use. | ||
export AR=$target_host-ar | ||
export AS=$target_host-clang | ||
export CC=$target_host-clang | ||
export CXX=$target_host-clang++ | ||
export LD=$target_host-ld | ||
export STRIP=$target_host-strip | ||
|
||
# Tell configure what flags Android requires. | ||
export CFLAGS="-fPIE -fPIC" | ||
export LDFLAGS="-pie" | ||
|
||
cd $src_dir |