2

I have a third party framework with different versions for simulator and real device.

What I am doing: Right now I maintain two different targets for simulator and device respectively. I need to add the framework to the target as well as to the embedded binaries section. I also have to import the header in the bridging header section as these are objc frameworks ( I have added swift compiler flags for each targets and import the necessary headers in bridging header section). If I add both frameworks in same target, it will give duplicate symbols error.

NB: I Don't have the source code for these frameworks. So I cannot build a universal framework and use.

Question: How can I use these frameworks such that , without changing any code or settings, I should be able to run the code on simulator as well as on a real device?

5
  • 1
    Doesn't the third party provide documentation on how to do this in the best way? Seems to be a rather strange to have one for the simulator and one for devices Commented Feb 14, 2018 at 11:24
  • You can just use two targets (one for simulator and other for device). Commented Feb 14, 2018 at 11:25
  • @rock88 That is what I am doing now. Commented Feb 14, 2018 at 11:29
  • 1
    @Scriptable This is a framework provided by google for video encryption and decryption. They don't provide any documentation. They gave one sample app which uses two different targets for device and sim. Commented Feb 14, 2018 at 11:30
  • @abhi1992 that is more than likely your best solution then. I cannot think of any other way and if Google knew of one they would of used it in the sample project Commented Feb 14, 2018 at 11:31

1 Answer 1

4

I do this using an aggregate build target for the framework that runs a shell script. That script uses xcodebuild to create a framework for both the sim and the device, and then uses lipo to combine them into a single framework that can be included in any project, and work on both platforms. Here's a simplified version:

#!/bin/sh

BASE_BUILD_DIR=${BUILD_DIR}
FRAMEWORK_NAME="FrameworkName"
PROJECT_NAME="Framework"
CONFIG=$CONFIGURATION
UNIVERSAL_OUTPUTFOLDER="Build/${CONFIG}-universal"


# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIG} -sdk iphoneos ONLY_ACTIVE_ARCH=NO  BUILD_DIR="${BASE_BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIG} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BASE_BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build

# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
echo "copying device framework"
cp -R "${BASE_BUILD_DIR}/${CONFIG}-iphoneos/${FRAMEWORK_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"

# Step 3. Copy Swift modules (from iphonesimulator build) to the copied framework directory
echo "integrating sim framework"
cp -R "${BASE_BUILD_DIR}/${CONFIG}-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/"

# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
echo "lipo'ing files"
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${BASE_BUILD_DIR}/${CONFIG}-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${BASE_BUILD_DIR}/${CONFIG}-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"

# Step 5. Convenience step to copy the framework to the project's directory
mkdir -p "${PROJECT_DIR}/iOS Framework/"
rm -rf "${PROJECT_DIR}/iOS Framework/${FRAMEWORK_NAME}.framework"
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework" "${PROJECT_DIR}/iOS Framework"
Sign up to request clarification or add additional context in comments.

2 Comments

This is a framework provided by google for video encryption and decryption. I don't have the source code for this framework. Your script will work only if you have the source code of the framework right?
For this particular solution, yes. However, you can use lipo directly to combine the sim and device frameworks into a single file, and use that (see step 4, above)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.