上传SDK时pod spec lint遇到的错误

`不久前把封装的AFN的SDK上传到了cocoapods上,最后pod spec lint时遇到了不少问题,这里总结下。

[!] Invalid `TYNetworkTool.podspec` file: can't find string "DESC" anywhere before EOF
TYNetworkTool.podspec:6: syntax error, unexpected end-of-input, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END.

 #  from TYNetworkTool.podspec:17
 #  -------------------------------------------
 #    s.dependency "YYCache"
 >  end
 #  -------------------------------------------


Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run: 
    `echo "2.3" > .swift-version`.

复制的别人的podspec文件的缘故,而且不是很了解内容的作用,没有开头与end对应,在开头输入Pod::Spec.new do |s|形成包围即可。
The validator for Swift projects uses Swift 3.0 by default把Swift升级下就好了,输入echo "3.0" > .swift-version命令即可。

[!] Invalid `TYNetworkTool.podspec` file: syntax error, unexpected tIDENTIFIER, expecting '}'
  s.platform     = :ios
   ^
TYNetworkTool.podspec:11: syntax error, unexpected tIDENTIFIER, expecting '}'
  s.reqiores_arc = true
   ^
TYNetworkTool.podspec:16: syntax error, unexpected keyword_end, expecting end-of-input.

 #  from TYNetworkTool.podspec:8
 #  -------------------------------------------
 #    s.author             = { "MasazumiQi" => "[email protected]" 
 >    s.platform     = :ios
 #    s.platform     = :ios, "7.0"
 #  -------------------------------------------


Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error.

可以看出是s.author = { "MasazumiQi" => "[email protected]"的低级错误,改为s.author = { "MasazumiQi" => "[email protected]" } #作者及联系方式就可以了。

 -> TYNetworkTool.podspec
    - ERROR | spec: The specification defined in `TYNetworkTool.podspec` could not be loaded.


[!] Invalid `TYNetworkTool.podspec` file: undefined local variable or method `s' for Pod:Module.

 #  from TYNetworkTool.podspec:1
 #  -------------------------------------------
 >    s.name         = "TYNetworkTool"
 #    s.version      = "0.0.1"
 #  -------------------------------------------


Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error.

Pod::Spec.new do |s|s要与‘|s|’的名字对应。

    TYNetworkTool
 -> TYNetworkTool (0.0.1)
    - WARN  | summary: The summary is not meaningful.
    - ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error and 1 warning.

[!] Unable to load a podspec from `TYNetworkTool.podspec`, skipping:

Pod::DSLError

s.source_files = "TYNetworkTool/*.{h,m}"的路径很重要,上文表示在与podspec同级目录中的TYNetworkTool文件夹下的.h.m文件全都是有效文件。

 -> TYNetworkTool (0.0.2)
    - WARN  | summary: The summary is not meaningful.
    - WARN  | xcodebuild:  TYNetworkTool/TYNetworkTool/TYCacheTool.m:11:17: warning: method definition for 'setHttpCache:URL:parameters:' not found [-Wincomplete-implementation]
    - NOTE  | xcodebuild:  TYNetworkTool/TYNetworkTool/TYCacheTool.h:22:1: note: method 'setHttpCache:URL:parameters:' declared here
    - WARN  | xcodebuild:  TYNetworkTool/TYNetworkTool/TYCacheTool.m:11:17: warning: method definition for 'httpCacheForURL:parameters:' not found [-Wincomplete-implementation]
    - NOTE  | xcodebuild:  TYNetworkTool/TYNetworkTool/TYCacheTool.h:32:1: note: method 'httpCacheForURL:parameters:' declared here
    - WARN  | xcodebuild:  TYNetworkTool/TYNetworkTool/TYCacheTool.m:11:17: warning: method definition for 'getAllHttpCacheSize' not found [-Wincomplete-implementation]
    - NOTE  | xcodebuild:  TYNetworkTool/TYNetworkTool/TYCacheTool.h:35:1: note: method 'getAllHttpCacheSize' declared here
    - WARN  | xcodebuild:  TYNetworkTool/TYNetworkTool/TYCacheTool.m:11:17: warning: method definition for 'removeAllHttpCache' not found [-Wincomplete-implementation]
    - NOTE  | xcodebuild:  TYNetworkTool/TYNetworkTool/TYCacheTool.h:39:1: note: method 'removeAllHttpCache' declared here
    - WARN  | [iOS] xcodebuild:  TYNetworkTool/TYNetworkTool/TYNetworkTool.m:236:70: warning: values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead [-Wformat]

 -> TYNetworkTool (0.0.4)
    - ERROR | attributes: Missing required attribute `summary`.
    - ERROR | [iOS] unknown: Encountered an unknown error (undefined method `dirname' for nil:NilClass) during validation.

Analyzed 1 podspec.

我只能说,厉害啊,特么代码都管的。。.h上对外公开的方法,.m必须有实现。NSUInteger也不能用,改unsigned long这类根据提示修改就行了。
然后出了这么多问题后,终于没问题了。

·
·
·
以下是我没遇到但是看到别人写了,有必要记录下,方便以后找

没有建demo工程并上传到GitHub。只传了Class文件,这个时候验证podspec是通不过的。

会报如下错误:

-> XLPhotoBrowser (1.0.0)
- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.

作者:sxtra
链接:http://www.jianshu.com/p/e5209ac6ce6b
來源:
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。```
```5.5.如果依赖了其它CocoaPods第三方库
请使用s.dependency
配置,如s.dependency "SDWebImage", "~> 3.7.1"

配参过程中可参考以下附录内容,或查看链接:[https://github.com/xiaoL0204/XLPhotoBrowser/blob/master/XLPhotoBrowser.podspec](https://github.com/xiaoL0204/XLPhotoBrowser/blob/master/XLPhotoBrowser.podspec)

作者:sxtra链接:http://www.jianshu.com/p/e5209ac6ce6b來源:著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。```
```忘记打tag

报错如下,使用git tag 1.0.0命令即可

Validating podspec
 -> XLPhotoBrowser (1.0.0)
    - ERROR | [iOS] unknown: Encountered an unknown error ([!] /Applications/Xcode.app/Contents/Developer/usr/bin/git clone https://github.com/xiaoL0204/XLPhotoBrowser.git /var/folders/w1/95fypdq96l92t55frcn0yhyh0000gn/T/d20161206-1790-put1kd --template= --single-branch --depth 1 --branch 1.0.0

Cloning into '/var/folders/w1/95fypdq96l92t55frcn0yhyh0000gn/T/d20161206-1790-put1kd'...
warning: Could not find remote branch 1.0.0 to clone.
fatal: Remote branch 1.0.0 not found in upstream origin
) during validation.

[!] The spec did not pass validation, due to 1 error.

作者:sxtra
链接:http://www.jianshu.com/p/e5209ac6ce6b
來源:
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。```
  1. ERROR | spec: The specification defined in LZTool.podspec could not be loaded.

MacBook:PodTest Artron_LQQ$ pod lib lint LZTool.podspec

-> LZTool.podspec
- ERROR | spec: The specification defined in LZTool.podspec could not be loaded.

[!] Invalid LZTool.podspec file: syntax error, unexpected tIDENTIFIER, expecting keyword_end
...<-DESC 这是一个测试文档, 这里主要是描述类库...
... ^
LZTool.podspec:28: syntax error, unexpected '\n', expecting '='.

from LZTool.podspec:27

-------------------------------------------

# * Finally, don't worry about the indent, CocoaPods strips it!

s.description = <<-DESC 这是一个测试文档, 这里主要是描述类库的功能设计初衷介绍

DESC

-------------------------------------------

[!] LZTool.podspec did not pass validation, due to 1 error.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a .swift-version file to set the version for your Pod. For example to use Swift 2.3, run:
echo "2.3" > .swift-version.
You can use the --no-clean option to inspect any issue.
MacBook:PodTest Artron_LQQ$
这个错误是使用指令 pod lib lint LZTool.podspec 检查文件是否合法时发生的;

可以看出是在设置 s.description 字段时发生的错误, 当时的写法是:

s.description = <<-DESC LZTool 是一个用于保存一些常用工具类的工具 DESC
以为可以吧他们并到一行, 导致一直报这个错, 后来写成两行, 还是报错, 最后才试出这样写才对:

s.description = <<-DESC
LZTool 是一个用于保存一些常用工具类的工具
DESC

作者:流火绯瞳
链接:http://www.jianshu.com/p/283584683b0b
來源:
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。```

3. fatal: Remote branch 0.0.1 not found in upstream origin

MacBook:PodTest Artron_LQQ$ pod spec lint

 -> LZTool (0.0.1)
    - ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/LQQZYY/PodTest.git /var/folders/14/95vmx0495_s5292ltvwpsc8h0000gn/T/d20170111-11240-1l3iq9n --template= --single-branch --depth 1 --branch 0.0.1

Cloning into '/var/folders/14/95vmx0495_s5292ltvwpsc8h0000gn/T/d20170111-11240-1l3iq9n'...
warning: Could not find remote branch 0.0.1 to clone.
fatal: Remote branch 0.0.1 not found in upstream origin
) during validation.

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run: 
    `echo "2.3" > .swift-version`.
MacBook:PodTest Artron_LQQ$
这个是使用指令pod spec lint来检查文件是否可用时发生的错误;

这是因为在你托管代码的库里(这里是指github)找不到这个分支, 也就是在编辑 LZTool.podspec时, 里面的字段s.verson, s.source 中的 tag与github创建的release版本号不一致导致, 修改为一样即可!

作者:流火绯瞳
链接:http://www.jianshu.com/p/283584683b0b
來源:
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
4. 加载xib问题

PS: 这个不是我个人遇到的问题, 是在文章中看到, 这里记录一下;
如果通过cocoapods下载的类库中含有Xib文件, 使用原来的方式初始化就不起作用了:

[[[NSBundle mainBundle] loadNibNamed:@"xibName" owner:self options:nil] lastObject];
[self.collectionView registerNib:[UINib nibWithNibName:@"xibName" bundle:nil] forCellWithReuseIdentifier:@"ZLCollectionCell"];
应该使用下面这种方式初始化:

#define kZLPhotoBrowserBundle [NSBundle bundleForClass:[self class]]
[[kZLPhotoBrowserBundle loadNibNamed:@"ZLPhotoActionSheet" owner:self options:nil] lastObject];
[self.collectionView registerNib:[UINib nibWithNibName:@"ZLCollectionCell" bundle:kZLPhotoBrowserBundle] forCellWithReuseIdentifier:@"ZLCollectionCell"];
这样就能正常使用了;

作者:流火绯瞳
链接:http://www.jianshu.com/p/283584683b0b
來源:
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
5.加载图片资源问题
PS: 这个问题我尝试了一个demo, 直接设置了** s.resources = "LZScaner/images/*.png"** , 图片也能正常显示( 可参考我设置的**podspec**文件[LZScaner.podspec](https://github.com/LQQZYY/LZScanner_OC/blob/master/LZScaner.podspec) )没有遇到这个问题, 但是还是把这个方式记录一下吧...

如果通过代码** "[UIImage imageNamed:@"picName"]"** 去设置图片的话,则图片资源有可能无法正常显示, 可通过以下方式解决:
创建bundle资源目录command+N -> Resource -> Settings Bundle

删除bundle携带的无用文件,把图片资源添加到**bundle**资源内
改变代码图片路径// 图片路径#define kZLPhotoBrowserSrcName(file) [@"ZLPhotoBrowser.bundle" stringByAppendingPathComponent:file]#define kZLPhotoBrowserFrameworkSrcName(file) [@"Frameworks/ZLPhotoBrowser.framework/ZLPhotoBrowser.bundle" stringByAppendingPathComponent:file]kZLPhotoBrowserSrcName(file) 为通过copy文件夹方式获取图片路径的宏kZLPhotoBrowserFrameworkSrcName(file) 为通过cocoapods下载安装获取图片路径的宏

然后修改代码中设置图片的方式如下UIImage *img = [UIImage imageNamed:kZLPhotoBrowserSrcName(@"img.png")]?:[UIImage imageNamed:kZLPhotoBrowserFrameworkSrcName(@"img.png")];

其**podspec**地址: [ZLPhotoBrowser.podspec](https://github.com/longitachi/ZLPhotoBrowser/blob/master/ZLPhotoBrowser.podspec) 可以参考学习!

作者:流火绯瞳链接:http://www.jianshu.com/p/283584683b0b來源:著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
7. xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information

MacBook:LZSortTool Artron_LQQ$ pod spec lint

 -> LZSortTool (0.0.1)
    - WARN  | [iOS] license: Unable to find a license file
    - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
    - NOTE  | [iOS] xcodebuild:  LZSortTool/LZSortToolDemo/LZSortToolDemo/LZSortClass/LZSortTool.m:14:9: fatal error: 'ChineseToPinyin.h' file not found

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error and 1 warning.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run: 
    `echo "2.3" > .swift-version`.
MacBook:LZSortTool Artron_LQQ$
这个是执行 pod spec lint指令的时候产生的错误:

这个错误从- NOTE可以看出, 是项目中的这个文件 ChineseToPinyin.h找不到, 回到项目, 编译一下也会报这个错. 是因为我修改了本地文件中的这个文件的路径, 项目中引用的还是原先的路径, 打开左侧文件列表, 可以发现这个文件是红色的, 删除引用, 重新添加, 然后到你的github上面, 重新添加一个release版本, 再重新执行指令即可验证通过.

作者:流火绯瞳
链接:http://www.jianshu.com/p/283584683b0b
來源:
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。```

以上

你可能感兴趣的:(上传SDK时pod spec lint遇到的错误)