一、搭建Linux编译环境,如果有Linux环境可以省略。
1.下载centos6.8.iso映像文件,下载网址:http://archive.kernel.org/centos-vault/6.8/isos/x86_64/CentOS-6.8-x86_64-bin-DVD1.iso
2.下载安装虚拟机:VMware-workstation-full-14.1.3-9474260.exe
3.安装虚拟机,安装centos6.8系统

4.运行centos6.8系统的虚拟机,实现centos系统与本机windows系统文件共享
4.1.运行centos系统,记住以root用户登录,点击虚拟机->重新安装VMware Tools(T)...

4.2.会弹出一个窗口,复制这个文件VMwareTools.xxxx.tar.gz到/mnt/cdrom 目录下,如果没有这个目录则创建

4.3.运行命令 tar -zxvf VMwareTools-xx.tar.gz 解压这个文件
4.4.这时你会发现有这个目录

4.5.打开命令行,进入到vmware-tools-distrib目录里面运行命令:./vmware-install.pl

4.6.设置共享目录,实现两个系统文件共享


把share文件设置成共享文件

把下载的android-ndk-r14b-linux-x86_64.zip放到share目录里面

重新启动虚拟机centos系统,这时你进入centos系统,打开/mnt/hgfs目录里面可以看到一个share目录

这样就实现centos和windows文件共享了,以后方便把编译完成的.so文件拷贝出来。
接下来就是重要的步骤了,睁大眼睛看清楚
二.搭建ndk环境。
1.我们先在/mnt目录下面新建一个ndk_build目录。
2.把/mnt/hgfs/share目录里面的android-ndk-r14b-linux-x86_64.zip文件拷贝到ndk_build目录下面,打开命令行,cd/mnt/ndk-build->运行命令
unzip android-ndk-r14b-linux-x86_64.zip


这时会生成一个android-ndk-r14b

配置全局ndk路径:命令行输入命令:vim ~/.bashrc

保存退出,运行命令:
source ~/.bashrc//执行环境变量
ndk-build//查看是否安装成功,只要不是显示ndk-build not found,则表示安装成功
这时ndk就搭建好了
三.安装c++环境,运行命令:yum install gcc-c++
四.编译ffmpeg
1.在/mnt目录下新建ffmpeg目录
2.打开命令行,进入到该目录下:下载ffmpeg,并且解压

3.找到configure文件,并且替换里面的一些设置:
将该文件中的如下四行:
SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'
SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR)$(SLIBNAME)'
替换为
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)'

保存文件
4.新建文件android_build.sh


打开该文件,粘贴以下代码:
#!/bin/bash
make clean
export NDK=/mnt/ndk_build/android-ndk-r14b
export SYSROOT=$NDK/platforms/android-9/arch-arm/
export TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
export CPU=arm
export PREFIX=$(pwd)/android/$CPU
export ADDI_CFLAGS="-marm"
./configure --target-os=linux
--prefix=$PREFIX --arch=arm
--disable-doc
--enable-shared
--disable-static
--disable-yasm
--disable-symver
--enable-gpl
--disable-ffmpeg
--disable-ffplay
--disable-ffprobe
--disable-ffserver
--disable-doc
--disable-symver
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi-
--enable-cross-compile
--sysroot=$SYSROOT
--extra-cflags="-Os -fpic $ADDI_CFLAGS"
--extra-ldflags="$ADDI_LDFLAGS"
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install

5.对android_build.sh授权,运行命令:chmod -R 777 ./android_build.sh

然后运行./android_build.sh

然后开始编译了.
编译成功之后会有这个文件



至此,动态库文件就生成好了,这样就可以在android上引用啦。
网友评论