How can I deploy (create .ipa) iphone app using 'cordova build ios --release'?

安稳与你 提交于 2019-11-28 15:12:38

I found this command which worked for me:

cordova build ios --device
cd platforms/ios/build/device
/usr/bin/xcrun -sdk iphoneos PackageApplication "$(pwd)/$PROJECT_NAME.app" -o "$(pwd)/$PROJECT_NAME.ipa"

Source: http://www.splinter.com.au/xcode-4-command-line-builds-of-iphone-apps/

I did run @MD. Mohiuddin Ahmed's Ruby script first, which would have changed my xcodeproj file. I'm not sure if that was necessary but I don't think so.

Update for XCode 8: As a commenter has noted, PackageApplication has been removed from XCode 8. To update the process, see the question: What's the replacement for Xcode's PackageApplication?

Edited to clarify process by adding cordova build command as suggested by comments.

If you are using cordova ios 3.9.0 or newer, you can use this command to create the .ipa directly from the CLI with no extra commands:

cordova build ios --device --release

You'll need a build.json file on the root of your project

{
  "ios": {
    "debug": {
      "codeSignIdentity": "iPhone Developer",
      "provisioningProfile": "your-dev-provisioning-profile-UUID-here"
    },
    "release": {
      "codeSignIdentity": "iPhone Distribution",
      "provisioningProfile": "your-distribution-provisioning-profile-UUID-here"
    }
  }
}

To get the UUID I open the .mobileprovision file on a text editor and search for 'UUID', not sure if there is an easier way of finding it.

If using Xcode 8 the build.json needs developmentTeam field and packageType field, but not longer need the provisioning profile, also, the codeSignIdentity should be iPhone Developer for both debug and release:

{
    "ios": {
        "debug": {
            "codeSignIdentity": "iPhone Developer",
            "developmentTeam": "FG35JLLMXX4A",
            "packageType": "development"
        },
        "release": {
            "codeSignIdentity": "iPhone Developer",
            "developmentTeam": "FG35JLLMXX4A",
            "packageType": "app-store"
        }
    }
}

http://cordova.apache.org/docs/en/6.x/guide/platforms/ios/index.html#using-buildjson

I finally figured out a way to automate this by using xcodeproj, xcode and this ruby script :

require 'xcodeproj'
xcproj = Xcodeproj::Project.open("HelloWorld.xcodeproj")
xcproj.recreate_user_schemes
xcproj.save

And then in the PROJECT_ROOT/platforms/ios/ directory this command helped me to generate my *.ipa:

xcodebuild -project HelloWorld.xcodeproj -exportArchive -exportFormat ipa -archivePath $(pwd)/HelloWorld.xcarchive -exportPath $(pwd)/HelloWorld.ipa CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -alltargets -configuration Release

Thought we can sign our .ipa later on :)

You can try a new tool from http://fir.im.

They have a fir cli tool written in ruby. You can install it with the following command:

sudo gem install fir-cli --no-ri --no-rdoc

Sign up an account (all free like the good old testflight) and get a token from your profile. From your command prompt run:

fir login

Provide your token.

CD into your directory where your .xcodeproj located.

fir build_ipa . 

After a while (if the build success) you will find your ipa in your ./build_ipa folder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!