转载自: http://blog.csdn.net/ytzys/article/details/47302123
1. 环境搭建
1.1 安装cygwin,并安装git,make,ysam
具体安装过程网上有很多资料,不再详述。
1.2 android sdk和android ndk下载和安装
参见网上资料
1.3 下载ijkplayer源码
<code class="hljs php has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">git <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">clone</span> https:<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//github.com/Bilibili/ijkplayer.git ijkplayer</span>
cd ijkplayer
git checkout -B latest k0<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.3</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.1</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>
1.4 设置环境变量
在cygwin的home目录下,修改 ~/.bash_profile 或 ~/.profile文件,添加
<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> ANDROID_SDK=<your sdk path>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> ANDROID_NDK=<your ndk path></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>
其中的路径根据实际情况填写。
2. 编译过程
进入ijkplayer源码根目录
<code class="language-bash hljs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">cd</span> config
rm module.sh
ln <span class="hljs-operator" style="box-sizing: border-box;">-s</span> module-default.sh module.sh
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#以上是默认的设置,也可以使用</span>
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># ln -s module-lite.sh module.sh</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li></ul>
回到ijkplayer源码根目录
<code class="language-bash hljs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># 下载ffmpeg源码</span>
./init-android.sh
<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">cd</span> android/contrib
./compile-ffmpeg.sh clean
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#编译ffmpeg,,以armv7a架构的cpu代码为例进行编译</span>
./compile-ffmpeg.sh armv7a
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#编译ijkplayer</span>
<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">cd</span> ..
./compile-ijk.sh armv7a</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li></ul>
如果编译成功的话,会在
F:\\ijkplayer\android\ijkplayer\player-armv7a\src\main\libs\armeabi-v7a下生成三个so库文件
![编译生成的共享库](https://img-blog.csdn.net/20150805190929629)
3. 编译过程中容易出问题的地方
注意:该步容易出问题,我在开始时编译只生成了一个libijkffmpeg.so。原因是F:\\ijkplayer\android\ijkplayer\player-armv7a\src\main\jni下使用了软链接,ijkmedia和android-ndk-prof分别链接到ijkplayer根目录下的/ijkmedia和/ijkprof,而cygwin和android NDK在处理文件夹软链接时似乎有问题,所以并没有执行ijkmedia和ijkprof的编译。
基于以上问题,可以做如下修改
-
将ijkmedia和ijkprof的makefile文件写在F:\ijkplayer\android\ijkplayer\player-armv7a\src\main\jni\Android.mk
文件的最后,用include包含进来
![这里写图片描述](https://img-blog.csdn.net/20150805193643477)
-
删除F:\ijkplayer\android\ijkplayer\player-armv7a\src\main\jni下的ijkmedia和android-ndk-prof
-
将compile-ijk.sh中生成android-ndk-prof链接文件的部分注释掉
![这里写图片描述](https://img-blog.csdn.net/20150805192435833)
4. 将工程导入eclipse中,编译并运行
<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">File <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-> </span><span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">New</span> <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-> </span>Project <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-> </span>Android Project from Existing Code
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">Select</span> android<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">/</span> <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">and</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">import</span> <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">all</span> project</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>
编译后在真机运行即可
5. 参考文献
ijkplayer的github主页:https://github.com/Bilibili/ijkplayer