Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa Touch Framework fails to debug on simulator in embedding project

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!

like image 562
AlBirdie Avatar asked May 15 '15 08:05

AlBirdie


1 Answers

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!

like image 157
AlBirdie Avatar answered Nov 17 '22 16:11

AlBirdie