環(huán)境
- Ubuntu 16.04 LTS
- NDK 16.1.4479499
Ref
- 雷神: 最簡(jiǎn)單的基于FFmpeg的移動(dòng)端例子:Android HelloWorld
- 逆流的魚(yú)yuiop:手把手圖文并茂教你用Android Studio編譯FFmpeg庫(kù)并移植
各種報(bào)錯(cuò)
- No such file or directory
Unknown option "".
See ./configure --help for available options.
./build_android.sh: 22: ./build_android.sh: --cross-prefix=/home/maple/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-: not found
CC libavfilter/aeval.o
In file included from libavfilter/aeval.c:26:0:
./libavutil/avassert.h:30:20: fatal error: stdlib.h: No such file or directory
#include <stdlib.h>
^
compilation terminated.
common.mak:60: recipe for target 'libavfilter/aeval.o' failed
make: *** [libavfilter/aeval.o] Error 1
CC libavfilter/aeval.o
In file included from libavfilter/aeval.c:26:0:
./libavutil/avassert.h:30:20: fatal error: stdlib.h: No such file or directory
#include <stdlib.h>
^
compilation terminated.
common.mak:60: recipe for target 'libavfilter/aeval.o' failed
make: *** [libavfilter/aeval.o] Error 1
看著很多眷蜈,很虎人雨膨,其實(shí)關(guān)鍵字就 No such file or directory
苫拍。一般都是從博客copy的看不見(jiàn)的字符(eg:空格盼忌,回車)引起的换怖,因?yàn)榇蠹业腛S都不一樣快集,系統(tǒng)對(duì)這些字符的編碼也可能不一笛臣,所以建議在純文本編輯軟件中打開(kāi)顯示各種空格,這樣能少不少莫名其妙的坑尸饺。
以逆流的魚(yú)yuiop博客為例进统,他系統(tǒng)為mac拓诸,編譯 FFmpeg 腳本 shell 為:
#!/bin/sh
NDK=/home/maple/Android/Sdk/ndk-bundle
SYSROOT=$NDK/platforms/android-18/arch-arm
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one() {
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-doc \
--disable-symver \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
}
build_one
在Ubuntu下編輯就會(huì)報(bào)上面的錯(cuò)。解決方法:在build_one
函數(shù)中給每行敲個(gè)空行麻昼,like:
#!/bin/sh
NDK=/home/maple/Android/Sdk/ndk-bundle
SYSROOT=$NDK/platforms/android-18/arch-arm
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one() {
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-doc \
--disable-symver \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
}
build_one
- NDK編譯報(bào) 'File format not recognized'
maple@maple-All-Series:~/AndroidStudioProjects/FFmpegDemo/app/src/main/jni$ /home/maple/Android/Sdk/ndk-bundle/ndk-build APP_ALLOW_MISSING_DEPS=true
Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-14.
Android NDK: WARNING: APP_PLATFORM android-14 is higher than android:minSdkVersion 1 in /home/maple/AndroidStudioProjects/FFmpegDemo/app/src/main/AndroidManifest.xml. NDK binaries will *not* be comptible with devices older than android-14. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md for more information.
/home/maple/Android/Sdk/ndk-bundle/build/core/setup-app.mk:81: Android NDK: Application targets deprecated ABI(s): armeabi
/home/maple/Android/Sdk/ndk-bundle/build/core/setup-app.mk:82: Android NDK: Support for these ABIs will be removed in a future NDK release.
/home/maple/Android/Sdk/ndk-bundle/build/core/build-binary.mk:693: Android NDK: Module sffhelloworld depends on undefined modules: avdevice postproc
[armeabi] Install : libavcodec-57.so => libs/armeabi/libavcodec-57.so
/home/maple/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip:/home/maple/AndroidStudioProjects/FFmpegDemo/app/src/main/libs/armeabi/libavcodec-57.so: File format not recognized
make: *** [/home/maple/AndroidStudioProjects/FFmpegDemo/app/src/main/libs/armeabi/libavcodec-57.so] Error 1
make: *** Deleting file `/home/maple/AndroidStudioProjects/FFmpegDemo/app/src/main/libs/armeabi/libavcodec-57.so'
老樣子,Dont Panic馋辈。 'File format not recognized' 文件格式不能識(shí)別抚芦,那我們就去看看這是個(gè)什么格式,這就需要個(gè) file
命令迈螟。
file命令用來(lái)探測(cè)給定文件的類型叉抡。file命令對(duì)文件的檢查分為文件系統(tǒng)、魔法幻數(shù)檢查和語(yǔ)言檢查3個(gè)過(guò)程答毫。
maple@maple-All-Series:~/AndroidStudioProjects/FFmpegDemo/app/src/main/jni$ file libavcodec-57.so
libavcodec-57.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=8de4e7be651e4db057b11d72e33fffd8d19d40dd, stripped
可知這個(gè)so是x86-64類型褥民,所以Application.mk中應(yīng)該這樣:
APP_ABI :=x86