最近花了一天時間將ffmpeg/tools/build_stagefright執行成功,主要是交叉編譯所須要的各類動態庫的支持沒連接上,致使各類報錯,基本上網絡上問到的問題我都碰到了,特此記錄下來。linux
編譯環境:Ubuntu 14.04 + Android NDK + FFmpeg源碼。android
第一步:將ffmpeg/tools/build_stagefright移動到ffmpeg下面,修改執行權限。c++
chmod u+x build_stagefright
第二步:打開build_stagefright文件,配置Android NDK路徑。git
#!/bin/bash export NDK=/to/your/ndk/path if [ "$NDK" = "" ]; then echo NDK variable not set, assuming ${HOME}/android-ndk-r8d export NDK=${HOME}/android-ndk-r8d fi
第三步:build_stagefright中的下載地址http://download.cyanogenmod.com/get/update-cm-7.0.3-N1-signed.zip失效了,因此得手動下載update-cm-7.0.3-N1-signed.zip,附一個能夠下載的地址http://sourceforge.net/projects/nexusoneandroid/files/update-cm-7.0.3-N1-signed.zip/stats/timelinegithub
第四步:修改TOOLCHAIN=`echo $NDK/toolchains/arm-linux-androideabi-4.3.3/prebuilt/*-x86 ` 爲 TOOLCHAIN=`echo $NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64 ` ,不然會出現arm-linux-androideabi-gcc is unable to create an executable file. C compiler test failed.這樣的錯誤vim
第五步:vim configure 將enabled libstagefright_h264 && require_cpp libstagefright_h264 改成 enabled libstagefright && require_cpp libstagefright_h264,不然會出現ERROR: libstagefright_h264 not foundbash
第六步:將build_stagefright中的EXTRA_CFLAGS="$EXTRA_CFLAGS -I$NDK/sources/cxx-stl/gnu-libstdc++/include -I$NDK/sources/cxx-stl/gnu-libstdc++/libs/$ABI/include"改成EXTRA_CFLAGS="$EXTRA_CFLAGS -I$NDK/sources/cxx-stl/gnu-libstdc++/4.8/include -I$NDK/sources/cxx-stl/gnu-libstdc++/4.8/libs/$ABI/include"網絡
第七步:將build_stagefright中的EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS -L$NDK/sources/cxx-stl/gnu-libstdc++/libs/$ABI"更改成EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS -L$NDK/sources/cxx-stl/gnu-libstdc++/4.8/libs/$ABI"ide
第八步:將build_stagefright中的EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS -L$NDK/sources/cxx-stl/gnu-libstdc++/libs/$ABI"繼續修改添加交叉編譯所須要的外部庫。最終修改成:ui
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS -L$NDK/sources/cxx-stl/gnu-libstdc++/4.8/libs/$ABI -lstagefright -lstdc++ -lutils -lbinder -lgnustl_static -lgnustl_shared"
第八步能解決大多數交叉編譯沒有連接相應的庫致使的問題。
最終修改完成的build_stagefright內容以下:
#!/bin/bash export NDK=$ANDROID_NDK if [ "$NDK" = "" ]; then echo NDK variable not set, assuming ${HOME}/android-ndk export NDK=${HOME}/android-ndk fi echo "Fetching Android system headers" git clone --depth=1 --branch gingerbread-release git://github.com/CyanogenMod/android_frameworks_base.git ../android-source/frameworks/base git clone --depth=1 --branch gingerbread-release git://github.com/CyanogenMod/android_system_core.git ../android-source/system/core echo "Fetching Android libraries for linking" # Libraries from any froyo/gingerbread device/emulator should work # fine, since the symbols used should be available on most of them. if [ ! -d "../android-libs" ]; then if [ ! -f "../update-cm-7.0.3-N1-signed.zip" ]; then wget http://download.cyanogenmod.com/get/update-cm-7.0.3-N1-signed.zip -P../ fi unzip ../update-cm-7.0.3-N1-signed.zip system/lib/* -d../ mv ../system/lib ../android-libs rmdir ../system fi SYSROOT=$NDK/platforms/android-9/arch-arm # Expand the prebuilt/* path into the correct one TOOLCHAIN=`echo $NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64` export PATH=$TOOLCHAIN/bin:$PATH ANDROID_SOURCE=../android-source ANDROID_LIBS=../android-libs ABI="armeabi-v7a" rm -rf ../build/stagefright mkdir -p ../build/stagefright DEST=../build/stagefright FLAGS="--target-os=linux --cross-prefix=arm-linux-androideabi- --arch=arm --cpu=armv7-a" FLAGS="$FLAGS --sysroot=$SYSROOT" FLAGS="$FLAGS --disable-avdevice --disable-decoder=h264 --disable-decoder=h264_vdpau --enable-libstagefright-h264" EXTRA_CFLAGS="-I$ANDROID_SOURCE/frameworks/base/include -I$ANDROID_SOURCE/system/core/include" EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/base/media/libstagefright" EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/base/include/media/stagefright/openmax" EXTRA_CFLAGS="$EXTRA_CFLAGS -I$NDK/sources/cxx-stl/gnu-libstdc++/4.8/include -I$NDK/sources/cxx-stl/gnu-libstdc++/4.8/libs/$ABI/include" EXTRA_CFLAGS="$EXTRA_CFLAGS -march=armv7-a -mfloat-abi=softfp -mfpu=neon" EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS -L$NDK/sources/cxx-stl/gnu-libstdc++/4.8/libs/$ABI -lstagefright -lstdc++ -lutils -lbinder -lgnustl_static -lgnustl_shared" #EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcutils -ldl -lstlport -lc -lm -lz -ldl -llog -lstdc++ -lstagefright -lbinder -lstlport -lstdc++ -lstl" EXTRA_CXXFLAGS="-Wno-multichar -fno-exceptions -fno-rtti" DEST="$DEST/$ABI" FLAGS="$FLAGS --prefix=$DEST" mkdir -p $DEST echo $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS" > $DEST/info.txt ./configure $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS" | tee $DEST/configuration.txt [ $PIPESTATUS == 0 ] || exit 1 make clean make -j4 || exit 1
第九步,執行./build_stagefright編譯,最終輸出以下內容則表示編譯成功:
CC ffprobe.o CC ffserver.o AR libavfilter/libavfilter.a AR libavformat/libavformat.a AR libavcodec/libavcodec.a AR libswresample/libswresample.a AR libswscale/libswscale.a AR libavutil/libavutil.a HOSTLD doc/print_options GENTEXI doc/avoptions_format.texi GENTEXI doc/avoptions_codec.texi POD doc/ffmpeg.pod POD doc/ffprobe.pod POD doc/ffserver.pod POD doc/ffmpeg-all.pod POD doc/ffprobe-all.pod POD doc/ffserver-all.pod POD doc/ffmpeg-utils.pod POD doc/ffmpeg-scaler.pod POD doc/ffmpeg-resampler.pod POD doc/ffmpeg-codecs.pod POD doc/ffmpeg-bitstream-filters.pod POD doc/ffmpeg-formats.pod POD doc/ffmpeg-protocols.pod POD doc/ffmpeg-filters.pod POD doc/libavutil.pod POD doc/libswscale.pod POD doc/libswresample.pod POD doc/libavcodec.pod POD doc/libavformat.pod POD doc/libavfilter.pod MAN doc/ffmpeg.1 MAN doc/ffprobe.1 MAN doc/ffserver.1 MAN doc/ffmpeg-all.1 MAN doc/ffprobe-all.1 MAN doc/ffserver-all.1 MAN doc/ffmpeg-utils.1 MAN doc/ffmpeg-scaler.1 MAN doc/ffmpeg-resampler.1 MAN doc/ffmpeg-codecs.1 MAN doc/ffmpeg-bitstream-filters.1 MAN doc/ffmpeg-formats.1 MAN doc/ffmpeg-protocols.1 MAN doc/ffmpeg-filters.1 MAN doc/libavutil.3 MAN doc/libswscale.3 MAN doc/libswresample.3 MAN doc/libavcodec.3 MAN doc/libavformat.3 MAN doc/libavfilter.3 LD ffmpeg_g LD ffprobe_g LD ffserver_g CP ffprobe CP ffmpeg STRIP ffprobe STRIP ffmpeg CP ffserver STRIP ffserver