iOS (oc)图像架构

CocoaPods安装SDWebImage/WebP(免番强)

2018-06-13  本文已影响104人  WillPan

项目突然不显示WebP格式的图片,所以要安装SDWebImage/WebP子库,修改下Podfile:

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

target 'CocoaPodsDDD' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for CocoaPodsDDD 
  pod 'SDWebImage'
  pod 'SDWebImage/WebP'

end

然后pod install发现

CocoaPodsDDD git:(master) ✗ pod install
Analyzing dependencies
Downloading dependencies
Installing SDWebImage 4.4.1 (was 4.4.1)
Installing libwebp (0.6.1)

[!] Error installing libwebp
[!] /usr/bin/git clone https://chromium.googlesource.com/webm/libwebp /var/folders/8j/9jfm_2xx54q89tzs0sfn7nxr0000gn/T/d20180613-76555-1d5w7hk --template= --single-branch --depth 1 --branch v0.6.1

Cloning into '/var/folders/8j/9jfm_2xx54q89tzs0sfn7nxr0000gn/T/d20180613-76555-1d5w7hk'...
fatal: unable to access 'https://chromium.googlesource.com/webm/libwebp/': Failed to connect to chromium.googlesource.com port 443: Operation timed out

原因:chromium.googlesource.com 被墙

解决办法1:让Mac终端走代理

打开小飞机,自动代理模式
如果你使用的是zsh:

$ vim ~/.zshrc

添加如下代理配置(完了按:wq保存退出):

# proxy list
alias proxy='export all_proxy=socks5://127.0.0.1:1080'
alias unproxy='unset all_proxy'

然后

$ source ~/.zshrc

如果你使用的是Mac自带终端:

$ vim ~/.bashrc

添加如下代理配置(完了按:wq保存退出):

# proxy list
alias proxy='export all_proxy=socks5://127.0.0.1:1080'
alias unproxy='unset all_proxy'

然后

$ source ~/.bashrc

然后pod install即可

解决办法2:使用镜像

观察SDWebImage仓库的SDWebImage.podspec文件会发现以下配置:

s.subspec 'WebP' do |webp|
    webp.source_files = 'SDWebImage/UIImage+WebP.{h,m}', 'SDWebImage/SDWebImageWebPCoder.{h,m}'
    webp.xcconfig = { 
      'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) SD_WEBP=1',
      'USER_HEADER_SEARCH_PATHS' => '$(inherited) $(SRCROOT)/libwebp/src'
    }
    webp.watchos.xcconfig = {
      'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) SD_WEBP=1 WEBP_USE_INTRINSICS=1',
      'USER_HEADER_SEARCH_PATHS' => '$(inherited) $(SRCROOT)/libwebp/src'
    }
    webp.dependency 'SDWebImage/Core'
    webp.dependency 'libwebp', '~> 0.5'
  end

SDWebImage/WebP依赖libwebp库,但是安装libwebp库的时候无法指定源,所以要先安装libwebp(此时换成github镜像),再安装SDWebImage/WebP即可

查看mac中cocoapods本地库对应的libwebp版本的配置文件
终端输入find ~/.cocoapods/repos/master -iname libwebp(10秒后按Ctrl+C终止查找),会得到一个SDWebImage/WebP依赖的库的spec路径

> find ~/.cocoapods/repos/master -iname libwebp
/Users/you_mac_name/.cocoapods/repos/master/Specs/1/9/2/libwebp

Finder进入/Users/you_mac_name/.cocoapods/repos/master/Specs/1/9/2/libwebp此目录会发现几个版本的libwebp库spec文件:

这里打开0.6.0文件夹,复制libwebp.podspec.json文件到自己项目根目录
修改libwebp.podspec.json文件里12行:
"git": "https://chromium.googlesource.com/webm/libwebp"
"git": "https://github.com/webmproject/libwebp"

然后运行pod install即可

参考:
Mac OSX终端走shadowsocks代理
# iOS使用cocoapods 安装libwebp 0.6.0遇到Error installing libwebp解决方法

你真的会写Podfile吗?

上一篇下一篇

猜你喜欢

热点阅读