1. Toolchain for compile (This NDK version is r8)
a. Android’s NDK allows we to create toolchain installation using “make-standalone-toolchain.sh” script.
b. Execute like below.
$> /home/bywyu/android/android-ndk-r8b/build/tools/make-standalone-toolchain.sh –platform=android-14 –install-dir=/home/bywyu/work/video/lib/x264/build/new-android-toolchain
c. You can use directly with PATH, CC setting.
export PATH=/home/bywyu/work/video/lib/x264/build/arm-linux-androideabi-4.6/bin:$PATH
export CC=arm-linux-androideabi-gcc
d. Done
2. Compile & Build x264 project for FFMpeg library.
a. Download x264 project (http://www.videolan.org/developers/x264.html)
$> make
$> make install
d. Done. You can find the library & include files in –prefix option’s directory.
3. Compile & Build FFMpeg project.
a. Download FFMpeg source code from http://ffmpeg.org/download.html (This case is FFmpeg 2.0 version)
–enable-libx264 \
–cross-prefix=arm-linux-androideabi- \
–enable-cross-compile \
–target-os=linux \
–arch=arm \
–enable-gpl \
$> make
e. Make install
$> make install
a. Android’s NDK allows we to create toolchain installation using “make-standalone-toolchain.sh” script.
b. Execute like below.
$> /home/bywyu/android/android-ndk-r8b/build/tools/make-standalone-toolchain.sh –platform=android-14 –install-dir=/home/bywyu/work/video/lib/x264/build/new-android-toolchain
c. You can use directly with PATH, CC setting.
export PATH=/home/bywyu/work/video/lib/x264/build/arm-linux-androideabi-4.6/bin:$PATH
export CC=arm-linux-androideabi-gcc
d. Done
2. Compile & Build x264 project for FFMpeg library.
a. Download x264 project (http://www.videolan.org/developers/x264.html)
b. Configuration for arm compile. (prefix option is very important for FFMpeg compiling.)
#!/bin/bash
export PATH=$PATH:~/x264/x264/build/new-android-toolchain/arm-linux-androideabi-4.6/bin
export CC=~/x264/x264/build/new-android-toolchain/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-gcc
./configure \
--host=arm-linux \
--cross-prefix=arm-linux-androideabi- \
--enable-shared \
--enable-static \
--prefix=~/x264/x264/build/new-android-toolchain/arm-linux-androideabi-4.6/sysroot/usr
-c. make / install
$> make
$> make install
d. Done. You can find the library & include files in –prefix option’s directory.
3. Compile & Build FFMpeg project.
a. Download FFMpeg source code from http://ffmpeg.org/download.html (This case is FFmpeg 2.0 version)
b. Configuration for arm compile.
$> ./configure –enable-shared \–enable-libx264 \
–cross-prefix=arm-linux-androideabi- \
–enable-cross-compile \
–target-os=linux \
–arch=arm \
–enable-gpl \
–prefix=/work/my-android-toolchain/sysroot/usr
#!/bin/bash
# For arm gcc
export PATH=$PATH:~/x264/x264/build/new-android-toolchain/arm-linux-androideabi-4.6/bin
# For libx264 header and libs
export PATH=$PATH:~/x264/x264/build/new-android-toolchain/arm-linux-androideabi-4.6/sysroot/usr/lib:~/x264/x264/build/new-android-toolchain/arm-linux-androideabi-4.6/sysroot/usr/include
export CC=~/x264/x264/build/new-android-toolchain/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-gcc
./configure --prefix=../ffmpeg_build \
--enable-gpl \
--enable-shared \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-debug \
--disable-network \
--disable-protocols \
--disable-devices \
--disable-encoders \
--disable-decoders \
--disable-muxers \
--disable-demuxers \
--disable-parsers \
--disable-bsfs \
--disable-filters \
--enable-encoder=h264 \
--enable-libx264 \
--extra-cflags=-U__STRICT_ANSI__ \
--target-os=linux \
--extra-cflags="-fno-short-enums" \
--extra-ldflags="-mandroid -lm" \
--enable-cross-compile \
--cross-prefix=arm-linux-androideabi- \
--arch=arm
d. Make
$> make
e. Make install
$> make install
f. Done. You can see the library and header in ../ffmepg_build directory (in the prefix option)
个人心得:
交叉编译的关键在于设置独立的工具连(gcc,as,ld等)和系统库(c,c++等)。这里就是通过设置CC和PATH分别指定的。
然后就可以简单的设置所需编译的源码包的
--cross-prefix(交叉编译的前缀)
--target-os:目标机的os
--arch:目标机的cpu架构体系
当然,别忘了用--enable-cross-compile
其它的配置,就要看具体的源代码包了