"Relative to Current SDK" doesn't work mixing Mac Framework and iPhone static library - xcode

I have a framework of code I maintain. It's got mac and iphone objective-c code. And some of it is shared. I'm not having any problems with code. It's a problem with Xcode.
Let's just call my framework "AwesomeKit" for this problem.
The first thing I did was create an xcode Framework project called "AwesomeKit". Add source files to it, link against the common mac frameworks: foundation, cocoa, carbon, etc. It compiles fine.
Then, add a new "static library" target, let's call it "AwesomeKit-iPhone" and set the base SDK in the build settings to iphone device 3.1.3.
The problem comes when I try to add "Existing Frameworks" to the AweseomKit-iPhone target.
First change the current build target to AwesomeKit-iPhone.
Right click on any group and select "Add > Existing Frameworks..."
Choose UIKit.framework
UIKit will immediately be highlighted red, as if it's missing. It is indeed missing because Xcode uses the "Relative SDK" setting from the "Mac OS 10.6" SDK. When it should be using it relative to the current target's base sdk iphone device 3.1.3.
What the heck? Has anyone experienced this? This is really annoying.

I found the solution to this. You have to edit the project.pbxproj file inside of the project.xcodeproj directory. Find any entries like "SDKROOT = XXX" and change it to you real base root. It's probably best to look another project.pbxproj file that has it correctly set. I've used this on multiple occasions now and works like a charm. Usually there's 2 or more of the SDKROOT entries in project.pbxproj.

I think I've seen your problem. I'm still new myself to this, but what I've found when universal static libraries for both simulators and devices is that it's best to keep the Xcode Active SDK set to "Base SDK" rather that selecting an SDK. IN that mode, the current SDK is the SDK of the currently selected target.
Active SDK is rather like overriding the sdk on the command line. If yoy set it, SDK settings on targets will be overridden.
So im my case I wanted two targets to be run at the same time, one using the simulator sdk which compiles for i386 architecture and the other pointing at the device sdk which builds a universal lib for armv6/armv7 architectures.
I have seen the red not found stuff and I seem to remember that doing this, made it go away. I also had the project SDK set to a device rather than Mac. Remember that targets override this so it's a good way to ensure that Xcode is pointing at the right sdk without effecting the settings on targets and the ultimate build.

I'm in the same boat right now, XCode keep tacking the wrong SDK in front of the frameworks. This is project with both OSX and iOS targets. But there's seems to be something really wrong with my Project Build settings. Your screenshots don't show them, but you may want to check them. In my case, many entries are duplicates. So I have two categories "Architectures", totally identical. If I change one, the other changes along with it. This could be related to the problem with the wrong SDK being chosen. I think the project file is corrupted, and I'm now trying to figure out if I can fix it manually.

Related

How Do I Delete A Target In Xcode 9?

Xcode 9 is quite similar to Xcode 8.
I'm building Apple's Open Source IOGraphicsFamily.
In the Products group there is a target called iogdiagnose. Its source produced many compiler errors when I tried to build all my targets, so I removed the group with iogdiagnose's source from my project.
But the iogdiagnose target is still there. It produces a link error - missing main.
Google failed to yield insight. There was the same question for Xcode 6.1, but Xcode 9 is quite different from 6.1.
Building the IOGraphicsFamily driver stack has been a huge PITA. I need my own build so I can enable the driver stack's kprintf logging.
Simply right-click on the target and click on Delete.
I deleted the target by editing the project.pbxproj that's in the .xcodeproj bundle.
That worked just fine however but there must a GUI to delete targets.
The great thing about Xcode is that Apple keeps us sharped-eyed by rearranging the GUI in profound ways with each new release.

Linking dual (iphoneos and watchos) frameworks with same product name

I recently had to duplicate my own frameworks to be able to link them from the native watchOS 2 extension, because the platform is different. So for every framework X I have an X-watchos counterpart.
Everything works fine in the simulator and when building directly to my devices, and it wasn't until I tried to archive that I got this linking error:
I ran lipo -i on the built watchOS framework and sure enough, its archs are arm7 and arm64 instead of armv7k.
When I looked further into the built directory I noticed this:
Both versions are symlinks to the same file, and because the have the same product name, they're being overridden. I could make them have different names, but that would make importing them really cumbersome.
Note that this is not a problem for 3rd-party frameworks because Carthage is already building them in separate directories.
EDIT 08/22/2015: I've filed a radar with a sample project: http://www.openradar.me/22392501
EDIT 08/24/2015: This has been acknowledged in Xcode 7 Beta 6 release notes as a known issue:
EDIT 09/9/2015: Xcode 7.1 Beta release notes hint that this is fixed, but I haven't confirmed it yet.
This is working for me in Xcode 7.1.
Iā€™m using a similar configuration with my own frameworks, but I set a different name when creating it in each platform (MyFramework and MyFramework-watchOS). Don't forget to set a common product name manually (mine is MyFramework on both) in the build settings tab of each framework.

OS X Framework Library not loaded: 'Image not found'

I am trying to create a basic OS X Framework, right now I just have a test framework created: TestMacFramework.framework and I'm trying to import it into a brand new OS X Application project.
I have built the .framework file and imported it into the new project, The framework appears to link okay, and I can reference the public header file I added to the framework build phases section.
However, when I try to run the container Application I get the following Error:
dyld: Library not loaded: /Library/Frameworks/TestMacFramework.framework/Versions/A/TestMacFramework
Referenced from: /Users/samharman/Library/Developer/Xcode/DerivedData/TestMacContainer-dzabuelobzfknafuhmgooqhqrgzl/Build/Products/Debug/TestMacContainer.app/Contents/MacOS/TestMacContainer
Reason: image not found
After a bit of googling I realised I needed to add a Copy Files section to my container application build phases, so I have done this and set it up like so...
However, I am still getting the runtime error. I'm obviously doing something wrong here, but the Apple developer library resource for this references Xcode 2, so isn't very helpful!
What have I missed?
UPDATE:
I can see in the build log that my TestMacFramework.framework is being copied into the .app contents/frameworks directory, but it isn't being installed to the Library/Frameworks directory on the HD
UPDATE 2:
The build links correctly if I manually copy the TestMacFramework.framework into the Library/Frameworks directory
[Xcode 11+]
The only thing to do is to add the framework to the General->Frameworks, Libraries And Embedded Content section in the General tab of your app target.
Make sure you select the 'Embed & Sign' option.
[Xcode v6 -> Xcode v10]
The only thing to do is to add the framework to the Embedded binaries section in the General tab of your app target.
So I managed to get it working, it's quite simple when you have the right instructions. What I was looking for was a 'private' framework which lives in the App bundle rather than being written to the system library folder.
Building The Framework
Add a target to create a Cocoa Framework
Within that targets 'Build Settings' configure the 'Installation Directory' to '#executable_path/../Frameworks'
Build library, and access the .framework from the archive or products directory
Including The Framework
Drag the created .framework file into the Xcode Project, be sure to tick 'Copy Files to Directory'
In the containing applications target, add a new 'Copy File Build Phase'
Set the 'Destination' to 'Frameworks'
Drag in the created .framework
It was quite simple for me, i just added my framework to my embedded binaries under app targets
The options above where not possible for me to include.
I solved it by specifying the Runpath Search Path
This is on the 'Build Settings' tab.
In the 'Linking' section.
Change 'Runpath Search Paths' into $(inherited) #executable_path/Frameworks
I ran into the same issue but the accepted solution did not work for me. Instead the solution was to modify the framework's install name.
The error in the original post is:
dyld: Library not loaded: /Library/Frameworks/TestMacFramework.framework/Versions/A/TestMacFramework
Referenced from: /Users/samharman/Library/Developer/Xcode/DerivedData/TestMacContainer-dzabuelobzfknafuhmgooqhqrgzl/Build/Products/Debug/TestMacContainer.app/Contents/MacOS/TestMacContainer
Reason: image not found
Note the first path after Library not loaded. The framework is being loaded from an absolute path. This path comes from the framework's install name (sometimes called rpath), which can be examined using:
otool -D MyFramework.framework/MyFramework
When a framework is embedded into an app this path should be relative and of this form: #rpath/MyFramework.framework/MyFramework. If your framework's install name is an absolute path it may not be loaded at runtime and an error similar to the one above will be produced.
The solution is to modify the install name:
install_name_tool -id "#rpath/MyFramework.framework/MyFramework" MyFramework.framework/MyFramework
With this change I no longer get the error
Deleting derived data saved it for me
None of these issues solved this for me. The problem in the end was pretty easy. It looks like its a pretty major Xcode bug which I have logged the problem and fix under Apple bug: 29820370. If you are struggling (as it seems like there are several pages of problems similar to this ) then it would be great if you can raise a bug on bug reporter: https://bugreport.apple.com/ and reference the bug I raised to gain visibility. I want to make Xcode back into the pleasure that it was before - and this is something I am sure Xcode should have fixed itself.
Here is the fix:
1. Open Keychain - go to Apple Worldwide Developer Cert.
2. Double Click on it
3. Change the permission level from "always trust" to use System Defaults
4. Save and close it
5. Restart Xcode, Clean and build your project and it should be gone.
Screenshot below of the correct settings:
Hope this helps!
When you drag a custom framework into a project under Xcode 10.1, it assumes that the framework is a system framework and puts the framework into "Link Binary With Libraries" section of "Build Phases" under your target.
System frameworks are already on the device so it is not copied over to the device and thus cannot execute at runtime so KABOOM (crash in __abort_with_payload, and disinforming error: "Reason: image not found"). This is because the framework code is not copied to the device...
In reality, to have Xcode both link the custom framework and ensure that it is copied along with your code to the iOS device (real or simulator) the custom framework needs to be moved to "Copy Bundle Resources". This ultimately packages the framework along with your code executable to be available on the device together.
To add a custom framework to a project and avoid the Apple crash:
Drag custom framework into your iOS project file list
Click ProjectName in Navigator -> TargetName -> "Build Phases" ->
Link Binary With Libraries disclosure triangle
Drag custom framework out and down to "Copy Bundle Resources" section below (Xcode now moves the framework reference, fixed in Xcode 10)
Run in simulator or device
The custom framework thus gets copied along with your code to your target device and is available at runtime.
[editorial: you would think Xcode would be smart enough to figure out the difference between one of it's system frameworks which need not be copied to the device and a custom framework that is, oh I don't know, in the project root directory hierarchy... šŸ™„]
Xcode 11 :
in Xcode 11 add framework into General->Frameworks, Libraries And Embedded Content
after adding make sure you select Embed & Sign option
There should be a 'Run Script' into 'Build Phases' with this: '/usr/local/bin/carthage copy-frameworks'
On the 'Input Files' of that 'Run Script', you should add the path to your libraries. Like this:
If you accidentally reset your keychain, this can occur due to missing Apple certificates in the keychain. I followed this to solve my problem.
I had the same issue and was able to fix by re-downloading the WWDR (Apple Worldwide Developer Relations Certification Authority).
Download from here: http://developer.apple.com/certificationauthority/AppleWWDRCA.cer
If you are using Xcode 11, ensure that you have the framework added in Frameworks, Libraries, and Embed Content under Target settings - General. Change Embed status from - 'Do not Embed' to 'Embed & Sign'
What solved it for me was changing abstract_target to target for the main target in my Podfile. I had previously set it to abstract_target and this caused the described error. Now it works like a charm
I faced this issue with Xcode 13 betas with the UniformTypeIdentifiers.framework. The app failed to run on iOS versions lower than 13.
The below approach fixed the issue :
Go to the target -> Build Phases -> Link Binary With Libraries -> Add the framework -> Add the status as "Optional"
The above worked perfectly for me! Hope this helps!
For Xcode 8, some stale products will be removed from derived data folder refer to this solution.
Apple: In macOS 10.12 and later, Xcode cleans up stale derived data, precompiled headers, and module caches. (23282174)
The Xcode build system supports stale file removal of some types of build artifacts that were produced in a previous build, but have since been removed from the project.
Base on the author's thought, I found this build log from my case.
Remove stale build products
/bin/rm -rf /Users/usename/Library/Developer/Xcode/DerivedData/myapp-esvvhwwwwngijeemhatmklwzoxnb/Build/Products/Debug-iphonesimulator/myapp.app/Frameworks/AliyunVodPlayerSDK.framework
/bin/rmdir /Users/usename/Library/Developer/Xcode/DerivedData/myapp-esvvhwwwwngijeemhatmklwzoxnb/Build/Products/Debug-iphonesimulator/myapp.app/Frameworks
After creating a new copy file phase and copy the target stale framework to Frameworks destination, the above removal log disappears after rebuilding.
Just clarify my situation and reason, hope it's helpful for someone.
For me this was the solution, after many hours of searching!!
For some reason, well into the development of a Swift 2.3 custom Framework, Xcode 8 had removed the DYLIB_INSTALL_NAME_BASE setting from the project.pbxproj file. A little walk into the Build Settings / Dynamic Library Install Name Base setting back to #rpath fixed it.
(from https://forums.developer.apple.com/thread/4687)
I found that this issue was related only to the code signing and certificates not the code itself. To verify this, create the basic single view app and try to run it without any changes to your device. If you see the same error type this shows your code is fine. Like me you will find that your certificates are invalid. Download all again and fix any expired ones. Then when you get the basic app to not report the error try your app again after exiting Xcode and perhaps restarting your mac for good measure. That finally put this nightmare to an end. Most likely this has nothing to do with your code especially if you get Build Successful message when you try to run it. FYI
Got the issue when trying Xcode 9 beta and going back to Xcode 8. A simple Clean on the target resolved the issue.
I had the same issue for a different reason.
I've created a new configuration to Debug and Release (under PROJECT -> Info tab -> Configuration).
And I had to change my pod frameworks shell script (Pods-"appName"-frameworks.sh , under Targets Support Files) to make it work.
[Xcode 9]
The only thing that worked for me:
Target > Build Phases > [CP] Embed Pods Frameworks
Uncheck "Show environment variables in build log" and "Run script only when installing"
I tried many fixes, but what worked for me was to delete a missing target listed in the build tab of the build scheme. You can get to it by opening the edit window of the current scheme.
Edit: My UI testing target was not working as well, and the solution I found was to delete it and generate it again.
open xcode -> general -> Embedded Binaries -> add QBImagepicker.framework and RSKImageCropper -> clean project
just add QBImagePicker.framework and RSKImageCropper.framework at embedded binaries worked for me
I think there is no fixed way to solve this problem since it might be caused by different reason. I also had this problem last week, I don't know when and exactly what cause this problem, only when I run it on simulator with Xcode or try to install it onto the phone, then it reports such kind of error, But when I run it with react-native run-ios with terminal, there is no problem.
I checked all the ways posted on the internet, like renew certificate, change settings in Xcode (all of ways mentions above), actually all of settings in Xcode were already set as it requested before, none of ways works for me. Until this morning when I delete the pods and reinstall, the error finally gonna after a week. If you are also using cocoapod and then error was just show up without any specific reason, maybe you can try my way.
Check my cocoapods version.
Update it if there is new version available.
Go to your project folder, delete your Podfile.lock , Pods file, project xcworkspace.
Run pod install
I experienced that problem only when running on real device (iPhone SE). On simulator project worked as expected.
I did try all fixes from this very thread and from here.
None of those worked for me.
For me problem was solved after restarting iPhone (sic!).
I did:
clean build folder,
clean derived data,
delete app from device,
reboot device
And it finally works. :)
If every other solution fails don't forget to try it out.
Xcode 11 :
Build Phases -> Embed Frameworks
This might happen with Pod Frameworks.
I was facing the same issue with AnswerBotProvidersSDK.framework and my mistake was, I set Run Script checked for Install builds only in targets build phases.
Incorrect settings:
Correct Settings:
For me for some reason xCode (12.5 up to this moment) decided that my Notification Service Extension Target should not have correct paths to frameworks. I suspect that this is happened after I've updated from xCode 12.1 to 12.5.
So I was getting the same error related to one of my internal frameworks. To fix this problem do the following:
go to Project's General Tab
Select your target (in my case it was Notification Service Extension Target)
Make sure that Framework and Libraries section contains your missing framework. I've left it Embed Without Signing in my NSE Target, but it is also was added with Embed & Sign to my primary app target
Keep your target selected and switch to Build Settings tab
There in a search bar enter LD_RUNPATH_SEARCH_PATHS (make sure that All possible settings will be displayed and not just Basic)
You will see Runpath Search Paths and it was empty for me.
Add 3 following values there:
$(inherited)
#executable_path/Frameworks
#executable_path/../../Frameworks
This is what helped me.

Attempting to recomple an old OS X screensaver in 10.8. Xcode reports Cocoa/Cocoa.h "file not found"

When I compile in Xcode 4.6.1, I am getting an error stating Cocoa/Cocoa.h "file not found"
I have tried troubleshooting this in the past, but ended up not being able to figure out what to do, or if this is even possible. Anyone have any ideas? On what / where I should look? What to do next?
The program I am attempting to compile is a screen saver from http://www.spiderland.org/breve/download.php called breve creatures. It used to work back in the 10.4.x days. Hence me adding a legacy tag to this post. I can provide more details if you need them, I just don't know what is important information at this point.
It's possible your project is not linking against the current version of the Cocoa framework, but is instead linking against the Cocoa framework from a specific SDK version (such as OS X 10.4), which may be missing from your current system.
In Xcode, choose your build target and select Build Phases. Expand "Link Binary with Libraries" and ensure that Cocoa is listed. You may need to remove it and re-add it to this list. When you press the + button to add a framework to link, ensure you are choosing Cocoa from the correct SDK folder. (I don't know what is installed on your system or whether you want to support OS X systems earlier than 10.8.) Add the framework, clean the project, and build again.

Adding OCHamcrest to an IOS Project

The documentation for the project says just add the framework and the linker flags and you are good to go. Hours and hours of wasted time later, I have figured out that that's not true. If you do that, the project does not see the header files. You have to put the framework somewhere were the compiler will find the headers. In my case, that worked when I dropped the framework into /Developer/Library/Frameworks and then told it to recurse in searching that framework directory (do not fiddle around with the headers search directories).
Then the problem I get is that the link fails with the message:
ld: framework not found OCHamcrestIOS
I noticed that the documentation for the project says that it was updated for Xcode 4. I pulled down the binary of the framework after checking out the code and wasting a ton of time unable to build the IOS version of the framework.
The documentation is here.
I also noticed in that documentation that the cocoa instructions tell you to put a copy files phase into the build. I tried that. Didn't change the outcome.
The last time I fell into a sink hole it was because the library was C++ code. Maybe that's still the problem.
Barring a rapid solution here, I am going to go back to using STAsserts, as sickening as that prospect is, this is far, far worse.
Update: reinstalled Xcode. Still doesn't work. There are cheap ways to make this work, like add the header files to the project. Did a blog post about this that brought out a person with the same experience.
I use a number of frameworks in my projects. Some from other people and some are mine. Looking at the documentation I would suggest that the copy phase stuff is not for iOS development. So I would not do that. I downloaded the latest zip from https://github.com/jonreid/OCHamcrest and it appears to contain a ready to go iOS static library. (Not on my mac so I cannot test to confirm).
Anyway, the way I include static libs is to
Select the project (XCode 4).
Select the target I want to add the library to.
Select the Build phases tab.
Expand Link binary with Libraries.
Click the [+] button to add a framework.
Click the [Add Other ...] button and navigate to the directory containing the <lib>.framework directory and select that.
Thats all. The targets search paths will be updated to include the framework directory and the framework will be listed on the left under the project. Expanding it will show the headers.
The problem you mention sound like a couple of things. Firstly the framework not found sounds like the framework has not been included in the target. When you select the framework in the project list on the left, you should be able to see it's Target Membership displayed on the right. Check it's on for the target you are compiling.
Secondly building frameworks is not a trivial task so don't attempt it unless you have the scripts to do it. I say this because building a iOS static framework means compiling for both simulator and devices, combining the compiled lib files into a universal one, and then storing it and the header in a specific directory strucuture.
The downloaded zip from OCHamcrest though, appears to have the correct OCHamcrestiOS.framework in it. So if you store that directory somewhere and link to it using the steps I've outlined above it should work just fine.
So the solution I adopted for now, after much thrashing around, was to include the framework in the project.
Create a group inside the Xcode project called Third Party.
Link it to a folder called thirdparty.
Go to the Add Files in Xcode and pick the framework.
Drag it over to the dependencies.
Run the tests, they pass!
This is maybe preferable anyway because referencing it in /System/Library/Frameworks would present some versioning issues, and this can be setup very quickly. Furthermore, we have a continuous integration server, and having to get in there and sync versions whenever something changes is not so great.
Thanks for checking it out, Derek.

Resources