Failed to generate release build of cordova ios app
Asked Answered
T

4

5

I am using phonegap CLI 3.1 and XCode5. I am trying to generate the build for release mode through Phonegap CLI and Xcrun. I don't want to use Phonegap Build to upload the mobileprovision or whatever the process of them. I want to do it by xcrun to assign the mobileprovison to release build.

1) cordova build ios --release

Compiling app on platform "ios" via command "/Applications/MAMP/htdocs/MyTest/MyTestApp/platforms/ios/cordova/build" --release Platform "ios" compiled successfully.

2) sudo xcrun -sdk iphoneos PackageApplication -v "ios/build/emulator/MyTestApp.app" -o "/Users/mymac/Desktop/Testnew/MyTestApp.ipa" --sign "iPhone Distribution: NAME (TEAM_ID)" --embed "MyTestApp_Dis.mobileprovision"

Packaging application: 'ios/build/emulator/MyTestApp.app' Arguments: embed=MyTestApp_Dis.mobileprovision verbose=1 output=/Users/mymac/Desktop/Testnew/MyTestApp.ipa sign=iPhone Distribution: NAME (TEAM_ID)
Environment variables:
HOME = /Users/mymac
SUDO_GID = 20
SDKROOT = /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk
VERSIONER_PERL_PREFER_32_BIT = no
MAIL = /var/mail/root
SSH_AUTH_SOCK = /tmp/launch-zsBMC8/Listeners
LANG = en_US.UTF-8
USER = root
LOGNAME = root
__CF_USER_TEXT_ENCODING = 0x0:0:0
USERNAME = root
PATH = /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
SUDO_USER = mymac
SHELL = /bin/bash
TERM = xterm-256color
SUDO_COMMAND = /usr/bin/xcrun -sdk iphoneos PackageApplication -v ios/build/emulator/MyTestApp.app -o /Users/mymac/Desktop/Testnew/MyTestApp.ipa --sign iPhone Distribution: NAME (TEAM_ID) --embed MyTestApp_Dis.mobileprovision
SUDO_UID = 501
VERSIONER_PERL_VERSION = 5.12

Output directory: '/Users/mymac/Desktop/Testnew/MyTestApp.ipa'
Temporary Directory: '/tmp/W81FhZ9VAH' (will NOT be deleted on exit when verbose set)
+ /bin/cp -Rp ios/build/emulator/MyTestApp.app /tmp/W81FhZ9VAH/Payload
Program /bin/cp returned 0 : []

Checking original app

  • /usr/bin/codesign --verify -vvvv ios/build/emulator/MyTestApp.app
    Program /usr/bin/codesign returned 1 : [ios/build/emulator/MyTestApp.app: code object is not signed at all
    In architecture: i386
    ] Codesign check fails : ios/build/emulator/MyTestApp.app: code object is not signed at all In architecture: i386

Done checking the original app

Embedding 'MyTestApp_Dis.mobileprovision'

  • /bin/rm -rf /tmp/W81FhZ9VAH/Payload/MyTestApp.app/embedded.mobileprovision Program /bin/rm returned 0 : []
  • /bin/cp -rp MyTestApp_Dis.mobileprovision /tmp/W81FhZ9VAH/Payload/MyTestApp.app/embedded.mobileprovision Program /bin/cp returned 0 : []
  • /usr/bin/codesign -d --entitlements /tmp/W81FhZ9VAH/entitlements_rawixGWnKhi /tmp/W81FhZ9VAH/Payload/MyTestApp.app Program /usr/bin/codesign returned 1 : [/tmp/W81FhZ9VAH/Payload/MyTestApp.app: code object is not signed at all ]
    error: Failed to read entitlements from '/tmp/W81FhZ9VAH/Payload/MyTestApp.app'
Tollefson answered 5/11, 2013 at 7:40 Comment(0)
J
2

Hmmh, I'm having a similar problem like Shashi.

When running 'cordova buld ios [--release]' from shell and then doing a 'xcrun ...' afterwards it works for me okay.

BUT: When running this sequence from within a script, I receive a "Codesign check fails ..." error too ...

If I insert (like) a "wait" cycle inside my script between the cordova and the xcrun call, it works.

So - to me - it seems, as if cordova returns to shell while it isn't completely finished (?)

Fact is if I code my script like

#!/bin/bash
cordova build ios --release
sleep 5
sh -c "xcrun ..."

it's working for me. Question: Is it a bug in cordova/phonegap ???

Jablonski answered 2/12, 2013 at 9:44 Comment(1)
Another observation (and probably the explanation (?)) If I replace the 'sleep' by e.g. a copy command, I get an error from that copy that the App folder which the 'cordova build ...' is creating wouldn't exist !?! In fact - later - it DOES exist. Which is why after having waited some time (the 'sleep') it succeeds. So to me it seems that 'cordova' is no synchronous command(!) Means: If it exits (with like '0') it still isn't done yet !!! Sounds logical ???Jablonski
J
2

Meanwhile I found: Fact is, that - when cordova exits and returns to shell - cordova related activities are NOT completed yet!

It takes a while after the cordova exit, for the 'platforms/ios/AppName/_CodeSignature/CodeResources' file to show up. This file obviously is essential for the 'codesign' which is started by xcrun command to succeed.

So I do in my script (which i call 'buildit.sh')

#!/bin/bash
[...]
cordova build ios --release
signaturefile="platforms/ios/build/device/$appname/_CodeSignature/CodeResources"
echo DEBUG:signatur file is $signaturefile

while [ ! -f $signaturefile ]
do
  echo waiting
  sleep 1
done
xcrun ...

Then the whole build/packaging process in one script succeeds.

However: Running the script from my ContinuousIntegration server Jenkins, I observe that this criteria may be essential, but not enough. From the CI I still get a

/usr/bin/codesign --verify -vvvv [...] Program /usr/bin/codesign returned 1 : [...] code object is not signed at all

error!??

EDIT (05.12.2013): This is due to the fact that the Jenkins service couldn't access the keychain. E.g. doing in the Jenkins job an unlock of the keychain prior running the build script sorts it. (May not be the most elegant solution, but at least it prooves the problem not to be in the scripting :)

Jablonski answered 3/12, 2013 at 10:14 Comment(3)
BTW: I just run this on a much faster machine with a much more powerful CPU and a SSD instead of an ordinary HD. On such a faster machine the encountered issue doesn't show at all. Still IMO this remains to be a bug in cordova ...Jablonski
even more weird: having created an image of the machine where it fails and booting the more powerful machine with that disk image, the issue shows here too !? so it must be an issue with the MacOS setup of that particular machine/disk (where it fails)? strange ... ! as I'm no MacOS expert and short on time, I give up here :|Jablonski
one more to mention: further analysis (with 'dtrace' showed, that cordova is calling a script which itself shall start 2 'xcrun...' processes (one for device package/build, one for emulator package/build). however we see that this script at a certain point in time gets a "kill" signal, which is why the first xcrun falls back to PPID 1 (the init:), and the 2nd xcrun never gets executed. ... and the cordova exits, while the 1st xcrun still isn't complete.Jablonski
J
2

So, finally I got everything to work okay ... :D

The problem of Jenkins complaining about a failed 'codesign ...' run is a MacOS (configuration) issue

The crucial thing is to allow the Jenkins access to the keychain of the system. The allowed access for the Login-shell of the Jenkins user is different from the Jenkins server process running under the Jenkins user account (!)

For now I realize this by running the unlock of the login.keychain within the Jenkins job before running my build script

like: in the Jenkins job for "execute shell"

security unlock-keychain -p password /Users/Shared/Jenkins/Library/Keychains/login.keychain
echo ##### building now ######################
./buildit.sh ios --release -v

This may not be the 100% nicest solution - but for now it works :P

See as well: [1]: Keychain won't unlock from Jenkins script unless user logged in

Jablonski answered 4/12, 2013 at 12:39 Comment(1)
Ugh, just so no one else spends hours fighting this problem... Same thing applies to if you're building from SSH! The security keychain unlock does not work properly without special measures!Gild
G
1

In order to skip the code signing you can perform a manual build from the console like this:

xcodebuild clean build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO Use additionally the -configuration, -target and -sdk parameters in order to define your build settings.

To Disable Code Signing:

*Go to /Applications. Right click on XCode and select 'Show Package Contents'. Copy Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/SDKSettings.plist to your desktop. (Make sure to actually copy and paste. No drag and drop) Open it and under DefaultProperties set CODE_SIGNING_REQUIRED to NO. Copy it back and replace the original file. Restart XCode. Open your project. In Project Navigator select your project and open Build Settings section of your porject (and not any particular target) Under Code Signing find Code Signing Identity and for both Debug and Release modes set Any iOS SKD to Don't Code Sign. Now you should be able to build your project without any errors.*

To make an IPA:

In 'Project Navigator' select Products Right click on [NameOfYourProject].app and select 'Show in Finder'. Create a folder and name it Payload Move [NameOfYourProject].app to Payload. Compress Payload and rename it to [NameOfYourProject].ipa

Glabrate answered 15/11, 2013 at 9:35 Comment(1)
Adding CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO to the build.xcconfig file in the ios platform directory seems to solve the problem.Arteritis

© 2022 - 2024 — McMap. All rights reserved.