一、环境准备
Mac系统版本:12.0.1 (21A559)
Xcode版本:13.1 (13A1030d)
brew --version
git --version
yasm --version
pkg-config --version
未完成安装的,安装下所缺少的
- 安装
brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 卸载
brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
- 使用
brew
安装git
brew install git
- 使用
brew
安装yasm
brew install yasm
-
使用brew
安装pkg-config
brew install pkg-config
完成后
二、下载ffmpeg
- 克隆仓库到本地
//克隆仓库到指定位置并重命名为ijkplayer-ios
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios
- 新增一个本地分支(可选项)
git checkout -B latest k0.8.8
- 下载
ffmpeg
(常见错误见下面错误锦集)
./init-ios.sh
- 下载成功后进入
ios
文件夹
cd ios
三、编译 fffmpeg
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all
编译过程中可能会出现 error2
四、打包framework
- 打开
ios/IJKMediaPlayer
并运行 -
调整target
-
调整运行模式
- 分别编译模拟器和真机
编译成功之后command + ,
前往xcode设置页 👉 Lications 👉 Derived Data 👉 IJKMediaPlayer-xxx 👉 Build 👉 Products
cd
到 Products
文件夹下合并真机和模拟器的framework
执行命令: lipo -create 真机framework路径 模拟器framework路径 -output 合并的文件路径
lipo -create Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework -output IJKMediaFramework
执行成功后Products
文件夹下会生成 IJKMediaFramework
五、集成framework
错误锦集
error1
Cloning into 'ios/ffmpeg-x86_64'...
fatal: unable to access 'https://github.com/Bilibili/FFmpeg.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
tools/pull-repo-ref.sh: line 11: cd: ios/ffmpeg-x86_64: No such file or directory
./init-ios.sh: line 64: cd: ios/ffmpeg-x86_64: No such file or directory
Cloning into 'ios/ffmpeg-i386'...
fatal: unable to access 'https://github.com/Bilibili/FFmpeg.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
tools/pull-repo-ref.sh: line 11: cd: ios/ffmpeg-i386: No such file or directory
./init-ios.sh: line 64: cd: ios/ffmpeg-i386: No such file or directory
这个问题是无法链接Bilibili服务器,搞了大半天,最后还是用手机热点才下载成功!建议切换网络多试几次
error2
AS libavcodec/arm/aacpsdsp_neon.o
CC libavcodec/arm/blockdsp_init_arm.o
./libavutil/arm/asm.S:50:9: error: unknown directive
.arch armv7-a
^
make: *** [libavcodec/arm/aacpsdsp_neon.o] Error 1
make: *** Waiting for unfinished jobs....
clang: warning: optimization flag '-fomit-frame-pointer' is not supported for target 'armv7' [-Wignored-optimization-argument]
最新的 Xcode 已经弱化了对 32 位的支持, 解决方法:
在 compile-ffmpeg.sh
中删除 armv7 ,
修改前后对如下
修改之后,再重新执行出现错误的命令: ./compile-ffmpeg.sh all
error 3
The linked library 'libavcodec.a' is missing one or more architectures required by this target: armv7.
xcode12之后 编译真机的时候会出现该错误
解决思路是在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))
error4
执行合并framework时可能会报错
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 Setting 👉 Excluded Architectures 👉Debug 👉添加上 arm64
设置 Build Setting 👉 Excluded Architectures 👉Release 👉添加上 arm64
出现的原因是XCode12
编译的模拟器库新增支持架构arm64
。将模拟器的arm64
给排除出去即可。