cocopods管理framework

xiaoxiao2021-02-28  108

前言

在上篇文章中介绍了Cocoapods管理本地代码,今天我们来说下,管理.a,.framework。

管理.a库

1、首先我们建立一个static library的工程TestLib。

1@2x.png

2、新建TestLib.h/.m,添加test方法。

2@2x.png

3、生成通用的.a库。

3@2x.png

在build phase中添加runscript。脚本如下:

# define output folder environment variable UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal # Step 1. Build Device and Simulator versions xcodebuild -target TestLib ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" xcodebuild -target TestLib ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" # make sure the output directory exists mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" # Step 2. Create universal binary file using lipo lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a" # Last touch. copy the header files. Just for convenience cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"

cmd+B,完事。在products/Debug-universal文件夹中找到生成的通用库。

5@2x.png

用lipo查看.a库所支持的架构。

lipo -info libTestLib.a Architectures in the fat file: libTestLib.a are: armv7 i386 x86_64 arm64

4、Cocoapods来管理.a。 跟管理代码一样,只需要在podspec里面,设置好要暴露的文件即可。.a也可看做是文件。这里我们把通用.a库,拷到TestLib.h同级目录下。主要就是把.a库,和.h放在某个目录中。目录结构看起来是这样:

6@2x.png

5、生成podspec

Pod::Spec.new do |s| s.name = "TestLib" s.version = "0.0.6" s.summary = "TestLib." s.homepage = "https://github.com/silan-liu" s.license = { :type => "MIT", :file => "FILE_LICENSE" } s.author = { "silan-liu" => "413769707@qq.com" } s.platform = :ios s.ios.deployment_target = "8.0" // 这里是TestLib工程目录 s.source = { :git => "~/快盘/mycode/TestLib", :tag => s.version } s.source_files = "**/*.{h}" // 向外提供的库 s.vendored_libraries = "TestLib/libTestLib.a" s.requires_arc = true end

6、新建工程来测试pod 具体步骤跟上一篇类似,在podfile中填写podspec的路径,pod install。成功后,如下图。

7@2x.png

管理.framework

跟管理.a类似,同样是生成通用framework。只不过podspec有点不同。.a是s.vendored_libraries,.framework是s.vendored_frameworks。

s.vendored_frameworks = 'Test/TestFramework.framework'
转载请注明原文地址: https://www.6miu.com/read-43228.html

最新回复(0)