Skip to content

Commit 0929c7e

Browse files
committed
build and link ffmpeg
1 parent 680c654 commit 0929c7e

File tree

5 files changed

+82
-5
lines changed

5 files changed

+82
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build
2+
shared
23
.externalNativeBuild
34
.gradle

CMakeLists.txt

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
cmake_minimum_required(VERSION 3.4.1)
2-
add_library (semitone-native SHARED src/main/cpp/semitone-native.cpp src/main/cpp/PianoEngine.cpp src/main/cpp/Tone.cpp src/main/cpp/Sound.cpp)
1+
cmake_minimum_required (VERSION 3.4.1)
2+
3+
add_library (semitone-native SHARED
4+
src/main/cpp/semitone-native.cpp
5+
src/main/cpp/PianoEngine.cpp
6+
src/main/cpp/Tone.cpp
7+
src/main/cpp/Sound.cpp)
8+
39
find_library (android-lib android)
4-
target_link_libraries (semitone-native oboe ${android-lib})
5-
add_subdirectory (./lib/oboe ./lib/oboe)
6-
include_directories (./lib/oboe/include)
10+
11+
add_subdirectory (lib/oboe lib/oboe)
12+
include_directories (lib/oboe/include)
13+
14+
set (FFMPEG_DIR ${PROJECT_SOURCE_DIR}/lib/ffmpeg/build/${ANDROID_ABI})
15+
include_directories (${FFMPEG_DIR}/include)
16+
add_library (avcodec SHARED IMPORTED)
17+
set_target_properties (avcodec PROPERTIES IMPORTED_LOCATION ${FFMPEG_DIR}/lib/libavcodec.so)
18+
add_library (avformat SHARED IMPORTED)
19+
set_target_properties (avformat PROPERTIES IMPORTED_LOCATION ${FFMPEG_DIR}/lib/libavformat.so)
20+
add_library (avutil SHARED IMPORTED)
21+
set_target_properties (avutil PROPERTIES IMPORTED_LOCATION ${FFMPEG_DIR}/lib/libavutil.so)
22+
add_library (swresample SHARED IMPORTED)
23+
set_target_properties (swresample PROPERTIES IMPORTED_LOCATION ${FFMPEG_DIR}/lib/libswresample.so)
24+
25+
target_link_libraries (semitone-native ${android-lib} oboe avcodec avformat avutil swresample)

build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ android {
4141
path "CMakeLists.txt"
4242
}
4343
}
44+
45+
sourceSets {
46+
main {
47+
jniLibs.srcDirs = ["shared"]
48+
}
49+
}
4450
}
4551

4652
gradle.projectsEvaluated {

tools/build_ffmpeg.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# NOTE: run this from project root
4+
5+
set -e
6+
cd lib/ffmpeg
7+
8+
[ -n "$ANDROID_NDK" ] || { echo >&2 no ndk; exit 1; }
9+
HOST_ARCH=${HOST_ARCH:-linux-x86_64}
10+
11+
TOOLCHAIN="$ANDROID_NDK/toolchains/llvm/prebuilt/$HOST_ARCH/bin"
12+
[ -d "$TOOLCHAIN" ] || { echo >&2 no toolchain; exit 1; }
13+
14+
while read ABI ARCH CC_CMD STRIP_CMD FLAGS
15+
do
16+
17+
[ -f "$TOOLCHAIN/$CC_CMD" ] || { echo >&2 "no cc for $ABI"; exit 1; }
18+
[ -f "$TOOLCHAIN/$STRIP_CMD" ] || { echo >&2 "no strip for $ABI"; exit 1; }
19+
20+
./configure \
21+
--prefix="build/$ABI" \
22+
--arch="$ARCH" \
23+
--cc="$TOOLCHAIN/$CC_CMD" \
24+
--strip="$TOOLCHAIN/$STRIP_CMD" \
25+
$FLAGS \
26+
--target-os=android \
27+
--enable-cross-compile --enable-small --enable-shared \
28+
--disable-programs --disable-doc --disable-static --disable-everything \
29+
--enable-decoder=mp3 --enable-demuxer=mp3
30+
31+
make clean
32+
make -j3
33+
make install
34+
35+
done <<x
36+
armeabi-v7a armv7-a armv7a-linux-androideabi16-clang arm-linux-androideabi-strip
37+
arm64-v8a aarch64 aarch64-linux-android21-clang aarch64-linux-android-strip
38+
x86 x86 i686-linux-android16-clang i686-linux-android-strip --disable-asm
39+
x86_64 x86_64 x86_64-linux-android21-clang x86_64-linux-android-strip --disable-asm
40+
x

tools/copy_ffmpeg.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
rm -rf shared
6+
mkdir shared
7+
for ABI in armeabi-v7a arm64-v8a x86 x86_64
8+
do
9+
mkdir "shared/$ABI"
10+
cp lib/ffmpeg/build/"$ABI"/lib/lib{avcodec,avformat,avutil,swresample}.so "shared/$ABI"
11+
done

0 commit comments

Comments
 (0)