The ‘Pods-App’ target has transitive dependencies that include static binaries:修改

背景

最近遇到了两次次这个问题,都是Swift项目Pod添加库开启了use_frameworks!,安装某些OC库时报错;花了好久时间解决,突然想起来之前OC项目安装Swift库也遇到了这个问题,但是之前没有记录,所以这次遇到时没有印象;这次记录下来,分享给大家:

解决方案

之前遇到的是OC代码安装ZLPhotoBrowser的Swift库,开启了use_frameworks!,和其他第三方库一起安装时,可以理解为,除了ZLPhotoBrowser是动态库,其他的第三方库默认都使用static_framework或者static_library

Pod文件末尾添加下面代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

use_frameworks!

...

dynamic_frameworks = ['ZLPhotoBrowser']
pre_install do |installer|
installer.pod_targets.each do |pod|
if !dynamic_frameworks.include?(pod.name)
def pod.static_framework?;
true
end
def pod.build_type;
Pod::BuildType.static_library
end
end
end
end

这次是Swift代码安装Pod库,同样开启了use_frameworks!,但是这里想要的是除了某些库使用static_framework或者static_library,其他库都默认使用use_frameworks!

所以Pod文件末尾添加的代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

use_frameworks!

...

# 要使用OC的第三方库
static_frameworks = ['xxx', 'yyy']
pre_install do |installer|
installer.pod_targets.each do |pod|
# 注意这里和上面的不同
if static_frameworks.include?(pod.name)
def pod.static_framework?;
true
end
def pod.build_type;
Pod::BuildType.static_library
end
end
end
end