Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift Pod causes runtime failure in Obj-C host app on device (codesign issue) #3008

Closed
jrosssavant opened this issue Jan 5, 2015 · 14 comments

Comments

@jrosssavant
Copy link
Contributor

🌈
I'm using the new 0.36.0.beta.1 prerelease version to see if I can create a pure-Swift Pod that will be included by a pure-Objective-C app project. I was able to build the pod and example app, but the app crashes on launch with this error:

dyld: Library not loaded: @rpath/libswiftCore.dylib
  ...
  Reason: no suitable image found.  Did find:
    ...MyApp.app/Frameworks/libswiftCore.dylib: code signature invalid for .../MyApp.app/Frameworks/libswiftCore.dylib'

I was able to resolve this issue by adding a few codesign executions to the Pods--frameworks.sh script at the end of the section "# Embed linked Swift runtime libraries"

for lib in $swift_runtime_libs; do
    echo "rsync -av \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
    rsync -av "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
  done
+  echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements ${destination}/*"
+  /usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements "${destination}"/*
@jrosssavant
Copy link
Contributor Author

The workaround I posted works fine, but it gets overwritten each time I do a "pod update".

jrosssavant added a commit to jrosssavant/CocoaPods that referenced this issue Jan 5, 2015
jrosssavant added a commit to jrosssavant/CocoaPods that referenced this issue Jan 6, 2015
jrosssavant added a commit to jrosssavant/CocoaPods that referenced this issue Jan 6, 2015
@secretfader
Copy link

I'm seeing this issue too, except with a project that is written in Swift, but needs to include both Swift and Objective-C libraries.

Without the Swift libraries in my Podfile, everything compiles and runs fine. When I include them, .dylibs suddenly become unavailable.

@jrosssavant
Copy link
Contributor Author

Yep, looks like there are some issues with how X-code handles this and the CocoaPods solution fixes some cases, but perhaps breaks yours. I think my patch will resolve this problem for you as well. My pull request: #3009. @fluidsonic posted this great article about what is actually going on: http://samdmarshall.com/blog/swift_and_objc.html

@secretfader
Copy link

@jrosssavant That error (both in your comment above and the linked article) looks exactly like mine. I can't reach libxml2.dylib, but I'm guessing this is a problem with all .dylibs.

How's it looking for the merge of #3009? Because I would love to keep cruisin' with Cocoapods, rather than needing to manually manage Swift libraries.

@jrosssavant
Copy link
Contributor Author

@nicholaswyoung Seems like there is some traction with the pull request - see the discussion. It's relatively straightforward to drop the fix into your current project, but it will be overwritten each time you run pod update.

  1. Find the file Pods--frameworks.sh in "Targets Support Files/Pods-"
  2. Add the block below to the end of the swift_runtime_libs loop block (around line 35)
    if [ "${CODE_SIGNING_REQUIRED}" == "YES" ]; then
      code_sign "${destination}/${lib}"
    fi

So the whole for loop will look like this:

  for lib in $swift_runtime_libs; do
    echo "rsync -av \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
    rsync -av "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
    if [ "${CODE_SIGNING_REQUIRED}" == "YES" ]; then
      code_sign "${destination}/${lib}"
    fi
  done

@jrosssavant
Copy link
Contributor Author

@nicholaswyoung Hmm, but I don't see how this could fix an issue with libxml2.dylib. Maybe you will have to add a codesigning step elsewhere.

@neonichu
Copy link
Member

neonichu commented Jan 7, 2015

@nicholaswyoung do you have a sample project for your problem? Would be interesting to see if there maybe is an additional issue.

@fluidsonic
Copy link
Contributor

@jrosssavant That's not my article. It's from @samdmarshall :)

@secretfader
Copy link

@neonichu I'll be working in an hour or so, and I'll throw together a demo then and share it.

@jrosssavant
Copy link
Contributor Author

@fluidsonic Sorry, didn't mean to imply you were the author of the article, just giving you credit for first posting the link in the PR.

@secretfader
Copy link

@neonichu Okay, the problematic project is up on Github: http://github.com/machinefm/ios

It's in progress, but if you download and try to build the master branch, it will compile and run fine. However, if you add:

pod 'Alamofire', git: 'https://github.com/Alamofire/Alamofire'

You'll see that the project throws errors when you try to build it.

@neonichu
Copy link
Member

neonichu commented Jan 7, 2015

@nicholaswyoung Thanks! It's actually a different issue, related to the use of frameworks when using Swift - could you please file it separately, then we can discuss and fix it there.

@secretfader
Copy link

@neonichu Filed as #3018.

jrosssavant added a commit to jrosssavant/CocoaPods that referenced this issue Jan 14, 2015
segiddins added a commit that referenced this issue Jan 15, 2015
Fix for issue #3008 Swift Pod causes runtime failure in Obj-C host app o...
@jrosssavant
Copy link
Contributor Author

PR #3009 was merged in df183ca. This issue is resolved; any objection to me closing?

@kylef kylef closed this as completed Jan 27, 2015
kylef added a commit that referenced this issue Jan 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants