使用Concorde库在真机上因bitcode编译出错的解决方法

来源:互联网 发布:西科软件培训中心 编辑:程序博客网 时间:2024/06/06 01:15

    xcode7.3 新开iOS项目,使用Cocoapods管理第三方库。

    根据文章《27 款 iOS 开源库,让你的开发溜到飞起》的推荐,引进了Concorde这个库。

    Concorde 是 一种渐进的加载方式,它可以让图片 以更好看的方式加载出来。

    模拟器编译运行成功,上真机时报错:

    libturbojpeg.a does not contain bitcode. You must rebuild it with bitcode enabled (Xcodesetting ENABLE_BITCODE), obtain an updated library from the vendor, or disablebitcode for this target. for architecture arm64.

    查找了文章,说项目默认设定了bitcode为YES,则引入的第三方的库也要设定bitcode为YES。如果第三方库不支持bitcode,则项目设置bitcode为NO就可以解决这个问题。

    参考文章:iOS中关于bitcode没有被包含的解决方法 ,内容贴在下面。

    这样做确实解决了问题,能编译通过了,但是仔细察看一下同时引入的其它库,都是设置bitcode为YES,因为这个就修改项目设置,非常可惜。

    再查找libturbojpeg 的官方资料,上面写明了支持bitcode的版本是1.5.1 :

    libjpeg-turbo 1.5.1 and later:
    iOS 6.0 and later / ARMv7 w/ bitcode (iPhone 3GS-4S, iPad 1st-3rd generation, iPad Mini)
    iOS 6.0 and later / ARMv7s w/ bitcode (iPhone 5 & 5C, iPad 4th generation)
    iOS 7.0 and later / ARMv8 w/ bitcode (iPhone 5S and later, iPad Mini 2 and later, iPad Air)

    去github的libjpeg-turbo主页去查找1.5.1版本,可惜没找到.a文件,又一番baidu之后找到这篇文章:使用OpenVC的一些报错及解决方法,内容贴在下面。

    http://sourceforge.net/projects/libjpeg-turbo/files/1.4.0/ 的页面写着Looking for the latest version? Download libjpeg-turbo-1.5.1.dmg (8.4 MB),很开心,就去下载ibjpeg-turbo-1.5.1.dmg文件。

    安装到系统后,把libturbojpeg.a 文件拷贝到项目文件里,bitcode设置为YES,成功编译并运行在真机里。

    以后更新cocoapods可能还需要复制一次,我觉得还是值得的,毕竟bitcode是苹果推的设置,有利于app的下载。


iOS中关于bitcode没有被包含的解决方法:

用Xcode 7 beta 3在真机(iOS 8.3)上运行一下工程,结果发现工程编译不过。看了下问题,报的是以下错误:

ld: ‘/Users/**/Framework/SDKs/PolymerPay/Library/mobStat/lib**SDK.a(**ForSDK.o)’does not contain bitcode. You must rebuild it with bitcode enabled (Xcodesetting ENABLE_BITCODE), obtain an updated library from the vendor, or disablebitcode for this target. for architecture arm64

得到的信息是引入的一个第三方库不包含bitcode。

Bitcode是个什么鬼?

查阅了一下官方文档,在App

Distribution Guide–App Thinning (iOS, watchOS)一节中,找到了下面这样一个定义:

Bitcode is an intermediate representationof a compiled program. Apps you upload to iTunes Connect that contain bitcodewill be compiled and linked on the App Store. Including bitcode will allowApple to re-optimize your app binary in the future without the need to submit anew version of your app to the store.

说的是bitcode是被编译程序的一种中间形式的代码。包含bitcode配置的程序将会在App store上被编译和链接。bitcode允许苹果在后期重新优化程序的二进制文件,而不需要重新提交一个新的版本到App store上。

而在What’s New in Xcode-New Features in Xcode 7中,还有一段如下的描述:

Bitcode. When you archive for submission tothe App Store, Xcode will compile your app into an intermediate representation.The App Store will then compile the bitcode down into the 64 or 32 bitexecutables as necessary.

当提交程序到App store上时,Xcode会将程序编译为一个中间表现形式(bitcode)。然后App store会再将这个botcode编译为可执行的64位或32位程序。

再看看这两段描述,都是放在App Thinning(App瘦身)一节中,可以看出其与包的优化有关了。

Bitcode配置

在上面的错误提示中,提到了如何处理我们遇到的问题:

You must rebuild it with bitcode enabled(Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, ordisable bitcode for this target. for architecture arm64

要么让第三方库支持,要么关闭target的bitcode选项。

实际上,在Xcode 7中,我们新建一个iOS程序时,bitcode选项默认是设置为YES的。我们可以在”Build Settings”->”Enable Bitcode”选项中看到这个设置。不过,我们现在需要考虑的是三个平台:iOS,Mac OS,watchOS。

对于iOS,bitcode是可选的;对于watchOS,bitcode是必须的;而Mac OS是不支持bitcode。

如果我们开启了bitcode,在提交包时,下面这个界面也会有个bitcode选项:

所以,如果我们的工程需要支持bitcode,则必要要求所有引入的第三方库都支持bitcode。

通过本文对bitcode的概念及配置情况的简要介绍,希望iOS开发人员在工程运行中遇到类似的情况,可以根据上文的介绍更有效的找到原因并及时处理。




使用OpenVC的一些报错及解决方法

1.报错:

Unsupported compiler 'com.apple.compilers.llvmgcc42' selected for architecture 'armv7'

解决:http://stackoverflow.com/questions/17162975/unsupported-compiler-com-apple-compilers-llvmgcc42-xcode-5-dp


屏幕快照 2016-10-27 下午2.24.26.png

2.报错:

"_jpeg_free_small", referenced from:

解决:http://blog.csdn.net/ioslearner_nana/article/details/45174365

a.到http://sourceforge.net/projects/libjpeg-turbo/files/1.4.0/ 下载ibjpeg-turbo-1.4.0.dmg(3.8 MB)文件。
b.安装,一旦完成可以在该路径下找到已经安装的文件 /opt/libjpeg-turbo/lib
c.打开终端输入命令 lipo -info /opt/libjpeg-turbo/lib/libjpeg.a
d.如果终端显示以下命令运行后输出,就意味着,你的项目(armv7/armv7s) * Architectures in the fat file: /opt/libjpeg-turbo/lib/libturbojpeg.a are: i386 x86_64 armv6 armv7 armv7s arm64
e.使用finder来导航到: /opt/libjpeg-turbo/lib,将 libjpeg.a文件添加到你的工程。
f. XCode-> Targets -> General -> Linked frameworks and libraries -> Click on the add button placed at the bottom -> include the libjpeg.a file
g.编译项目,问题解决(可能还有问题包这个错误:


屏幕快照 2016-10-27 下午2.49.10.png

解决方法:在Build Settings搜索 enable_bitcode改为No

0 0
原创粉丝点击