使用xcodebuild命令进行自动化打包

1 修改xcodeproj/project.pbxproj 文件

这个文件修改的是项目的证书配置和描述文件配置

关键修改如下

对于打Release模式包的,找到这一段

        638234841AE62041001700C9 /* Release */ = {
            isa = XCBuildConfiguration;
            baseConfigurationReference = 6A6EBCC368D67FB5C2365F82 /* Pods-Toon.release.xcconfig */;
            buildSettings = {
                ....
                PRODUCT_BUNDLE_IDENTIFIER = com.test.enterprise.xxx
                PROVISIONING_PROFILE = "d73920ec-9178-4f26-a0b8-c89ca2bbea6d";
                PROVISIONING_PROFILE_SPECIFIER = com.test.enterprise.xxx
                DEVELOPMENT_TEAM = TLWP697Z5D;
                ....
            };
            name = Release;
        };

将这四个值配置成对应的证书和描述文件即可

2 构建archive包

  • 使用cocoapods管理第三方的工程使用这条命令打包

    xcodebuild archive -workspace 项目名称.xcworkspace -scheme 项目名称 -configuration Release -archivePath archive包存储路径 CODE_SIGN_IDENTITY="证书" PROVISIONING_PROFILE="描述文件UUID"
    
  • 未使用Pod管理第三方的工程使用这个

    xcodebuild archive -project 项目名称.xcodeproj -scheme 项目名称 -configuration Release -archivePath archive包存储路径 CODE_SIGN_IDENTITY=证书 PROVISIONING_PROFILE=描述文件UUID
    

证书去钥匙串中查找,需要注意的是这里需要把证书的完整名字拷贝过来。

描述文件的UUID在下面会有介绍如何获取

示例

 ᐅ xcodebuild archive -workspace Test.xcworkspace -scheme Test -configuration Release -archivePath ~/Desktop/Test.xcarchive CODE_SIGN_IDENTITY="iPhone Distribution: Beijing Test Internet Technology Co. Ltd." PROVISIONING_PROFILE="d78212ec-9128-4f26-a428-c89ca5232bea6d"

3 导出ipa包

xcodebuild  -exportArchive 
            -archivePath archive文件的地址.xcarchive 
            -exportPath 导出的文件夹地址 
            -exportOptionsPlist exprotOptionsPlist.plist 
            CODE_SIGN_IDENTITY=证书 
            PROVISIONING_PROFILE=描述文件UUID
各参数说明
  • -archivePath 指定从哪里读取archive包
  • -exportPath 指定ipa包导出后的放置位置
  • -exportOptionsPlist 该参数的值是一个plist文件的地址,打包时候的一些配置,该文件中的值如下
    • teamID - 值为证书的teamID
    • method - 指定打包方式,是内侧包、企业包、App Store包。值为下面几个: enterprise、ad-hoc、..
    • ...
  • CODE_SIGN_IDENTITY - 打包证书
  • PROVISIONING_PROFILE - 使用的描述文件

exportOptionsPlist在用xcode手动打包的时候会自动生成的,和ipa文件在同一个目录,可以拷贝来用。也可以手动创建。文件中需要配置的值在上面已经说明。

示例

ᐅ xcodebuild -exportArchive -archivePath ~/Desktop/Test.xcarchive -exportPath ~/Desktop/ -exportOptionsPlist ~/WorkSpace/archive/ExportOptions.plist CODE_SIGN_IDENTITY="iPhone Distribution: Beijing Test Internet Technology Co. Ltd." PROVISIONING_PROFILE="d78212ec-9128-4f26-a428-c89ca5232bea6d"

通过xcodebuild命令查看项目设置

通过命令查看描述文件的详细信息 包括UUID等信息

/usr/bin/security cms -D -i 文件路径

输出如下





    AppIDName
    comtestenterprisexx
    ApplicationIdentifierPrefix
    
    TLWP697Z5D
    
    CreationDate
    2018-06-06T03:36:47Z
    Platform
    
        iOS
    
    IsXcodeManaged
    
    DeveloperCertificates
    
        MIIFvjCCBKagAwIBAgIIS3zyrKjgso8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNVBAYTAlVTMRMwEQYDVQQKDApBcHBsZSBJbmMuMSwwKgYDVQQLDCNBcHBsZSBXb3JsZHdpZGUgRGV2ZWxvcGVyIFJlbGF0aW9uczFEMEIGA1UEAww7QXBwbGUgV29ybGR3aWRlIERldmVsb3BlciBSZWxhdGlvbnMgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTYxMjI0MDkyNjA3WhcNMTkxMjI0MDkyNjA3WjCBvzEaMBgGCgmSJomT8ixkAQEMClRMV1A2OTdaNUQxSTBHBgNVBAMMQGlQaG9uZSBEaXN0cmlidXRpb246IEJlaWppbmcgU3lzd2luIEludGVybmV0IFRlY2hub2xvZ3kgQ28uIEx0ZC4xEzARBgNVBAsMClRMV1A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A1UdDwEB/wQEAwIHgDAWBgNVHSUBAf8EDDAKBggrBgEFBQcDAzATBgoqhkiG92NkBgEEAQH/BAIFADANBgkqhkiG9w0BAQUFAAOCAQEAmeGtWRppAcYdOe7l6hEdzlQE1YT2BztljaLW38hkrhVU+omaaF8LEb3F58fZxSCOteEsaiyTkq9lgt/3wKbmzPVFW379az1+sxnk5sb+PHCrg7BvfVIlB9/1CljxYuGwwOWKkLL6MP/sAFInrBJkDYWt3NHvpe1aH0bT/3rVW2bkV4LWfcJlVPtGzAGNYOr4itL4wma3h9ryvVQb1Eiy+RWbn//QmJGavkuICh3cJ25/ywUR6sLMsIQLMyt+GcZdUMioXJn5RqDxSDlB3wArJkav2CDP7QN83m/bbplKdph+e/r0jRoHCTXPs2A4xnIkUIQJNkGGvdDvc0AFcV+kNQ==
    
    Entitlements
    
        keychain-access-groups
        
            TLWP697Z5D.*
        
        get-task-allow
        
        application-identifier
        TLWP697Z5D.com.systoon.enterprise.milintoon
        com.apple.developer.associated-domains
        *
        com.apple.security.application-groups
        
        
        com.apple.developer.team-identifier
        TLWP543Z5D
        com.apple.external-accessory.wireless-configuration
        
        aps-environment
        production
    
    ExpirationDate
    2019-06-06T03:36:47Z
    Name
    com.markday.enterprise.test
    ProvisionsAllDevices
    
    TeamIdentifier
    
        TLWP697Z5D
    
    TeamName
    Beijing MarkDay Internet Technology Co. Ltd.
    TimeToLive
    365
    UUID
    d73234ec-9178-4f26-a0b8-c89ca2bbea6d
    Version
    1

%

这里面就有UUID、TeamName等信息

描述文件存放的位置

/Users/用户名称/Library/MobileDevice/Provisioning Profiles

查看工程的信息

xcodebuild -list

输出如下

Information about project "Toon":
    Targets:
        Toon
        ToonTests
        TNAOrgTest
        TNGroupChatTests
        TNShareExtension

    Build Configurations:
        Debug
        Debug_Automation_Test
        Release

    If no build configuration is specified and -scheme is not passed then "Release" is used.

    Schemes:
        jiaoyutong
        menchengtong
        milin
        TNAOrgTest
        TNShareExtension
        Toon
        ToonTests

你可能感兴趣的:(使用xcodebuild命令进行自动化打包)