1.pod庫創(chuàng)建
方式一 : pod spec create (pod庫名稱)
方式二: pod lib create (pod庫名稱) 帶有示例工程
本地驗(yàn)證 pod lib lint 文件名.podspec
pod lib lint JCMaNongChenZaiTest.podspec --allow-warnings
聯(lián)網(wǎng)驗(yàn)證 pod spec lint JCMaNongChenZaiTest.podspec
2.podspec文件基本操作
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
# Run `pod lib lint jdfpassportlogin.podspec' to validate before publishing.
#
Pod::Spec.new do |s|
# 庫名
s.name = 'jdfpassportlogin'
# 庫版本號(hào), 和下載使用版本對(duì)應(yīng)
s.version = '0.0.1'
# 簡(jiǎn)短介紹
s.summary = 'A new Flutter plugin.'
# 詳細(xì)介紹
s.description = <<-DESC
A new Flutter plugin.
DESC
# 主頁,這里要填寫可以訪問到的地址摄咆,不然驗(yàn)證不通過
s.homepage = 'http://example.com'
# 截圖
# s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
# 開源協(xié)議
s.license = { :file => '../LICENSE' }
# 作者信息
# s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Your Company' => 'email@example.com' }
# 項(xiàng)目地址,不支持ssh的地址,驗(yàn)證不通過膊升,只支持HTTP和HTTPS俺榆,最好使用HTTPS
s.source = { :path => '.' }
# { :git => 'https://github/jdfpassportlogin.git', :tag => s.version.to_s }
# 支持的平臺(tái)及版本
s.platform = :ios, '9.0'
# 添加模塊名
# spec.module_name = 'Three20'
# 是否使用ARC空繁,如果指定具體文件惭聂,則具體的文件使用ARC
# s.requires_arc = true
# 代碼源文件地址蒲肋,**/*表示Classes目錄及其子目錄下所有文件乒省,如果有多個(gè)目錄下則用逗號(hào)分開巧颈,如果需要在項(xiàng)目中分組顯示,這里也要做相應(yīng)的設(shè)置
# Classes/**/*.{h,m} 以 .h 和 .m 結(jié)尾的文件
# Classes/**/*.h 以.h 結(jié)尾的文件
# Classes/**/*.{h,m,storyboard}
s.source_files = 'Classes/**/*.{h,m}'
# 圖案: *
# *將匹配所有文件
# c*將匹配所有以開頭的文件c
# *c將匹配所有以c
# *c*將匹配其中的所有文件c(包括開頭或結(jié)尾)
# 圖案: **
# 遞歸匹配目錄袖扛。
# 多個(gè)文件示例
# s.source_files = #{root}/JZActionJumpModule-umbrella.h", "#{root}/Classes/**/*.{h,m}"
# 導(dǎo)入頭文件, 不建議
# spec.prefix_header_contents = '#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>'
# 頭文件引用, 不建議
# spec.prefix_header_file = 'iphone/include/prefix.pch'
# 公開頭文件地, 也可以指定具體文件
s.public_header_files = 'Classes/**/*.h', #'Classes/example/example.h'
# 項(xiàng)目頭文件
# spec.project_header_files = 'Headers/Project/*.h'
# 私有文件, 即不公開
# spec.private_header_files = 'Headers/Private/*.h'
# 排除文件
# spec.exclude_files = 'Classes/**/unused.{h,m}'
# buildsetting相關(guān)設(shè)置, 這里bitcode設(shè)置為NO, C++ Standard Library設(shè)置為libstdc++
# s.xcconfig = {
# 'ENABLE_BITCODE' => 'NO',
# 'CLANG_CXX_LIBRARY' => 'libstdc++'
# }
# 該pod依賴的系統(tǒng)framework砸泛,多個(gè)用逗號(hào)隔開
# s.frameworks = 'UIKit','CoreGraphics'
# 弱引用的庫
# spec.weak_frameworks = 'Twitter', 'SafariServices'
# 該pod依賴的系統(tǒng)library,多個(gè)用逗號(hào)隔開
# s.libraries = 'iconv','sqlite3','stdc++','z'
# 第三方.a文件
# s.vendored_libraries = 'login_sdk/*.a'
# 第三方frameworks文件
# s.vendored_frameworks = 'XXEncryptKit/Classes/ThirdParty/*.framework'
# 依賴關(guān)系蛆封,該項(xiàng)目所依賴的其他庫唇礁,如果有多個(gè)需要填寫多個(gè)s.dependency
# 依賴項(xiàng)可以指定版本要求。建議使用樂觀版本指示器~>惨篱,因?yàn)樗峁┝藢?duì)版本的良好控制盏筐,而不會(huì)太嚴(yán)格。
# 例如砸讳, ~> 1.0.1相當(dāng)于與>= 1.0.1結(jié)合< 1.1琢融。同樣, ~> 1.0將匹配1.0, 1.0.1, 1.1绣夺,但不會(huì)升級(jí)到2.0.
# spec.dependency 'AFNetworking', '~> 1.0', :configurations => ['Debug']
# spec.dependency 'AFNetworking', '~> 1.0', :configurations => :debug
# spec.dependency 'AFNetworking', '~> 1.0'
s.dependency 'Flutter'
s.dependency 'JDLLogin'
s.dependency 'YYKit'
# 此處待驗(yàn)證, 配置可能添加到示例工程
# spec.info_plist = {
# 'CFBundleIdentifier' => 'com.myorg.MyLib',
# 'MY_VAR' => 'SOME_VALUE'
# }
# 應(yīng)該傳遞給編譯器的標(biāo)志列表吏奸。
# spec.compiler_flags = '-DOS_OBJECT_USE_OBJC=0', '-Wno-format'
# 添加到最終私有pod 目標(biāo) xcconfig 文件的任何標(biāo)志。
# spec.pod_target_xcconfig = { 'OTHER_LDFLAGS' => '-lObjC' }
# 是否允許使用靜態(tài)庫
s.static_framework = true
# 使用subspec來實(shí)現(xiàn)目錄分層陶耍。
s.subspec 'IdassSKD' do |ss|
ss.source_files = 'login_sdk/**/*.{h,m}'
ss.vendored_library = 'login_sdk/libJDMobileLoginSDK.a'
# 資源文件地址
ss.resources = 'login_sdk/JDMobileLoginSDK.bundle'
end
s.subspec 'LegoasSDK' do |ss|
ss.vendored_frameworks = "legolas_sdk/*.framework"
ss.resources = 'legolas_sdk/JDJR_Legolas.bundle'
ss.frameworks = 'Security','WebKit'
end
# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
end
3.加載xcassets圖片
- 這種方式把resources資源合并主項(xiàng)目的xcassets中
- 加載圖片依然使用[UIImage imageNamed:@"test"]
- podfie 需要添加install! 'cocoapods',
:disable_input_output_paths => true- 使用它use_frameworks
示例
s.resources = "Assets/*.xcassets"
3.framework腳本
# Sets the target folders and the final framework product.
FRAMEWORK_NAME=LibraryName
FRAMEWORK_VERSION=1.0
FRAMEWORK_CONFIG=Release
# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
INSTALL_PATH=${PROJECT_DIR}/Products/
INSTALL_DIR=${INSTALL_PATH}/${FRAMEWORK_NAME}.framework
# Working dir will be deleted after the framework creation.
WORK_DIR=build
DEVICE_DIR=${WORK_DIR}/${FRAMEWORK_CONFIG}-iphoneos/${FRAMEWORK_NAME}.framework
SIMULATOR_DIR=${WORK_DIR}/${FRAMEWORK_CONFIG}-iphonesimulator/${FRAMEWORK_NAME}.framework
xcodebuild -configuration "${FRAMEWORK_CONFIG}" -target "${FRAMEWORK_NAME}" -sdk iphoneos
echo "Build simulator"
xcodebuild -configuration "${FRAMEWORK_CONFIG}" -target "${FRAMEWORK_NAME}" -sdk iphonesimulator
# Creates install directory if it not exits.
if [ ! -d "${INSTALL_DIR}" ]
then
mkdir -p "${INSTALL_DIR}"
fi
# Creates headers directory if it not exits.
if [ ! -d "${INSTALL_DIR}/Headers" ]
then
mkdir -p "${INSTALL_DIR}/Headers"
fi
# Remove all files in the headers diectory.
for file in `ls "${INSTALL_DIR}/Headers"`
do
rm "${INSTALL_DIR}/Headers/${file}"
done
# Remove binary library file.
rm -f ${INSTALL_DIR}/${FRAMEWORK_NAME}
# Copies the headers files to the final product folder.
if [ -d "${DEVICE_DIR}/Headers" ]
then
for file in `ls "${DEVICE_DIR}/Headers"`
do
cp "${DEVICE_DIR}/Headers/${file}" "${INSTALL_DIR}/Headers/${file}"
done
fi
# copy nibs to bundle,then copy bundle to final folder
BUNDLE_DIR=${DEVICE_DIR}/${FRAMEWORK_NAME}.bundle
if [ -d "${BUNDLE_DIR}" ];then
if ls ${DEVICE_DIR}/*.nib >/dev/null 2>&1;then
rm -rf ${BUNDLE_DIR}/*.nib
cp -rf ${DEVICE_DIR}/*.nib ${BUNDLE_DIR}
fi
rm -rf "${INSTALL_DIR}/${FRAMEWORK_NAME}.bundle"
cp -R "${BUNDLE_DIR}" "${INSTALL_DIR}/${FRAMEWORK_NAME}.bundle"
fi
echo "Merge with simulator"
# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FRAMEWORK_NAME}" "${SIMULATOR_DIR}/${FRAMEWORK_NAME}" -output "${INSTALL_DIR}/${FRAMEWORK_NAME}"
open "${INSTALL_PATH}"
# rm -r "${WORK_DIR}"
4. static_framework應(yīng)用
s.static_framework = true
1.用cocoapods
導(dǎo)入swift
框架到swift
項(xiàng)目和OC
項(xiàng)目都必須要在 Podfile
文件 use_frameworks!
2.使用use_frameworks!
, cocoapods
, 會(huì)生成相應(yīng)的, .frameworks
,文件(動(dòng)態(tài)鏈接庫:實(shí)際內(nèi)容為 Header + 動(dòng)態(tài)鏈接庫 + 資源文件)
此時(shí)如果podspec
中又必須引入.a
文件, 可以使用此命令解決
否則pod install
報(bào)錯(cuò)
[!] The 'Pods-***_Example' target has transitive dependencies that include statically linked binaries:
(/***/***/Example/Pods/DouyinOpenSDK/DouyinOpenSDK/libDouyinOpenSDK.a)
靜態(tài)庫:(靜態(tài)鏈接庫)(.a)在編譯時(shí)會(huì)將庫copy一份到目標(biāo)程序中奋蔚,編譯完成之后,目標(biāo)程序不依賴外部的庫,也可以運(yùn)行
缺點(diǎn): 會(huì)使應(yīng)用程序變大
動(dòng)態(tài)庫:(.dylib)編譯時(shí)只存儲(chǔ)了指向動(dòng)態(tài)庫的引用泊碑±ぐ矗可以多個(gè)程序指向這個(gè)庫,在運(yùn)行時(shí)才加載馒过,不會(huì)使應(yīng)用體積變大臭脓,但是運(yùn)行時(shí)加載會(huì)損耗部分性能,并且依賴外部的環(huán)境腹忽,如果庫不存在或者版本不正確則無法運(yùn)行
Framework:實(shí)際上是一種打包方式来累,將庫的二進(jìn)制文件,頭文件和有關(guān)的資源文件打包到一起窘奏,方便管理和分發(fā)嘹锁。