• 主页
  • 系列总集
  • OpenCV
  • CMake
  • iOS
  • Java
  • 前端
所有文章 关于我

  • 主页
  • 系列总集
  • OpenCV
  • CMake
  • iOS
  • Java
  • 前端

模块化与Shell(24):常用的工具

2017-07-24

Xcode相关命令行

lipo

最常见的命令行,用于合并和拆封 Framework,在Framework脚本伪装Bundle 文章中用来摘除多余架构

1
2
3
4
//抽出架构
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
//合并多个架构Framework 为一个
lipo -o "$FRAMEWORK_EXECUTABLE" -create "$FRAMEWORK_EXECUTABLE-ARM64" "$FRAMEWORK_EXECUTABLE-X86"

nm

最常用的查看符号表的指令,在文章 Xcode和符号表 中用于查看不同Mach-O的的符号表差异

1
nm "$MACH-O-FILE"

其中除了压缩包和符号表的不同,指的注意的是该符号是否具有地址和类型

1
2
3
4
5
6
0000000000000000 t -[StaticLibObj init]
00000000000000a0 t -[StaticLibObj selectorInStaticLibraryObjFix]
U _NSLog
U _OBJC_CLASS_$_NSObject
00000000000000d8 S _OBJC_CLASS_$_StaticLibObj

类型 是否具有地址 备注
t 有
U 无 代表未定义的符号
S 有
s 有

otool

用于查看 Mach-O文件的构造,在Framework脚本伪装Bundle 文章中用来判断是否是Static Mach-O,其指令

1
otool -a "$FRAMEWORK_EXECUTABLE_PATH" | head -n 1

可以利用其输出的不同,来进行准确的判断

Mach-O 输出
Static Archive : ….Base.framework/Base
Dynamic 无输出

-a 参数的描述

1
-a     Display the archive header, if the file is an archive.

defaults

用于读写Plist,其实Bundle和Framework的plist文件差别不大,在Framework脚本伪装Bundle 文章中用来修改有区别的字段

1
2
3
4
5
6
//读取所有字段
defaults read "$FRAMEWORK/Info.plist"
//修改 CFBundlePackageType 为 "BNDL"
defaults write "$FRAMEWORK/Info.plist" CFBundlePackageType "BNDL"
//删除 CFBundleExecutable 字段
defaults delete "$FRAMEWORK/Info.plist" CFBundleExecutable

assetutil

用于查看资源文件 Assets.car 包含的文件,在 UniqueFramework的制作 可以配合 nm 命令检查 资源 和 符号表 的最终结果

1
2
//以Json的格式打印出所有资源
assetutil -I "..../../Assets.car"

actool

在Xcode Build的过程中,用来把 .xcasseets 文件夹压缩成 Asset.car 文件的工具, 在UniqueFramework的制作过程中,也可以尝试自己脚本来处理资源

以下是把 Media1 和 Media2 一起压缩成 某个Framework里的 Assets.car的命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/Applications/Xcode.app/Contents/Developer/usr/bin/actool
--output-format human-readable-text
--notices --warnings
--export-dependency-info "....assetcatalog_dependencies"
--output-partial-info-plist "..../assetcatalog_generated_info.plist"
--compress-pngs
--enable-on-demand-resources NO
--filter-for-device-model iPhone7,2
--filter-for-device-os-version 11.0
--sticker-pack-identifier-prefix "com.XXX.sticker-pack"
--target-device iphone --target-device ipad
--minimum-deployment-target 9.0 --platform iphoneos
--product-type com.apple.product-type.framework
--compile "/Debug-iphoneos/Some.framework" ".../Resource/Media1.xcassets" ".../Resource/Media2.xcassets"

Linux通用命令行

head

用来取出命令行输出的头部,在Framework脚本伪装Bundle 文中配合 otool来验证判断,不然输出太多

1
head -n 1

od

按二进制取出读取文件的, 原本想用二进制文件的头部判断 Static Framework

因为误以为 Static Framework的头部是一样,后来发现会受到架构的影响

1
2
3
4
5
od -H -A n -N 8 static.framework/static

#-H, -X Output hexadecimal ints. Equivalent
#-A base Specify the input address base. base may be one of d, o, x or n, which specify decimal, octal, hexadecimal addresses
#-N length Dump at most length bytes of input

其中 H代表输出十六进制, A n 代表以十六进制显示地址, N代表要读取的长度

赏

请问老板还招人么(/ω\)

支付宝
微信
  • iOS
  • Shell
  • IDE
  • Xcode
  • Compiler
  • Tutorial

扫一扫,分享到微信

微信分享二维码
模块化与CocoaPods(25):StaticLib和Framework两种方式引入Pods
模块化与Framework(23):StaticLib混合引用测试
© 2021 Alan Li
Hexo Theme Yilia by Litten
  • 所有文章
  • 关于我

tag:

  • iOS
  • Java
  • Collection
  • Python
  • Shell
  • CMake
  • Memory
  • JavaScript
  • Architecture
  • AnchorPoint
  • Android
  • Web
  • Annotation
  • AFNetworking
  • Window
  • ViewController
  • AutoLayout
  • Dozer
  • CoreAnimation
  • Cycle Retain
  • Block
  • UI
  • IDE
  • FrontEnd
  • CSS
  • Category
  • TableViewCell
  • Security
  • Net
  • JSP
  • Spring
  • C
  • MyBatis
  • Date
  • React
  • GCD
  • UITouch
  • Gesture
  • UIControl
  • Git
  • HTML
  • HTTPS
  • HTTP
  • Servlet
  • Server
  • DataBase
  • MySQL
  • Linux
  • Tutorial
  • Ajax
  • Type
  • JQuery
  • JSON
  • Exception
  • Parameter
  • Reflect
  • Thread
  • Sort
  • KVO
  • MKMapKit
  • Overlay
  • Maven
  • Configure
  • Tips
  • Transaction
  • Swift
  • NavigationBar
  • Nginx
  • Runtime
  • OpenCV
  • Property
  • Playground
  • Protocol
  • Redux
  • ScrollView
  • Session
  • Cookie
  • Shiro
  • Error
  • Singleton
  • RegEx
  • StackView
  • StatusBar
  • Base64
  • Socket
  • TCP
  • IP
  • TextField
  • CALayer
  • UILabel
  • View
  • Animation
  • Xcode
  • Hexo
  • Terminal
  • OC
  • Device
  • Log
  • Image
  • JUnit
  • Oval
  • Archive
  • XSS
  • Compiler
  • Aspect
  • Responder
  • Class
  • FireWall
  • RetainCount
  • Const
  • Frame
  • String
  • Symbols
  • Framework
  • CocoaPods
  • Unity
  • Message
  • Button
  • AuthorizationStatus
  • Struct
  • XCTest
  • NSNotification
  • Contact

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

我写的,大概率是错的。。。。。