Cocoapods: Missing embed pods build phase for Messages Extension target

Created on 5 Jul 2016  ยท  30Comments  ยท  Source: CocoaPods/CocoaPods

What did you do?

Create a new "Messages Extension" in Xcode 8. On the master cocoapods branch, run pod install. Then run on simulator. It is worth noting that there is no scheme in this Xcode template to build the host application (as messages extensions are intended to be installed without a host application). There are, however, two targets, the first of which is seemingly useless, and the second of which is the actual messages extension.

What did you expect to happen?

I expected my app to launch with all specified pods available for use.

What happened instead?

First, I got a runtime error when the app is launched:

dyld: Library not loaded: @rpath/XLForm.framework/XLForm
  Referenced from: /Users/andrew/Library/Developer/CoreSimulator/Devices/1BC2D122-FFBF-41DF-88B1-5A847A67856B/data/Containers/Bundle/Application/47FC386C-F697-4211-965D-13A8CE8C5C47/ExampleMessagesExtension.app/PlugIns/MessagesExtension.appex/MessagesExtension
  Reason: image not found

Second, I noticed that the "Embed Pods" step is missing from the build phases.

The issue can be fixed by ensuring that the framework is weakly linked and manually adding a "Run Script" build phase for the -frameworks.sh script

CocoaPods Environment

Stack

   CocoaPods : 1.0.1
        Ruby : ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
    RubyGems : 2.0.14.1
        Host : Mac OS X 10.11.5 (15F34)
       Xcode : 7.3.1 (7D1014)
         Git : git version 2.7.4 (Apple Git-66)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ e2e04b498cde0a253beecd2ece18ab649ab4e24d

Installation Source

Executable Path: ../cocoapods/bin/pod

Plugins

cocoapods-deintegrate  : 1.0.0
cocoapods-dependencies : 1.0.0.beta.1
cocoapods-plugins      : 1.0.0
cocoapods-search       : 1.0.0
cocoapods-stats        : 1.0.0
cocoapods-trunk        : 1.0.0
cocoapods-try          : 1.0.0
cocoapods_debug        : 0.1.0

Podfile

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

target 'ExampleMessagesExtension' do
  # Comment this line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for ExampleMessagesExtension

end

target 'MessagesExtension' do
  # Comment this line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MessagesExtension
  pod 'XLForm', '~> 3.0'
end

Project that demonstrates the issue

https://github.com/ndrewh/pods-example-error

discussion

Most helpful comment

@neonichu I looked into this some more, and the messages application target does have target dependencies (looks like there's just no way to manage them in Xcode). This is probably why 1.1.0.beta.1 strips the embed frameworks build phase from the extension target (it works! ๐Ÿ˜ƒ). I guess this scenario just needs an exception: if the host is a messages application, then leave it be. I'll have a look at doing this soon.

All 30 comments

Thanks for the sample, my guess is that the Messages Extension product types are not handled correctly, yet.

Whoops. I forgot to actually commit the sample project in the erroring state, fixed now. So https://github.com/ndrewh/pods-example-error/commit/3d83201a52f9f7d6845b34cf56660d7a36903a1d is the Xcode template and https://github.com/ndrewh/pods-example-error/commit/dcd3a0fb7bfd855eaab8e75f2125c1b14a65be92 is after pod install

@neonichu I included messages extensions in #5502. The embed frameworks phase should be missing for that target, since the frameworks will be embedded in the application target.

As long as the messages extension is listed in the Target Dependencies phase of the application target it's embedded in, and the Runpath Search Paths are setup property (should be by default) for the messages extension, it should work okay. I'll have a look at the sample project later today.

@ndrewh I cloned your pod-example-error repo, and when I open the workspace in Xcode 8 beta 2, the application target has no Build Phases tab and is generally missing a bunch of other tabs I'd expect to see (which are present for the messages extension target) like Build Settings, Capabilities, etc:

Application Target:
screen shot 2016-07-08 at 7 54 00 am

Messages Target:
screen shot 2016-07-08 at 7 55 23 am

Is it possible this project was upgraded from a previous beta and the upgrade to the project didn't go well or something? Can you try re-creating the application target and then running pod install again? It might be worth just creating a new project

I can try to test out a new project in Beta 2 tomorrow. But in beta 1 the
behavior was just as your screenshots show - the host application is
missing build settings. I had assumed this was because messages
applications by default are standalone and do not have a host application
which shows on the home screen.

As I said, I'll try this in Beta 2 tomorrow. But I suspect cocoapods will need
to adapt to handle cases where there may or may not be a buildable host
application.
On Fri, Jul 8, 2016 at 10:56 AM Ben Asher [email protected] wrote:

@ndrewh https://github.com/ndrewh I cloned your pod-example-error repo,
and when I open the workspace in Xcode 8 beta 2, the application target has
no Build Phases tab and is generally missing a bunch of other tabs I'd
expect to see (which are present for the messages extension target) like
Build Settings, Capabilities, etc:

Application Target:
[image: screen shot 2016-07-08 at 7 54 00 am]
https://cloud.githubusercontent.com/assets/1120429/16691346/361cbb48-44e1-11e6-9cb7-1f1dbb4a3e80.png

Messages Target:
[image: screen shot 2016-07-08 at 7 55 23 am]
https://cloud.githubusercontent.com/assets/1120429/16691377/60158902-44e1-11e6-9dc2-19567ee0e126.png

Is it possible this project was upgraded from a previous beta and the
upgrade to the project didn't go well or something? Can you try re-creating
the application target and then running pod install again? It might be
worth just creating a new project

โ€”
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/CocoaPods/CocoaPods/issues/5594#issuecomment-231381919,
or mute the thread
https://github.com/notifications/unsubscribe/ACBLY4JQu_FhKtD17xY2u1unj3VGrbe0ks5qTmU5gaJpZM4JEzG0
.

Right now, CocoaPods has certain product types white-list as requiring a host target. Messages extensions are one of those, but this could be easily changed. The current understanding (from the CocoaPods code standpoint) is that messages extensions require a host target, and this seems to be accurate based on the default setup in beta 2. If it's possible to have a project where a messages extension builds without an application target, then I suppose we'll have to add another kind of target: one that can be built with and without a host. This situation seems unlikely to me though.

I just tried (another) new project in beta 2:

template

And the issue persists. The main app target does not have build settings or build phases. Tried with cocoapods master.

Ah okay. @neonichu, CocoaPods currently supports the product type com.apple.product-type.app-extension.messages (:messages_extension) but not com.apple.product-type.application.messages (the target in question). I can try working on this this week. @ndrewh thanks for bearing with me.

@neonichu do you know if messages extensions can have frameworks embedded into them? I looked into this some more and right now there are 2 cases with messages extensions:

  1. Messages extension is extending an app
  2. Messages extension is extending a messages app (this case)

In case 2, the messages app has no build phases, which makes me think that maybe messages extensions should be able to (in either case) allow the embedding of frameworks. It seems like it'd be crazy to restrict this in case 1 but not in case 2. Thoughts? Maybe I pre-maturely added messages extensions to the list of extension types that can't have frameworks embedded in them.

@benasher44 I'm not sure โ€” but my guess would be the same as yours: in case 1, frameworks need to be embedded in the host application and in case 2, they need to be embedded in the extension.

@neonichu I looked into this some more, and the messages application target does have target dependencies (looks like there's just no way to manage them in Xcode). This is probably why 1.1.0.beta.1 strips the embed frameworks build phase from the extension target (it works! ๐Ÿ˜ƒ). I guess this scenario just needs an exception: if the host is a messages application, then leave it be. I'll have a look at doing this soon.

@ndrewh I've made some progress, but I don't have a PR up quite yet. Can you try updating your Gemfile to look like this:

gem 'cocoapods', :git => 'https://github.com/benasher44/CocoaPods', :ref => '72b005cd89e9524498c01514b269f0ad2791d018'
gem 'xcodeproj', :git => 'https://github.com/benasher44/Xcodeproj', :ref => '386ea77acb69c0c9ef4397b07e5a4b87dba6ca5b'

I believe this should bring back the build phase in cases where the messages extension is embedded in a messages application.

Update 1: I had rebase problems, but now it should be okay. Shas are up-to-date
Update 2: Updated the shas again now that the related CocoaPods/Xcodeproj#396 PR is in master.

@benasher44 This doesn't seem to be working. Assuming, of course, that I modified my Gemfile correctly. It looks like this:

source 'https://rubygems.org'

gem 'cocoapods', :git => 'https://github.com/benasher44/CocoaPods', :ref => '72b005cd89e9524498c01514b269f0ad2791d018'
gem 'xcodeproj', :git => 'https://github.com/benasher44/Xcodeproj', :ref => '386ea77acb69c0c9ef4397b07e5a4b87dba6ca5b'
gem 'cocoapods-downloader', :git => 'https://github.com/CocoaPods/cocoapods-downloader.git'
gem 'cocoapods-keys', :git => 'https://github.com/orta/cocoapods-keys.git'

gem 'xcpretty'
gem 'shenzhen'
gem 'sbconstants'

I did bundle install and ran with bundle exec pod install --project-directory=<some directory> but the embed frameworks phase is still missing.

I created a new project with the "Messages Application" template, ran pod init, added a gem to the Podfile (under the MessagesExtension target) and then ran pod install as shown above.

@ndrewh okay thanks for looking into it. i'll try debugging it some more this afternoon

Okay. Try with

gem 'cocoapods', :git => 'https://github.com/benasher44/CocoaPods', :ref => 'b68487eae32213f8194bdaa5611f311152e4903d'
gem 'xcodeproj', :git => 'https://github.com/benasher44/Xcodeproj', :ref => '386ea77acb69c0c9ef4397b07e5a4b87dba6ca5b'

@benasher44 It works! ๐Ÿ‘

Great! I'll try to have a PR up soon.

@ndrewh PR is out! I'd appreciate it if you could update your Gemfile and report back!

gem 'cocoapods', :git => 'https://github.com/benasher44/CocoaPods', :ref => '4742e6cb6624f04b170523767f786d12ea334349' # PR
gem 'xcodeproj', :git => 'https://github.com/CocoaPods/Xcodeproj', :ref => '2f8cc93e82df9cb207eca789cdadded02ac9e7a9' # Xcodeproj master

@benasher44 Hmm, not working this time. It looks like some code didn't make it from the working commit into the PR? https://github.com/benasher44/CocoaPods/compare/4742e6cb6624f04b170523767f786d12ea334349...benasher44:b68487eae32213f8194bdaa5611f311152e4903d (edit: or perhaps github isn't telling me the truth)

@ndrewh PR just got merged. Going to double check again. That is odd.

@benasher44 After merge with CocoaPods + Xcodeproj master it works fine. Dunno what was going on earlier.

@ndrewh Yep it works. I gave you the wrong Xcodeproj sha. Phew ๐Ÿ˜…. Thanks again for the help!

Hi @benasher44 what is the current sha to get this working?

@lostincode it's on master now!

ah thanks!

I'm having the same issue. How to get this working? sudo gem install cocoapods --pre didn't help.

@andrew8712 you'll need to use a local Gemfile in your project directory to use master branch. More info: https://guides.cocoapods.org/using/a-gemfile.html

I'm having the same issue in my project - I've updated to the cocoapods master branch, but it hasn't resolved the error. Anything else I could try? The error I'm receiving is:

dyld: Library not loaded: @rpath/KeychainAccess.framework/KeychainAccess
  Referenced from: /Users/Andrew/Library/Developer/CoreSimulator/Devices/FC209E75-4661-49E0-A127-4A179ACB9E4D/data/Containers/Bundle/Application/D44E7C27-6BA7-40CF-9230-6D74B8015A8B/MarcyMoji.app/PlugIns/MessagesExtension.appex/MessagesExtension
  Reason: image not found

Here's my Podfile:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'xxxxx' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!
  # Pods for xxxxx

end

target 'MessagesExtension' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!
 pod 'KeychainAccess'
  # Pods for MessagesExtension

end

Cocoapods version is: 1.1.0.rc.2

We're currently discussing this issue and the PR fix in #5860

Was this page helpful?
0 / 5 - 0 ratings