ijkplayer 的编译、打包 framework

1.准备工作

安装 homebrew, git, yasm. (如果已经安装好可以跳过, 不清楚的再来一遍也无妨)

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew install git

brew install yasm

2.获取 ijkplayer 源码

在一个合适的位置新建一个文件夹, 假设为桌面, 文件夹名为ijkplayer.

打开终端, 输入下面的指令

# 进入到刚刚新建的文件夹内cd ~/Desktop/ijkplayer/# 获取ijkplayer源码git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios# 进入源码目录cd ijkplayer-ios# 切换分支 (目前为k0.8.8, 可以自行去GitHub查看最新版本号)git checkout -B latest k0.8.8

3.配置编解码器格式支持

默认为最少支持, 如果足够你使用, 可以跳过这一步. 否则可以改为以下配置:

module-default.sh更多的编解码器/格式

module-lite-hevc.sh较少的编解码器/格式(包括hevc)

module-lite.sh较少的编解码器/格式(默认情况)

# 进入 config 目录cd config# 删除当前的 module.sh 文件rm module.sh# 可根据需要替换为`module-default.sh`, `module-lite-hevc.sh`, `module-lite.sh`# 创建软链接 module.sh 指向 module-lite-hevc.shln -s module-lite-hevc.sh module.shcd ..cd iossh compile-ffmpeg.sh clean

4.获取 ffmpeg 并初始化

cd .../init-ios.sh

5.添加 https 支持

最后会生成支持 https 的静态文件libcrypto.a和libssl.a, 如果不需要可以跳过这一步

# 获取 openssl 并初始化./init-ios-openssl.shcd ios# 在模块文件中添加一行配置 以启用 openssl 组件echo 'export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-openssl"' >> ../config/module.sh./compile-ffmpeg.sh clean

6.编译

# 如果下一步提示错误`xcrun: error: SDK "iphoneos" cannot be located`, 请执行`sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/`, 再重新执行下一步# 编译openssl, 如果不需要https可以跳过这一步./compile-openssl.sh all# 编译ffmpeg./compile-ffmpeg.sh all

ps: 如果提示错误:

./libavutil/arm/asm.S:50:9: error: unknown directive        .arch armv7-a        ^make: *** [libavcodec/arm/aacpsdsp_neon.o] Error 1

最新的 Xcode 已经弱化了对 32 位的支持, 解决方法:

在compile-ffmpeg.sh中删除armv7, 修改如:

需要把compile-ffmpeg.sh中的armv7去掉之后再次执行./compile-ffmpeg.sh clean,./compile-ffmpeg.sh all

第24行 改为: FF_ALL_ARCHS_IOS8_SDK="arm64 i386 x86_64" 

第120行 改为: if [ "$FF_TARGET" = "armv7s" -o "$FF_TARGET" = "arm64" ]; then 

第159行 改为: echo " compile-ffmpeg.sh arm64|i386|x86_64" 

因为之前没有编译armv7的版本,真机编译的时候可能会出现'armv7/avconfig.h' file not found和'armv7/config.h' file not found错误。都需要把avconfig.h和config.h中的include "armv7/config.h"和include "armv7/avconfig.h"注释掉。

armv7/avconfig.h文件在xcode中找不到可以到ijkplayer-ios/ios/build/universal/include/libavutil/avconfig.h找,或者再编译后出现的build文件夹中搜索。

用命令:

open IJKMediaPlayer/IJKMediaPlayer.xcodeproj

或者手动用 Xcode 打开 ios 目录下的 IJKMediaPlayer 项目.

添加 openssl 相关包以支持 https

如果不使用 https, 可以跳过此步, 直接开始打包 framwork

如果使用 https, 那么需要手动给 IJKMediaFramework 添加libcrypto.a和libssl.a文件, 默认不会添加

ps: 这两个依赖库的目录为: ijkplayer-ios/ios/build/universal/lib, 只有进行了上面跟 openssl 相关的操作, 才会在这个目录下有生成libcrypto.a和libssl.a


7.打包 framwork



1.Xcode12适配The linked library is missing one or more architectures required by this target问题:

解决办法:在Target-Build Settings-Excluded Architectures中添加以下代码

EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64=arm64 arm64e armv7 armv7s armv6 armv8 EXCLUDED_ARCHS=$(inherited)$(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT))

2.打包framwork时可能会出现无法合成真机和模拟器framework的问题:

 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework and Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework have the same architectures (arm64) and can't be in the same fat output file

解决办法:

Build Settings -> Excluded Architectures里按照这样设置一下,再编译合并就不会报错了。

大家会发现除了IJKMediaFramework这个 target, 还有一个叫IJKMediaFrameworkWithSSL, 但是不推荐使用这个, 因为大部分基于 ijkplayer 的第三方框架都是使用的前者, 你把后者导入项目还是会报找不到包的错误, 就算你要支持 https 也推荐使用前者, 然后按照上一步添加 openssl 即可支持

配置 Release 模式如果下图

[email protected]

[email protected]

打包真机 framework

选择你连接的手机或者Generic iOS Device

[email protected]

如图操作,然后按键command+b编译即可

如果之前的步骤删除了compile-ffmpeg.sh中armv7, 这里会报错, 我们直接注释掉就好

[email protected]

[email protected]

打包模拟器 framework

[email protected]

如图操作,然后command+b编译即可

合并 framework

如果只需要真机运行或者模拟器运行, 可以不用合并, 直接找到对应的 framework 导入项目即可; 一般我们为了方便会合并 framework, 这样就同时支持模拟器和真机运行.

先找到生成 framework 的目录:

[email protected]

[email protected]

准备合并:

打开终端, 先cd到Products目录下

然后执行:lipo -create 真机framework路径 模拟器framework路径 -output 合并的文件路径

lipo -create Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework -output IJKMediaFramework

合并完成:

可以看到这里生成了一个大概两倍大小的文件, 将生成的IJKMediaFramework文件替换掉真机framework中的IJKMediaFramework文件,然后这个替换掉文件的真机framework就是我们需要的通用的framework了。

[email protected]

[email protected]

集成 framework 到项目中

导入 framework

直接将IJKMediaFramework.framework拖入到工程中即可

注意记得勾选Copy items if needed和 对应的target

添加下列依赖到工程

libc++.tbd( 编译器选 gcc 的请导入libstdc++.tbd)

libz.tbd

libbz2.tbd

AudioToolbox.framework

UIKit.framework

CoreGraphics.framework

AVFoundation.framework

CoreMedia.framework

CoreVideo.framework

MediaPlayer.framework

MobileCoreServices.framework

OpenGLES.framework

QuartzCore.framework

VideoToolbox.framework

导入 ijkplayer 头文件运行一下项目, 如果遇到了类似这样的错误:

[email protected]

可能是因为导入的依赖库不全, 比如缺少 libc++.tbd, 请再次对照添加好所有的依赖库:

你可能感兴趣的:(ijkplayer 的编译、打包 framework)