Creating universal iOS Framework - ios

I have a workspace which has 2 projects: One is a Cocoa touch framework and the other is the app which uses the framework.I have added the framework in the embedded binaries section. When I run the app, it compiles the framework and the app and things are fine. However, I need the framework to compile for all architectures and not just the one it is currently being built for. I have searched for this and the most common solution is to add a run script to enable this functionality. However, every run script I have come across is different from one another, so I am confused what is the script that is ideal for this situation? Also, is it a good idea to create a fat binary for this purpose?
I am using the following script at the moment, that I have added to the build phase of the framework (taken from http://www.insert.io/frameworkios8xcode6/):
set -e
set +u
# Avoid recursively calling this script.
if [[ $SF_MASTER_SCRIPT_RUNNING ]]
then
exit 0
fi
set -u
export SF_MASTER_SCRIPT_RUNNING=1
# Constants
SF_TARGET_NAME=${PROJECT_NAME}
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Take build target
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]
then
SF_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
if [[ "$SF_SDK_PLATFORM" = "iphoneos" ]]
then
echo "Please choose iPhone simulator as the build target."
exit 1
fi
IPHONE_DEVICE_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos
# Build the other (non-simulator) platform
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/arm64" SYMROOT="${SYMROOT}" ARCHS='arm64' VALID_ARCHS='arm64' $ACTION
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/armv7" SYMROOT="${SYMROOT}" ARCHS='armv7 armv7s' VALID_ARCHS='armv7 armv7s' $ACTION
# Copy the framework structure to the universal folder (clean it first)
rm -rf "${UNIVERSAL_OUTPUTFOLDER}"
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework"
# Smash them together to combine all architectures
lipo -create "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/arm64/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/armv7/${PROJECT_NAME}.framework/${PROJECT_NAME}" -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}"
This script requires that the framework be built for iOS Simulator. After building the the .framework in the Products folder in my workspace shows that the framework is in iphoneos folder instead of the Universal folder. Should I drag the .framework from the Universal folder into the Products section in the worksapce?

I don't know about having the framework project and the app project in the same workspace, however you can see my answer here on how I did this. I didn't have to put the framework in embedded binaries. I only had to put in Linked Frameworks and Libraries. I just set up a build script that when I build for a Generic iOS Device, it builds a Fat Framework to my desktop. I can then run the -lipo info command to confirm this is actually a fat framework. From there I put the framework in my Linked Frameworks and Libraries in my app.

What it worked for me was the following complete tutorial:
https://github.com/jverkoey/iOS-Framework
There you can see the benefits of using a Cocoa Touch static Library based Framework over a Static iOS Framework. It really is an open discuss, but I am only telling you my positive experience with it in a production environment.
The important command you have to care about is the lipo one. It's the one who will smash the binaries into a fat one. With that command you can easily check if the result contains the architectures you wanted or not. If not, check first this and then ensure you follow the instructions of the guide above.
Once you create the static library you can run the following command to check the architectures:
lipo -info YourLibrary.framework/YourLibrary
This solutions also allows you to include the framework as a dependent target to your project making your Framework development much easier. For that purpose check this chapter of the guide.

Related

import swift framework in objc project xcode 11.3.1?

I have question about framework.
When I import my customized swift framework in Objc project, I cant init class object and find customized delegate.
And I also have script to combined different framework like this:
Is my script problem?
Or project setting problem?
Xcode 11.3.1
swift 5
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "XXXSDK" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "XXXSDK" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/XXXSDK.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/XXXSDK.framework/Modules/XXXSDK.swiftmodule/."
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/XXXSDK.framework/Modules/XXXSDK.swiftmodule"
fi
# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/XXXSDK.framework/XXXSDK" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/XXXSDK.framework/XXXSDK" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/XXXSDK.framework/XXXSDK"
# Step 5. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/XXXSDK.framework" "${PROJECT_DIR}"
cp -R "${UNIVERSAL_OUTPUTFOLDER}/XXXSDK.framework" "${PROJECT_DIR}/../../XXXSDKDemo"
cp -R "${UNIVERSAL_OUTPUTFOLDER}/XXXSDK.framework" "${PROJECT_DIR}/../../XXXSDKObjcDemo"
# Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"
If you build your framework with xcframeworks, all this configuration mess will be a lot easier. If you can, give it a try. Look at https://github.com/bielikb/xcframeworks
There should not be any problem to consume swift framework in objective c, check if the framework has the correct .h file in it.
If you want to combine multiple framework in one the you can use lipo command from terminal. Please do check the combined framework after lipo and see if there is the header file.
Also try to use the frameworks individually before lipo.

Xcode 10: unable to attach DB error

When updating to Xcode 10, iOS static library target fails to build. Way how I am trying to build it is following:
xcodebuild -target TargetName -configuration Release clean build
With Xcode 9 everything runs smoothly, but when Xcode 10 is used for build, I am getting following error (after clean runs smoothly):
note: Using new build system
note: Planning build
note: Constructing build description Build system information error:
unable to attach DB: error: accessing build database
"/Users/uerceg/random-path/build/XCBuildData/build.db": database is
locked Possibly there are two concurrent builds running in the same
filesystem location.
** BUILD FAILED **
** BUILD FAILED **
The following build commands failed: PhaseScriptExecution
MultiPlatform\ Build
/Users/uerceg/random-path/build/Library.build/Release-iphoneos/LibraryTarget.build/Script-9DE7C9021AE68FA5001556E5.sh
(1 failure)
This probably unrelated, but I noticed that new Xcode 10 build system flags duplicated Copy Bundle Resource Info.plist files as errors, so I did make sure that there're no duplicated entries, but probably this error is not related to this fact.
Does anyone have any idea what might be wrong?
Okay, seems like I managed to solve it. I was having /bin/sh script in Build Phases that was trying to build fat static library. In the script, I had OBJROOT path set like this:
OBJROOT="${OBJROOT}"
Seems like Xcode 10 and new build system changed some paths on the way and this line was the source of the issue. It needs to be adjusted to:
OBJROOT="${OBJROOT}/DependentBuilds"
After that, xcodebuild manages to build this target without issues with new build system introduced in Xcode 10.
I didn't get to this solution by myself, big thanks to Matt Gallagher and his post in here: https://github.com/mattgallagher/CwlSignal/issues/24#issuecomment-396931001
As requested by #TMin in comment, here's how my script looks like:
set -e
# If we're already inside this script then die
if [ -n "$RW_MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then
exit 0
fi
export RW_MULTIPLATFORM_BUILD_IN_PROGRESS=1
RW_FRAMEWORK_NAME=${PROJECT_NAME}
RW_INPUT_STATIC_LIB="lib${PROJECT_NAME}.a"
RW_FRAMEWORK_LOCATION="${BUILT_PRODUCTS_DIR}/static/${RW_FRAMEWORK_NAME}Sdk.framework"
function build_static_library {
echo "1"
echo "${BUILD_DIR}"
# Will rebuild the static library as specified
# build_static_library sdk
xcrun xcodebuild -project "${PROJECT_FILE_PATH}" \
-target "${TARGET_NAME}" \
-configuration "${CONFIGURATION}" \
-sdk "${1}" \
ONLY_ACTIVE_ARCH=NO \
BUILD_DIR="${BUILD_DIR}" \
OBJROOT="${OBJROOT}" \
BUILD_ROOT="${BUILD_ROOT}" \
SYMROOT="${SYMROOT}" $ACTION
}
function make_fat_library {
# Will smash 2 static libs together
# make_fat_library in1 in2 out
xcrun lipo -create "${1}" "${2}" -output "${3}"
}
# 1 - Extract the platform (iphoneos/iphonesimulator) from the SDK name
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]; then
RW_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
# 2 - Extract the version from the SDK
if [[ "$SDK_NAME" =~ ([0-9]+.*$) ]]; then
RW_SDK_VERSION=${BASH_REMATCH[1]}
else
echo "Could not find sdk version from SDK_NAME: $SDK_NAME"
exit 1
fi
# 3 - Determine the other platform
if [ "$RW_SDK_PLATFORM" == "iphoneos" ]; then
RW_OTHER_PLATFORM=iphonesimulator
else
RW_OTHER_PLATFORM=iphoneos
fi
# 4 - Find the build directory
if [[ "$BUILT_PRODUCTS_DIR" =~ (.*)$RW_SDK_PLATFORM$ ]]; then
RW_OTHER_BUILT_PRODUCTS_DIR="${BASH_REMATCH[1]}${RW_OTHER_PLATFORM}"
else
echo "Could not find other platform build directory."
exit 1
fi
# Build the other platform.
build_static_library "${RW_OTHER_PLATFORM}${RW_SDK_VERSION}"
# If we're currently building for iphonesimulator, then need to rebuild
# to ensure that we get both i386 and x86_64
if [ "$RW_SDK_PLATFORM" == "iphonesimulator" ]; then
build_static_library "${SDK_NAME}"
fi
# Join the 2 static libs into 1 and push into the .framework
make_fat_library "${BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}Sdk"
# Ensure that the framework is present in both platform's build directories
cp -a "${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}Sdk" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/static/${RW_FRAMEWORK_NAME}Sdk.framework/Versions/A/${RW_FRAMEWORK_NAME}Sdk"
# Copy the framework to the project directory
ditto "${RW_FRAMEWORK_LOCATION}" "${SRCROOT}/Frameworks/static/${RW_FRAMEWORK_NAME}Sdk.framework"
Problem is in build_static_library method in this line:
OBJROOT="${OBJROOT}" \
Changing that line to:
OBJROOT="${OBJROOT}/DependantBuilds" \
solves the issue for me.
Open XCode File->Project Settings
Build System->Legacy Build System
Configure XCode of version 10.0 project settings can solve the problem.
If you use build script to build submodule's libraries like me.
You also need to disable new build system in your build script explicitly by using -UseModernBuildSystem=NO in your xcodebuild command.
For example:
xcodebuild -configuration "${CONFIGURATION}" -project "${PROJECT_NAME}.xcodeproj" -target "${TARGET_NAME}" -sdk "${OTHER_SDK_TO_BUILD}" ${ACTION} RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" SYMROOT="${SYMROOT}" -UseModernBuildSystem=NO
Deleting the Derived Data worked for me.
See how you can do it: https://programmingwithswift.com/delete-derived-data-xcode/
I have the same issues and try everything from the hints but this error still continues. Sometimes the project is built, next time there is no and error. And the solution that helps me is to edit scheme and switch off Parallelize Build. After that everything works fine.
Use this script it will it is working fine with new build system
# Step 1 search RECURSION and if detected stop "*/
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Step 2. Build Device and Simulator versions
xcodebuild -target logger ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target logger-configuration ${CONFIGURATION} -sdk iphonesimulator -arch i386 -arch x86_64 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 3. Create universal binary file using lipo
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}universal.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a"
# Last touch. copy the header files. Just for convenience
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"
fi
before Xcode 10 build system uses single thread, but in Xcode 10 usees new build system with multiple threads, so every time you run your build Xcode run button this script
xcodebuild -target logger ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}".
will call one more time for build so on, that will create RECURSION
Don't forgot to end you Script With (fi) its end of IF condition
Step 1 is to Detect RECURSION and stop them
If you want to keep the XCode 10 default build system but still running your build outside of the IDE (in a CI machine for instance), just replace your -target parameter for the -scheme parameter in your xcodebuild command like:
xcodebuild -scheme SchemeName -configuration Release clean build
Thanks to this post from 2015 that talks about a very similar problem and it gave me the hint to solve this problem. As the same author says,
I would hazard a guess, that xcodebuild without a scheme goes
wrongly through the "modern build system", giving the mentioned error
Adding a Clean derived data step in my build scripts (before an Xcode build) seems to fix the problem for me.
Not sure if it's related, but my project uses Realm (installed with CocoaPods). This is the GitHub issue that inspired the "fix" -> https://github.com/realm/realm-cocoa/issues/5812.
I encountered this issue when running swift run <your_proj>.
A quick fix can be achieved by deleting the build.db file, along with its sibling files and directories. This may seem trifle, but it worked for me.
I am reposting this because a moderator saw it fit to delete my previous answer.
I encountered the same issues when I upgraded by builds to New Build System because of xcframeworks requirements.
Error: ".....Build/Intermediates.noindex/XCBuildData/build.db": database is locked Possibly there are two concurrent builds running in the same filesystem location."
The build was previously working fine when triggered with xcodebuild( )
None of the above/approved answered worked for me.
What worked for me was a switch from xcodebuild( ) to build_app( ) in my Fastlane script.
Hope this answer helps someone in the future.
For me, I just cleaned my project.
Restarted the IDE & rebuilt the project & it worked like a charm.
It could be because you have in your podfile an incompatible version to make sure open the runner.xcodeproj with xcode and see the version then go and see podfile to make sure it is the same and uncomented if not make them the same.
hope this is helpful.

Undefined symbols for architecture x86_64 using Swagger API:

I am having this error in my Xcode project....So basically what I am doing is creating a static library that uses a Swagger Api that I have installed using CocoaPods. I am able to import the header files and use the header files in the library, but when I put the static library in another Xcode project I receive this error where It says _OBJC_CLASS_$_SWG....", referenced from: objc-class-ref in Sendable.o.... which is basically the class where I am using the Swagger header files.....
Things I have attempted:
1: Delete Derived Data folder, cleaned and rebuilt
2: made sure POD, library, and project using library have the same architectures as well as
3: made sure architecture build active is set to NO for all
4: made sure $(inherited) is in both library and project using library
5: installed pod file again in library
Things I noticed:
1: the library itself does not have POD in the header search path
2: I get the following warnings but ignored them
3: using Pod update gives me error saying GitHub is offline make sure you have internet connection, only removing and installing seem to work successfully.
My guess is that you are building the library for a single architecture - you are building it either for a Generic iOS Device, or some speciffic iOS device. Either way, you will not be able to use the library on a simulator (x86_64 architecture). Vice versa, if you build the library for a simulator, you will not be able to use it on a device.
If you want to use the same build on both devices and simulator, you need to create an universal library using a tool called lipo, either manually or by Build Phase script. Check out this article. Short summary:
Add an Aggregate target to your library project
Add a Run Script Build Phase
Paste this script into it:
# define output folder environment variable
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Step 1. Build Device and Simulator versions
xcodebuild -target ${PROJECT_NAME} ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target ${PROJECT_NAME} -configuration ${CONFIGURATION} -sdk iphonesimulator -arch x86_64 -arch i386 -arch armv7 -arch armv7s -arch arm64 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 2. Create universal binary file using lipo
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a"
echo "Universal library can be found here:"
echo ${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a
# Last touch. copy the header files. Just for convenience
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"
Build your Aggregate target and an universal library will be built

ERROR While Creating Archive : bitcode bundle could not be generated because 'Library Path(filename.o)' was built without full bit code?

I have created library for my Apple watch based on the Ray Wenderlich Tutorial. Steps I fallowed in brief.
Step 1 : I chosen template as Xcode -> File -> New -> watchOS -> Framework & Library -> Watch Static Library
Step 2 : Added files which are needed to make as library.
step 3 : Added header files in the library build in to public files.
step 4 : Run the application
step 5 : I want to create a universal library so I added target as Xcode -> File -> New -> Target -> Other -> Aggregate
step 6 : Added run script for simulator and watch os as
# define output folder environment variable
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
xcodebuild -target RBWatchModelManager ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator -arch x86_64 -arch i386 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
UNIVERSAL_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-universal
mkdir -p "${UNIVERSAL_BUILD_DIR}"
# Step 2. Create universal binary file using lipo
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-watchos/lib${PROJECT_NAME}.a"
# Last touch. copy the header files. Just for convenience
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/include" "${UNIVERSAL_OUTPUTFOLDER}/"
and I tried one more script but tried either one of these two available scripts
# define output folder environment variable
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Step 1. Build Device and Simulator versions
xcodebuild -target RBIWatchModelManager ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target RBIWatchModelManager -configuration ${CONFIGURATION} -sdk iphonesimulator -arch i386 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target RBIWatchModelManager ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk watchos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 2. Create universal binary file using lipo
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-watchos/lib${PROJECT_NAME}.a"
# Last touch. copy the header files. Just for convenience
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"
Using any one of this script i Created Library successfully.
Step 7 : I added this library (Universal folder library and header files (include folder)) to my actual project.
step 8 : selected library in the build phases Link Binary with Libraries
step 9 : Added Header search Path
Step 10 : Run the application. In simulator, and Device its running properly.
But While creating Archive of this project, I'm getting one error as shown in the image below.
Then I searched about this error, I tried the suggestion :
Suggestion I tried :
Changing the bit code. Because of I'm using watchOS there is no bit code option available in build settings while creating library So there is no scope for this solution.
Added -fembed-bitcode for Custom Compiler Flags in build setting of the Library while creating it. But no use. I'm getting the same error.
I thought this error because of particular file name showed in the error log. So I tried of separating those files and I created new library but then I'm getting same error for other files that are used for creating library. So no use..
I tried of enabling and disabling Enable Bitcode Option in Build settings of my original project where i have added this created library, no use at all.
At finally... Is there any other solution available to resolve this error. And One thing from apple i found is
For iOS apps, bitcode is the default, but optional. For watchOS and
tvOS apps, bitcode is required. If you provide bitcode, all apps and
frameworks in the app bundle (all targets in the project) need to
include bitcode.
After you distribute your app using iTunes Connect, you can download the dSYMs file for the build, described in Viewing and
Importing Crashes in the Devices Window.
Help me out ??

Error building custom iOS Framework in Xcode

This is the first time I have ever tried to create a custom iOS Framework. I'm trying to create custom iOS Framework using xCode by following this tutorial. I have gotten all the way to the very last step (Step 12).
Step 12: Build Project with Aggregate scheme
Select Aggregate("UniversaliOS") Scheme
Select iOS device
Build Project (⌘-B)
But the build fails with a Shell Script Invocation Error: Command /bin/sh failed with exit code 1. The error details are:
ditto: can't get real path for source
lipo: can't create temporary output file: /Users/pdl/Library/Developer/Xcode/DerivedData/InnerID-iOS-SDK-dgyjuudeootshidhpzlejhbyqvco/Build/Products/InnerID-iOS-SDK-Bundle.framework/InnerID-iOS-SDK-Bundle.lipo (No such file or directory)
Command /bin/sh failed with exit code 1
I have absolutely no clue as to what to do now. Any suggestions? I can provide the PhaseScriptExecution dump if necessary.
Thank you in advance for your help.
This is the correct shell script to be used (for swift).
CONFIG=Release
# Step 1. Make sure the output directory exists
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIG}-universal
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 2. Build Device and Simulator versions
codebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIG} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIG} -sdk iphonesimulator -arch x86_64 -arch i386 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Step 3. Copy the framework structure to the universal folder. Subsequently copy the files of the swiftmodule (in Modules directory) of -iphonesimulator to the swiftmodule of universal framework directory.
cp -R "${BUILD_DIR}/${CONFIG}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
cp -R "${BUILD_DIR}/${CONFIG}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"
# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIG}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIG}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
If you still have any doubts, you can look at the video tutorial.
You didn't compile your iOSBundle for both(Step 10) and directly attempt to merge both iOS simulator and device(Step 12).
Basically what Step 10 is doing?
Its's just creating Framework for both Simulator and Device, So for some reason your build folder gets empty and your script not able find framework for iOS-Simulator and Device both or any one.
Quick resolution :
Perform Step 10, one more time before Step 12, this will create iOS-simulator Framework and Device Framework both, After that build project for your Aggregate scheme, this will merge both framework.
You can find all three(iOS-Simulaor, Device, Merged) framework at below
/Users/jaym/Library/Developer/Xcode/DerivedData/iOSFramework-doeqysadgntrrlguuvcivuhapnlr/Build/Products/
In your case, /Users/pdl/Library/Developer/Xcode/DerivedData/InnerID-iOS-SDK-dgyjuudeootshidhpzlejhbyqvco/Build/Products/

Resources