Getting Started With Dynamic Libraries


#1

With the release of Structure SDK (for iOS) 0.10.1 we are no longer shipping a static binary with our Structure.framework. While dynamic frameworks were not allowed prior to iOS 7.0, we’ve realized that any dependency or symbol collision we might have outside of our public API will cause problems as long as we ship with a static binary. So now, our framework is dynamically linked. To use it, please follow these steps:

1. Embed the framework into your app.
Go to your app’s target in Xcode, and then navigate to the “General” tab. From there you will be able to embed the framework by adding it to the “Embedded Libraries” section

2. Strip out the iphonesimulator targets.
Unfortunately, Apple is very strict about what architecture you can ship to the app store. Since our framework contains binaries for both iphoneos (arm64) and iphonesimulator (x86_64), you’ll need to strip out the iphonesimulator targets if you want to ship to the app store. Fortunately you can add a simple script to your build phases to make this work. Make a “run script” phase on your “Build Phases” tab, and add the following script (you can use /bin/sh as the shell):

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

This script is generic and so it should work without any dependencies or changes.

This is the solution that we will be using moving forward, so that some of our dependencies (Eigen3, OpenCV) don’t collide with dependencies that developers are using.

If you have any issues with the dynamic library update, please post your question here or email developers@occipital.com.


Structure SDK (for iOS) 0.10.1: Updates for Apple Submission Compliance, Dynamic Libraries, and More
#2

Need help with this, thanks.

After doing this:

I get this:


#3

Hi OGuler,

Can you try clearing your derived data, and re-building?


#4

This will happen if you have Structure.framwork in the “Embed Framworks” and not in the “Link Binary With Libraries”. It needs to be in both places.


#5

Thanks @n6xej this resolved the issue. :fu:

For everyone else who struggle with this find the screenshots below from my “Build Phases”

Link Binary With Libraries


Embed Frameworks:


#6

Hey any idea how to embed binaries in a Carthage file.??


#7

Not sure what you are asking? Is your Carthage file building a static or dynamic framework?