Cocoa Touch Framework fails to debug on simulator in embedding project - ios

I've got a Cocoa Touch framework built with XCode 6 targetted towards iOS >= iOS8.
This framework's target architecture settings are default, meaning that I haven't changed anything.
The architectures are set to standard (which doesn't include x86_64, more on that later).
The framework itself contains both Swift and Objective-C code, so building it using the static library workaround from Ray Wenderlich won't work.
Now, if I create a new project and add the framework project to it, the project builds for both the device and simulator, which is fine.
However, if I take the .framework file and add it to a different project just like you'd add any other framework, the project won't build for the simulator. Well, it does build, but it crashes because it can't find the relevant classes. It works fine on the device and archiving works just as expected as well.
The framework project itself already gives me a warning;
"Apple Mach-O Linker Warning - Directory not found for option ....(Debug-ophoneos)".
Any help would be highly appreciated!

I have finally found the solution to this issue.
As it turns out, XCode no longer creates fat binaries out of the box. No idea what Apple's reasoning behind this might be, too me it just seems like sometimes the guys responsible for XCode like to make fun of the developers using their product...
Anyways, you can find the definitive guide as to how to create a fat binary for simulator and all iOS devices (yes, you even have to lipo different architectures in order to get a framework that works on newer and older devices): https://kodmunki.wordpress.com/2015/03/04/cocoa-touch-frameworks-for-ios8-remix/
In short;
Create a Cocoa Touch Framework
Set the Architectures to arm64, armv7, and armv7s
Set "Build Active Architecture" to "NO"
Set "Valid Architectures" to arm64, armv1, and armv7s
Add the following script to the framework's build Scheme as an Archive Post-action;
set -e
DEVICE_BIN="${OBJROOT}/UninstalledProducts/${TARGET_NAME}.framework"
SIMULATOR_BIN="${SYMROOT}/../../../../Products/Debug- iphonesimulator/${TARGET_NAME}.framework"
ARCHIVE_PATH="${SRCROOT}/_Archive"
rm -rf "${ARCHIVE_PATH}"
mkdir "${ARCHIVE_PATH}"
if [ "${CONFIGURATION}" = "Release" ]; then
if [ -d "${DEVICE_BIN}" ]; then
DEVICE_PATH="${ARCHIVE_PATH}/Release"
mkdir "${DEVICE_PATH}"
cp -r "${DEVICE_BIN}" "${DEVICE_PATH}"
fi
if [ -d "${SIMULATOR_BIN}" ]; then
SIMULATOR_PATH="${ARCHIVE_PATH}/Debug"
mkdir "${SIMULATOR_PATH}"
cp -r "${DEVICE_BIN}" "${SIMULATOR_PATH}"
lipo -create "${DEVICE_BIN}/${TARGET_NAME}" "${SIMULATOR_BIN}/${TARGET_NAME}" -output "${SIMULATOR_PATH}/${TARGET_NAME}.framework/${TARGET_NAME}"
fi
fi
exit 0;
This will create an _Archive directory in your project's directory where you can find the frameworks for both debug and release.
Important: As of today (May 22nd 2015) you'll have to build the project with the simulator first, and then archive with a device. Otherwise you won't get a universal binary!
This post has been created in order to avoid dead link errors, for updates regarding the packaging process, please ALWAYS try the steps posted on the kodmunki website I've linked above first as the steps in this post might have been outdated already!

Related

Xcode project giving pod file error for FIRAnalyticsConnector.framework . How to solve it?

I'm working on a book project and the project is connected by API . I'm working on the book app which has different libraries imported from the various places.
Recently, i cloned the project from bitbucket in Xcode and tried to run it. The result i got i error as follows:
enter image description here
It shows :
ld: in /Users/ishinfoservices/Documents/vadltaldhambooks/Pods/FirebaseAnalytics/Frameworks/FIRAnalyticsConnector.framework/FIRAnalyticsConnector(FIRAnalyticsConnector_a8eeba373b74508311b8b22b8d3202a6.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/ishinfoservices/Documents/vadltaldhambooks/Pods/FirebaseAnalytics/Frameworks/FIRAnalyticsConnector.framework/FIRAnalyticsConnector' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Help needed to fix the error, as the project has lots of mixes of old libraries along with .h and .m files, the swift files with wireframes
According to the image I saw that you are trying run the app on the iOS simulator, then you could try to add the arm64 to the Excluded Architectures on the Build Settings section of your project or target, it would be like:
Take in mind that if you use Cocoa Pods is possible that also you should add the arm64 to the Exclude Architectures into the Pods project
After the above, clean, build and run the project on the iOS simulator, is possible that on your physical device you must remove the arm64 from the Exclude Architectures, it could depend on what you use in your project.
On the other hand, you can try the following: Select the project -> Select the target -> Go to the Build Phases -> Expand the Link Binary with libraries and add all pod libraries (remove if they exist in embedded binaries or Remove the old FrameWorks), after that, clean and build the project

Lipo Error while creating Universal frameworks in xcode 12

I am facing problem while making universal frameworks in xcode 12. following is the command that i ran:-
lipo -create build/simulator/FrameworkName.framework/FrameworkName build/devices/FrameworkName.framework/FrameworkName -output build/universal/FrameworkName.framework/FrameworkName
And following is the error that i am facing:-
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: build/simulator/FrameworkName.framework/FrameworkName and build/devices/FrameworkName.framework/FrameworkName have the same architectures (arm64) and can't be in the same fat output file
when i googled this error i found solution to set my 'Architectures', in 'Build Settings', to Standard, however it was already set to standard find the screenshot attached
Note: I was following this tutorial:- https://medium.com/#anuragajwani/how-to-build-universal-ios-frameworks-74b6b07bf31d
The error tells you that both your frameworks in build/simulator and build/device folders have been built for the same architecture (arm64, which is a device architecture). You can verify this by yourself, by looking inside the .framework file: FrameworkName.framework/Modules/FrameworkName.swiftmodule.
It is possible, that one of the folders (or both) contain more than one architecture like this:
Personally, I like to build my 'fat' frameworks outside the Xcode.app folders (just to make sure I have complete control over what is where). First, run your framework for simulator (select any simulator as build target). After the process has completed, go to Products folder in Xcode Navigator, click Show in Finder on FrameworkName.framework file. Copy the shown .framework somewhere more convenient (e.g. Desktop/simulator folder)
Then, build the framework again, only this time for device (select Any iOS device as build target). Copy second .framework somewhere like Desktop/iphone folder.
Create empty Desktop/universal folder for output framework. Copy .framework file there from Desktop/iphone folder and remove Desktop/universal/FrameworkName.framework/Framework executable file. This file will later be replaced by lipo.
Next, do the lipo magic:
lipo -create ~/Desktop/iphone/FrameworkName.framework/FrameworkName ~/Desktop/simulator/FrameworkName.framework/FrameworkName -output ~/Desktop/universal/FrameworkName.framework/FrameworkName
Last step, go to Desktop/simulator/FrameworkName.framework/Modules/FrameworkName.swiftmodule copy all files that start with x86_64 prefix, and paste them to Desktop/universal/FrameworkName.framework/Modules/FrameworkName.swiftmodule. Now your Desktop/universal/FrameworkName.framework contains both device and simulator architectures. Congrats, you've got your 'fat' library!
Disclaimer: Yes, I realise there are easier ways to do this with various scripts and terminal commands, but all of them do pretty much the same thing. Once you try to do this manually step by step, it will help you understand what goes where, and what are architectures and how they can be combined.
Disclaimer 2: Starting from Xcode 12, Apple insists you build .xcframeworks instead of 'fat' libraries. See here

dyld: Library not loaded: #rpath/libswiftAVFoundation.dylib Reason: image not found

I'm getting this error upon launch of my app. I am building under Xcode 9.0 (9A235) on MacOS High Sierra 10.13. I also tried building under Xcode 8.3.3 with the same result. The project is generally Objective C, but the framework YouAppi.framework is Swift:
dyld: Library not loaded: #rpath/libswiftAVFoundation.dylib
Referenced from: /private/var/containers/Bundle/Application/7D3E2815-4CA3-4258-AEF6-C0626055A8F2/dingbats.app/Frameworks/YouAppi.framework/YouAppi
Reason: image not found
At first glance, this appears to be a duplicate of this question, but the error is different in that one. In that other question, the Reason is no suitable image found, where mine is image not found.
I've tried the following to resolve:
Remove and re-add the framework
Clean and Option+Clean the project
Delete ~/Library/Developer/Xcode/DerivedData folder
Build Settings -> Always Embed Swift Standard Libraries = Yes
Build Settings -> Strip Swift Symbols = No
Build Settings -> Linking -> Runpath Search Paths --
added #loader_path
added #rpath
added #executable_path/Frameworks
Checked developer and distribution certificates that Trust was set to Use System Defaults
Checked that I have latest WWDR and G2 certificates installed
Checked validity of above-mentioned certificates
Moved YouAppi.framework into Frameworks/ folder. (It was originally in a "Third-Party Frameworks" folder.)
Tried copying libswiftAVFoundation.dylib into my project's Frameworks folder
I haven't moved to a new computer recently.
I have the same result on my iPhone 7+ running iOS 11.0.23 (15A432) as well as an iPad Mini 1 running iOS 9.3.5 (13G36).
Also tried this:
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData
rm -rf ~/Library/Caches/com.apple.dt.Xcode
Ideas?
When including a framework built with Swift in a non-Swift project, the Swift standard libraries need to be copied into the final output. Xcode has a checkbox for this (#4 in the original question), but apparently there's a bug where, in some cases, it doesn't actually happen.
I saw another thread somewhere that said this happens when you have a framework built with Swift, which is built for multiple architectures, such as armv7 and arm64. (See the thread here.)
In any case, the solution is to add them all manually. The files you are looking for are in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos.
What I did was this:
Step 1. Open Terminal and type this, copying the libraries to a new folder, swiftStdLib, in your home directory.
cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos
mkdir ~/swiftStdLib
cp libswift*.dylib ~/swiftStdLib
Step 2. Within Xcode, go to General -> Embedded Binaries, and hit the + to add. Click Add Other, then navigate to your home folder/swiftStdLib. Select all and hit enter.
Step 3. Clean and build the project.
Hope this helps someone.
UPDATE FOR XCODE 11:
In Xcode 11.3, the Swift libraries folder has changed to include the major Swift version number. The original question was based on Xcode 9, so this probably changed earlier than Xcode 11.3, but I haven't checked.
The new folder is /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/iphoneos.
So that makes Step 1, above, this instead:
cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/iphoneos
mkdir ~/swiftStdLib
cp libswift*.dylib ~/swiftStdLib
Before adding frameworks try this:
I deleted derived data in xcode9 - it works for me
refer link below: How to delete contents from derived data
How can I delete derived data in Xcode 9?
Deleting old developer certificates from Keychain Access helped for me.
Just cleaning the project sometimes seems to work for me. I have noticed this happen more frequently when I have a swfit/objc/c++ project combination.
Simple step to follow
Project -> Build Phases -> Embed Frameworks -> +.
It will works for all.. Perfect solution for everyone.
Add library in Link Binary with Libraries &
Add new Copy Files Phrase, Select framework in destination section and import library there.
And Run your code.. Magic.. Enjoy
NOTE:-Please make sure "Copy only when installing" in Copy files is unchecked

Failed to verify bitcode while exporting archive for ad hoc distribution - tried Xcode 8.3.3 & Xcode 9

Apps containing our framework complains about missing bitcode while exporting archive for Ad-hoc distribution.
I have gone through the documentation provided by Apple in this regard
Technical Note TN2432. The documentations' listed possible root causes do not resemble our scenario. (We are not using assembly instructions or have malformed info.plist file)
I have gone through following similar questions posted on SO
Error while exporting with Bitcode enabled (symbol not found for architecture armv7)
Is it possible to create a universal iOS framework using bitcode?
New warnings in iOS 9
But the provided solutions do not seem to work.
I have tried adding BITCODE_GENERATION_MODE flag in User-Defined build settings. I also tried adding -fembed-bitcode-marker & -fembed-bitcode in Other C flags in framework target.
I check if bitcode segments are present in my generated framework using the suggested command
otool -l -arch arm64 <framework_name> | grep __LLVM
It shows 2 segments
segname __LLVM
segname __LLVM
But while exporting the archive, Xcode still complains about absent bitcode.
I tried to upload app on App store to verify if this issue is due to Xcode versions (I tried 8.3.3. and 9.0), but I get following email about build import error from iTunes Store.
While processing your iOS app, APP_NAME 1.0(4), errors occurred in the app thinning process, and your app couldn’t be thinned. If your app contains bitcode, bitcode processing may have failed. Because of these errors, this build of your app will not be able to be submitted for review or placed on the App Store. For information that may help resolve this issue, see Tech Note 2432.
PS: Disabling bitcode is not an option for us as host app need to support bitcode.
The error description took me in the wrong direction to find the solution.
This error is not related to bitcode.
It appeared when the framework contained simulator slices (i386 x86_64)
Removing them before archiving resolved the issue.
Adding a run script phase to build phases of the target with following code helped in getting rid of the error.
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[#]}"
rm "${EXTRACTED_ARCHS[#]}"
echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
done
Credits: http://ikennd.ac/blog/2015/02/stripping-unwanted-architectures-from-dynamic-libraries-in-xcode/
If you don't know how to add a run script phase to your Xcode project, because maybe you're building a project with Cordova or Ionic and you never were taught much about Xcode, here's how you do that:
Open your project in Xcode.
Make sure you're looking at your project in the "Project Navigator" by clicking on the left-most icon in the left pane of Xcode (the one that says "show Project Navigator" when you point at it.
Click on your project at the top of the navigator window, so that it is selected as your target
At that point, in the middle portion of the Xcode window, you'll see several things appear near the top. General, Capabilities, Resource Tags, Info, among others. One of them is Build Phases -- click on it.
Click the + that's near the top-left of the middle portion of the Xcode Window. It will say Add New Build Phase if you point at it long enough.
Select "New Run Script Phase" from the menu that popped up when you clicked on the +
Click on the arrow next to the Run Script that just appeared.
Copy and paste the above script into the appropriate area just below the word "Shell". You shouldn't have to change anything else.
Build/Archive your project like normal, only now you won't get those annoying "failed to verify bitcode" errors. :-)
I had to set Enable Bitcode to 'NO' in Build Settings
Try the following:
Make sure this framework is added under Copy Frameworks Script in Build Phases.
Use BITCODE_GENERATION_MODE instead of BITCODE_GENERATION_CODE
I was facing the same issue. But in my case, I found out after one day of struggle that my system was running out of memory. As soon as I created some space in the system all worked fine.

ERROR ITMS-90085: “No architectures in the binary. Lipo failed to detect any architectures in the bundle executable.”

We have built a Xamarin app (iOS, Android) with several native bindings. The app runs fine on device and simulator and we are able to build an archive without any issues (apparently).
The issue is when we want to upload the build to the app store (using the app loader or xcode 7.3.1), we get the following error:
ERROR ITMS-90085: “No architectures in the binary. Lipo failed to detect any architectures in the bundle executable.”
Running lipo -info on the app yields the following response :
Architectures in the fat file: NameOfMyApp.iOS.app/NameOfMyApp.iOS are: armv7 arm64
We have searched for an answer thoroughly before posting this question and have made sure of the following:
The product name is correct
Xcode is installed
Application loader is the latest version
Bundle Id is correct
If anyone has an idea the help would be greatly appreciated!
Thanks,
A.
I recently ran into this error for a totally different reason. We were using this really popular script to remove unused architectures from our app before app store submission.
The problem is that this script does the totally wrong thing if you include a watch app and are building with Xcode 10! It looks for all architectures in the ARCHS variable and removes all other architectures from fat binaries, the problem is
ARCHS doesn't include watch architectures, and
starting in Xcode 10, watch binaries are fat (due to the new watch)
In XCode 9 the script would skip over watch stuff, but now it wrongly strips them.
I fixed the error by changing the script to instead only remove simulator architectures.
EXTRACTED_ARCHS=()
GOOD_ARCHS=()
PRESENT_ARCHS=($(lipo -archs "$FRAMEWORK_EXECUTABLE_PATH"))
if [[ "${#PRESENT_ARCHS[#]}" -lt 2 ]]
then
echo "Framework is not a Fat binary, skipping..."
continue
fi
for ARCH in "${PRESENT_ARCHS[#]}"
do
if [[ "$ARCH" != x86_64 && "$ARCH" != i386 ]]
then
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
GOOD_ARCHS+=("$ARCH")
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
fi
done
So it turns out that we were doing some native bindings in our project.
In one of these bindings we included a framework at the root of the project, the framework being a folder that includes sub-folders that contain the lib.a.
It turns out that at compilation time the whole framework folder structure was being copied into the resulting IPA and this was causing the issue.
The solution was to simply extract the lib.a and move it to the root of the project and delete the framework folder.
The resulting IPA no longer had the framework folder and the submission went through without a glitch.
May sometimes this error occurs when you in hurry and forgot to change Build Environment to Generic iOS Device for Archiving !
Find image here!
In my case the error was a bit misleading. It had nothing to do with architectures, it just wasn't finding the binary itself.
I'm generating an app extension through CMake, using add_library. CMake renames the extension's executable from MyExtension to libMyExtension.so.
Since "CFBundleExecutable must match the name of the bundle directory minus its extension.", I had to tweak my CMakeLists.txt file to prevent that the extension's executable is renamed:
set_target_properties(${APPEX_NAME} PROPERTIES
XCODE_ATTRIBUTE_EXECUTABLE_SUFFIX ""
XCODE_ATTRIBUTE_EXECUTABLE_PREFIX ""
)
In my case,
turn "Embed & Sign" to "Do not embedded" of each framework.
Then restart Xcode. No need to use pod update or pod disintegrate.

Resources