Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble packaging and signing iOS apps built with Cordova CLI

Until now, all of my experience compiling PhoneGap apps has been via the excellent PhoneGap:Build service. However, I now find myself in a situation where I need to compile locally, because I need to use a plugin that includes a binary file, which precludes it from being included for use with PG:B.

So for these reasons, I need to compile locally. "Great!" I thought, I'll just use the new CLI...

I have developed my app, and I can test it on-device via deploy over USB from Xcode, but trying to get a release build, and sign it, with the provisioning profile embedded, has been a nightmare.

For completeness, this is the basic outline of everything I've done, aside from the app development itself.

$ pwd
 /users/adam/dev/myapp/mobile/
$ cordova create build_local com.foo.bar MyApp
 Creating a new cordova project with name "MyApp" and id "com.foo.bar" at location "/Users/adam/DEV/myapp/build_local"
$ cd build_local
$ cordova platform add ios
 Creating ios project...
$ cordova platform add android
 Creating android project...
 Creating Cordova project for the Android platform:
    Path: platforms/android
    Package: com.foo.bar
    Name: MyApp
    Android target: android-19
 Copying template files...
 <snip>
 Project successfully created.
$ cordova plugin add https://github.com/hazemhagrass/BackgroundJS
 Fetching plugin "https://github.com/hazemhagrass/BackgroundJS" via git clone
 Installing com.badrit.BackgroundJS (android)
 Fetching plugin "https://github.com/apache/cordova-plugin-device.git" via git clone
 Installing org.apache.cordova.device (android)
 Installing com.badrit.BackgroundJS (ios)
 Installing org.apache.cordova.device (ios)
$ cordova plugin add de.appplant.cordova.plugin.local-notification
 Fetching plugin "de.appplant.cordova.plugin.local-notification" via plugin registry
 Installing de.appplant.cordova.plugin.local-notification (android)
 Installing de.appplant.cordova.plugin.local-notification (ios)
$ cordova plugin add https://github.com/kdzwinel/phonegap-estimotebeacons
 Fetching plugin "https://github.com/kdzwinel/phonegap-estimotebeacons" via git clone
 Installing pl.makingwaves.estimotebeacons (android)
 Installing pl.makingwaves.estimotebeacons (ios)

For what it's worth, this last plugin is the reason that I have to compile locally.

Now, here's one other potential monkey wrench: This app is actually two apps. It's the same core codebase, merged into two different deployment branches of the repo, one for each client. So each app will have its own id, name, and config stuff. Because of this, I actually have more than one cordova project folder (1 for each final app) and after creating each project through the steps above, I remove the generated www folder and replace it with a symlink to the shared www folder that exists outside of these phonegap project directories.

This is supported behavior; the CLI allows you to generate your app with a symlink via the --link-to flag (see cordova help create for details). However, doing so seems to have issues; so I've resorted to doing all of the app config up front and then replacing the generated www folder with a symlink after everything is ready to compile.

At this point, I can deploy to either the iOS simulator or Android emulator, and I can deploy to devices over USB, and everything works just fine; all of my plugins are available and function as expected. So I'm ready to compile a release build. Android is easy. iOS, not so much.

$ cordova build ios
 <snip>
 ** BUILD SUCCEEDED **

However, this is a DEV build. The generated file is in the build/emulator/ folder, and when I attempt to sign it, I'm told that it's not signed because of the I386 architecture (which indicates that it's a development build).

$ xcrun -sdk iphoneos PackageApplication -v "platforms/ios/build/emulator/MyApp.app" -o "/users/adam/dev/myapp/MyApp.ipa" --sign "iPhone Distribution: {our cert name} ({our cert id})"
 <snip>
 Codesign check fails : platforms/ios/build/emulator/MyApp.app: code object is not signed at all
 In architecture: i386
 <snip>

I've attempted to generate a release build from the cordova CLI. I haven't been able to find the --release flag documented anywhere, but the CLI doesn't complain, and it usually does if it doesn't recognize a flag.

$ cordova build ios --release
 <same result as previously>

Attempting to sign this build results in the same problem.


At this point, I started attempting to work directly in Xcode. I've set the .mobileprovision file and the signing credentials up appropriately, to the best of my knowledge:

screenshot of signing and provisioning profile settings

With these values set, Xcode no longer allows me to build:

screenshot of build menu disabled

So I'm stuck: I have no choice but to build locally, and I can't figure out how to get it to build for release and sign! Please help!


Additionally, if I attempt to embed a provisioning profile, that fails because of an issue with entitlements. I'm not exactly sure what this means, but I'm hopeful that it's a result of working with a dev build, and resolving that will resolve this as well.

$ test -e ~/.ios/DEV.mobileprovision && echo exists
 exists
$ xcrun -sdk iphoneos PackageApplication -v "platforms/ios/build/emulator/MyApp.app" -o "/users/adam/dev/myapp/MyApp.ipa" --embed "~/.ios/DEV.mobileprovision"
 <snip>
 error: Failed to read entitlements from '/var/folders/zs/j2hmt69n12sbjm6gyn0m_q4c0000gn/T/tyYvYPQKf3/Payload/MyApp.app'

Update 1:

This SO question helped in one regard. I don't know how the active scheme (I'm not really sure what that means, but that's the tooltip when I hover over the control) got changed as part of specifying keys/etc, but clearly it did. Changing this back to an iOS Device, like iPhone, allows me to build my project, and even Archive (which, to the best of my understanding, means it's creating the .ipa file I need to submit to the app store), but I can't find the archived file. Where should it be? Can I define this in a setting somewhere in Xcode?

Update 2:

By fiddling with certificates and provisioning profiles I've finally been able to create an archive from Xcode, which I've been told is a release build (is it?). Ideally I would like to be able to build from the command line so that I can automate it as much as possible, so that's where I'll be picking up in the morning. Any advice on that front would be quite welcome!

like image 312
Adam Tuttle Avatar asked Mar 25 '14 15:03

Adam Tuttle


2 Answers

If you managed to create an archive in Xcode, then your signing certificate and provisioning profiles are known to Xcode, so cordova build ios --release --device should make it.

The steps are:

1) Import your iOS developer certificate for production to the keychain by downloading and double clicking on it in Finder (or get it via Xcode)

2) Download your provisioning profile (with the App ID set to the id attribute of the widget element in config.xml) and double click it on Finder so it goes to the Xcode provisioning profile store

3) cordova build ios --release --device

like image 67
Nacho Marín Avatar answered Nov 15 '22 11:11

Nacho Marín


it looks like you're trying to sign the app with a wildcard provisioning profile (the XCode screenshot). Can you try creating and downloading a distribution certificate and provprofile to your Mac? Then import the .cer file in the keychain access app (doubleclicking should suffice) and doubleclick the provprofile as well.

Now you should be able to select the appropriate values from the release dropdowns in the XCode build settings.

Hope this helps somewhat... Eddy

like image 34
Eddy Verbruggen Avatar answered Nov 15 '22 13:11

Eddy Verbruggen