Cannot import Cocoapod into Dynamic Framework - xcode

I am creating a project in Xcode8 which has a widget extension. I am trying to factor out my service API code (some class functions that hit a web API written in Swift) into a dynamic Framework.
I have created the Framework through the template and dragged my ServiceAPI.swift file/code to it. Made sure that the file was included in the framework target.
This code relies on SwiftyJSON to parse the JSON it gets from the web. Now, before moving the code into the framework, SwiftyJSON was compiled and running fine in my application target. After moving it I get a linker error:
ld: framework not found SwiftyJSON
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have tried several things to fix it. I thought possibly setting the framework search paths might work but no paths I added fixed the issue.
So what can I do to fix this?

It looks like you are using cocoapods. In that case you can simply add your framework as a target for the Pod, SwiftyJSON. To do this simply edit your Podfile to include the second target.
target 'MyApplication' do
pod 'SwifyJSON'
end
target 'MyFramework' do
pod 'SwiftyJSON'
end

Related

Xcode beta generates App cannot be opened because of a problem

Check with the developer to make sure MyApp works with this version of macOS.
After trying to use ASWebAuthenticationSession, when the App receives the callback, it shows the error:
The same error is showed after an attempt to generate the app and open it.
The error you are seeing is because your code is referring to either a non existing library or is pointing to the wrong directory where your code should look for such library. Please check the rpath you are using. Usually, you should place any dylibs inside a Frameworks folder inside your bundle and thus your rpath should start like this: ../Frameworks/InternalAPI.framework (...)

Framework Search Paths - Mixing $(inherited) with $(PROJECT_DIR)

I have an iOS project in XCode 11.2 that requires a mix of Frameworks, some of which are available on Cocoapods and some are not. For the non-Cocoapod frameworks, I have the frameworks copied to the root of my project folder.
The trouble comes with getting XCode to be able to find both using the Framework Search Paths setting as shown here:
All of the entries following $(inherited) are actually the ones inherited from Cocoapods (these are not explicitly specified).
If I don't add the $(PROJECT_DIR) at the end then Cococapod frameworks are found fine, but my embedded non-Cocoapod frameworks get compiler errors that their header files are not found.
If I do add the $(PROJECT_DIR) at the end, then the Cocoapod frameworks are not found and I get a build error like:
ld: warning: directory not found for option '-F/Users/dyoung/Library/Developer/Xcode/DerivedData/MyApp-acdmyjbbrpbhlkfiyypetovwacrz/Build/Products/Debug-iphoneos/AWSAuthCore'
...
ld: framework not found AWSAuthCore
Why? How do I get XCode to find frameworks in both places?
Here's one way:
pod deintegrate
Open the .xcodeproj
Add the non-CocoaPods frameworks.
pod install
Open the .xcworkspace
The problem was that the CocoaPods Frameworks that I was trying to add were built only for iOS 11+, but my very old project had a deployment target of iOS 8.4.
Looking at error details in the Report Navigator as #paul-beusterien suggested was critical. I found this:
Ld /Users/dyoung/Library/Developer/Xcode/DerivedData/MyApp-acdmyjbbrpbhlkfiyypetovwacrz/Build/Intermediates.noindex/MyApp.build/Debug-iphoneos/MyApp.build/Objects-normal/armv7/Binary/MyApp normal armv7 (in target 'MyApp' from project 'MyApp')
The key thing there is the armv7 architecture. This architecture is only part of the build process if you have a deployment target of 10.x or earlier but not if you have 11.x or later. And if the frameworks you are including don't have armv7 architecture (e.g. if they are built for 11.0+), XCode gives very misleading error messages about the frameworks not being found. What really isn't found is that specific architecture inside the framework.
Bottom line: My problem had nothing to do with framework search paths. Removing $(PROJECT_DIR) from the framework search path only appeared to solve the problem by triggering a different compile-time problem to happen before it got to the linker problem.
The solution in this case is that I must change my deployment target to 11.0, then everything builds properly.

iOS8: Custom Swift Framework accessing external framework written in Objective-C

I'm trying to create a custom framework called CouchbaseKit (a new target in Xcode) in Swift. Inside my CouchbaseKit, I need to access CouchBaseLite Framework that's entirely written in Obj-C. I'm using Cocoapods to manage CouchBaseLite and a couple of other frameworks. Below is my podfile.
Podfile
# Uncomment this line to define a global platform for your project
link_with ['CouchbaseKit']
# platform :ios, '8.0'
use_frameworks!
target 'CouchbaseDB' do
link_with ['CouchbaseKit']
pod 'couchbase-lite-ios'
pod 'SwiftyJSON', '~> 2.2.0'
pod 'Alamofire', '~> 1.2'
pod 'XCGLogger', '~> 2.0'
end
target 'CouchbaseDBTests' do
end
target 'CouchbaseKit' do
end
target 'CouchbaseKitTests' do
end
Pods inside the project:
For my TARGETS I have the following settings in Build Phases.
Define Module Yes
Allow Non-modular Includes in Framework Modules Yes
Problem:
When I try to access the CouchbaseLite framework inside my CouchbaseKit (my custom framework), I get an error, "No such module 'CouchbaseLite' does not exist.
Tried:
Since the project is in Swift, I created an Objective-C File and Hit yes to "Would you like to configure an Objective-C bridging header?"
Even though Allow Non-modular Includes in Framework Modules is set to YES in all targets, I still get an error when I try to #import <CouchbaseLite/CouchbaseLite.h> in CouchbaseKit.h
Here is what my Build Phases looks like for my custom framework CouchbaseKit
Question: How can I see an external Objective-C framework (CouchasebaseLite) in my custom Swift framework?
CouchbaseLite on iOS is a static framework, i.e. its binary is a static library not a dylib. This means it's linked into your app as though it were a source file. For this reason you don't use import in Swift to access it; the classes are already in the same namespace as your app's classes.
Unfortunately Cocoapods 0.39 suffers from "Transitive Vendor Dynamic Libraries Unsupported" You'll see this with the newest couchbase-lite-ios release including the binary CouchbaseLite.framework. This unfortunately issue bit me so hard I had to refactor everything to use Carthage, and manually manage my frameworks in my final projects.
Speaking of which the binary released CouchbaseLite.framework is simply missing a module map.
Add one to: CouchbaseLite.framework/Modules/module.modulemap
framework module CouchbaseLite {
umbrella header "CouchbaseLite.h"
export *
module * { export * }
}
You will then be able to include this framework into a bridging header, and have your dynamic framework nest properly. But you might need to switch to building your CouchbaseKit.framework to using Carthage like I did.
If you still want to use Cocoapods you can follow this
Steps:
Create a folder called the name of your Framework you want to use in
that case CouchbaseLite and inside it create module map. The file name will be module.map and its content will be
module CouchbaseLite {
header "../Pods/couchbase-lite-ios/CouchbaseLite.framework/Headers/CouchbaseLite.h"
export *
}
Important Note: Don't add that folder to the project, I don't know why not when done it will not work.
Import Paths under Swift Compiler – Search Paths in your project settings. Use ${SRCROOT} in the module path (e.g. ${SRCROOT}/CouchbaseLite)
.
Then you can import it like any swift module.
Update:
It will work nicely in Xcode, but when I have tried to validate the pod with the pod lint it still give error and I still don't know why.

dyld library error while using cocoapods to add testing library

I'm trying to install a testing library for a project on top of SenTestingKit.
Prior to installing, the project builds fine and runs the test suite using SenTestingKit.
However, after using cocoapods to install another testing framework like Specta or Kiwi (which apparently depend on SenTestingKit), the project builds, but then immediately throws this error:
dyld: Library not loaded: #rpath/SenTestingKit.framework/Versions/A/SenTestingKit
Referenced from: [...]
Reason: image not found
I've tried about a dozen different suggestions from people with similar problems (changing the target build settings test host, changing the target framework search paths, etc, making sure pods are configured for the test target, etc.), all to no avail. Any suggestions?
Try with the following steps to link the static library to our project (which inturn uses a framework or static library):
Include the static library in the main projects "link binary with library".
Provided the header path at HEADER_SEARCH_PATH as well as LIBRARY_SEARCH_PATH (Inside Build Settings of app's target).
Most important:
In the target's build phases - > Link binaries with libraries set the relevant framework (SenTestKit.framework in our case) to "Optional" instead of "Required".
Hope this will fix your issue
Finally tracked down the answer.
Following the steps laid out in the answer here fixed the issue:
How to set dyld_library_path in Xcode

Using the Parse iOS SDK with RubyMotion

RubyMotion provides these instructions for vendoring 3rd party code: http://www.rubymotion.com/developer-center/guides/project-management/#_files_dependencies
I'm trying to add Parse.com's iOS SDK. These are the instructions for adding it to an XCode project: https://parse.com/apps/quickstart#ios/existing. However, I'm not using XCode since I'm working with RubyMotion.
I documented my attempt here: https://github.com/adelevie/RubyMotionSamples/commit/603bf4428995bb203cce7e7e8e6989d6e86bda3b
And here are the errors I'm getting: https://gist.github.com/2595284
I believe we're actually dealing with a static library here, so I believe you should specify :static instead of :Xcode as the second option.
With the following code in your Rakefile, the app compiles:
app.libs << '/usr/lib/libz.1.1.3.dylib'
app.frameworks += [
'AudioToolbox',
'CFNetwork',
'SystemConfiguration',
'MobileCoreServices',
'Security',
'QuartzCore']
app.vendor_project('vendor/Parse.framework', :static,
:products => ['Parse'],
:headers_dir => 'Heiders')
However, I'm getting the following error running the Parse setApplicationId method:
(main)>> Objective-C stub for message `setApplicationId:clientKey:' type `v#:##' not precompiled. Make sure you properly link with the framework or library that defines this message.
The documentation linked says, "To vendor a 3rd-party library in a RubyMotion project, the source code must be available somewhere on the filesystem." So I don't think dropping a .framework file in there will work.
You could try downloading the ParseStartProject, called "Blank Xcode w/ SDK" from parse.com/docs. If you vendor that project folder, RubyMotion will be able to find an xcode project like it's looking for. You'll want to delete the .m and .h files from the xcode project, of course, since you only want the project to include Parse.framework.
I haven't actually tried this. Please let us know if you get it working.
Okay copied this from an answer in the RubyMotion group. It seems to fix the stub error message:
Now, to make this work, I've modified /Library/RubyMotion/lib/motion/project/vendor.rb and changed the Dir.glob on line 38 from:
source_files = (opts.delete(:source_files) or Dir.glob('*.
{c,m,cpp,cxx,mm,h}'))
to:
source_files = (opts.delete(:source_files) or Dir.glob('**/*.
{c,m,cpp,cxx,mm,h}'))
http://groups.google.com/group/rubymotion/msg/0efa74214523d0f5

Resources