Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I codesign a Swift app via the commandline?

Tags:

ios

swift

xcode6

I am attempting to run an enterprise signed build of my Swift app on a real phone running iOS 7.1.

If I create the enterprise signed app via the Xcode interface, the app works perfectly. If I create the enterprise signed app via xcodebuild and codesign on the command line, then the app crashes on open with the following log:

Dyld Error Message:
Library not loaded: @rpath/libswiftCore.dylib
Referenced from: /var/mobile/Applications/96578E7F-7FE6-4603-82F2-8941561225D8/Foo.app/Foo
Reason: no suitable image found.  Did find:
  /private/var/mobile/Applications/96578E7F-7FE6-4603-82F2-8941561225D8/Foo.app/Frameworks/libswiftCore.dylib: code signature invalid for '/private/var/mobile/Applications/96578E7F-7FE6-4603-82F2-8941561225D8/Foo.app/Frameworks/libswiftCore.dylib'
Dyld Version: 324

When I create the IPA via the command line, the IPA always contains the same libswiftCore.dylib

$ md5 cli/Payload/Foo.app/Frameworks/libswiftCore.dylib
MD5 (cli/SwiftSupport/libswiftCore.dylib) = 0fe0370b5585a88a89d230b7501aee31 <- same every time; matches what is provided by Xcode

$ md5 /Applications/Xcode6-Beta5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCore.dylib
MD5 (/Applications/Xcode6-Beta5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCore.dylib) = 0fe0370b5585a88a89d230b7501aee31 <- Same!

When the Xcode UI produces the IPA, it is clear that it is somehow signing or modifying libswiftCore.dylib

$ md5 ui/Payload/Foo.app/Frameworks/libswiftCore.dylib
MD5 (ui/Payload/Foo.app/Frameworks/libswiftCore.dylib) = df73f604b1370b19721dfa7de298340f <- different every time

I have tried using the --deep option on codesign with no luck.

How can I get libswiftCore.dylib to get signed correctly when building/codesigning via the command line?

like image 737
Nick Snyder Avatar asked Aug 13 '14 23:08

Nick Snyder


People also ask

How do I run Xcode from command line app?

go to the 'Info' tab and in a menu 'Executable' choose 'Other...' in file window go to search input field and type 'terminal' and click on its icon when you find it. Now you should see 'Terminal. app' in 'Executable' field.

What is your codesign identity?

This is a cryptographic process that identifies you as a developer, and identifies your application as something that has been distributed by you. The process of obtaining a code signing identity is slightly different on every platform.


4 Answers

It looks like as of Xcode 6 Beta 6 you need to codesign the Swift libraries manually.

codesign --force --verbose --sign 'iPhone Distribution: My Company' Foo.app/
codesign --force --verbose --sign 'iPhone Distribution: My Company' Foo.app/Frameworks/*

I have filed a bug report with Apple and hopefully they will make this happen automatically if you use codesign's --deep option.

like image 185
Nick Snyder Avatar answered Sep 27 '22 17:09

Nick Snyder


The solution is not obvious but easy. Apple changed something in the code signing process for Swift:

  • Delete your distribution certificate and provisioning profile from your developer machine
  • Log into the developer portal
  • generate a new production certificate and distribution provisioning profil
  • Install both on your mac

The error should be gone.

like image 23
Lukas Alperowitz Avatar answered Sep 27 '22 18:09

Lukas Alperowitz


I create a gist to solve this problem, and it works (->link).

The main idea is to codesign the dylibs frist, and then codesign the app.

like image 39
idy Avatar answered Sep 27 '22 17:09

idy


codesign -f -s 'iPhone Distribution: My Company' Foo.app/Frameworks/*
codesign -f -s 'iPhone Distribution: My Company' Foo.app --entitlements=$ENTITLEMENTS_PATH

not the other way around, otherwise it will fail on installing

like image 36
Hogdotmac Avatar answered Sep 27 '22 19:09

Hogdotmac