xcode4.5下编译出包含armv6架构的静态库

升级到Xcode4.5之后,新增了iPhone5的armv7s支持,但是去除了armv6的支持,也就是说用XCode4.5无论如何配置项目都是无法编译出能在iPhone3G、iTouch2上面运行的程序或者库文件的,虽然说千寻影视已经不在打算支持这些古老的机型,而TCClick作为一个开源项目,还是需要提供支持的,下面就对TCClick项目中编译打包时所使用的方法进行介绍。

在TCClick项目代码根目录下,有一个名为lipo的脚本文件,该脚本文件就是用来执行编译打包的,执行这个脚本之后就可以在release目录下生成包含了armv6, armv7, armv7s以及i386四种CPU架构的库文件

york:tcclick-ios$ file release/libtcclick.a
release/libtcclick.a: Mach-O universal binary with 4 architectures
release/libtcclick.a (for architecture armv6):  current ar archive random library
release/libtcclick.a (for architecture armv7):  current ar archive random library
release/libtcclick.a (for architecture cputype (12) cpusubtype (11)):   current ar archive random library
release/libtcclick.a (for architecture i386):   current ar archive random library

lipo脚本文件的代码如下

#!/bin/sh

lipo=/usr/bin/lipo
xcodebuild=/usr/bin/xcodebuild
# 这个设置需要调整到你所放置的低版本XCode的地方
xcodebuild_armv6=/Applications/Xcode4.3.3/Xcode.app/Contents/Developer/usr/bin/xcodebuild

project_lib_iphoneos=./build/Release-iphoneos/libtcclick.a
project_lib_iphoneos_armv6=./build/Release-iphoneos-armv6/libtcclick.a
project_lib_iphonesimulator=./build/Release-iphonesimulator/libtcclick.a
target_lib=./release/libtcclick.a

# 删除之前的残留文件,进行重新编译构建
rm -rf ./build/*

# 编译armv6版本,然后把编译出来的内容移动到临时目录下面
$xcodebuild_armv6 -configuration=Release -arch armv6
mv ./build/Release-iphoneos ./build/Release-iphoneos-armv6

# 编译armv7、armv7s以及simulator的版本
$xcodebuild -configuration=Release
$xcodebuild -configuration=Release -sdk iphonesimulator

# 合并之前所编译出来的所有.a文件
$lipo -create "$project_lib_iphoneos_armv6" "$project_lib_iphoneos" "$project_lib_iphonesimulator" -output "$target_lib"
file "$target_lib"
cp ./build/*.h ./release

首先,因为XCode4.5已经去除了armv6的编译器,所以要编译armv6的版本是一定要在机器上安装更之前的XCode,我是在我的机器上的/Applications/Xcode4.3.3目录下安装了4.3.3的版本。除此之外,我还在TCClick项目的build目录变更到了项目所在目录,要不然我们就比较难找到编译好之后那些的.a文件,配置方法如图

Tcclick set build path

This entry was posted in iOS and tagged . Bookmark the permalink.

5 Responses to xcode4.5下编译出包含armv6架构的静态库

  1. hhb says:

    你好 请问你的这种做法支持编译出ipa 发布吗?

  2. 泡泡 says:

    mark下,在查这方面资料

Leave a Reply to hhb Cancel reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Verify Code   If you cannot see the CheckCode image,please refresh the page again!