Reputation: 425
I've read several tutorials and guides on how to have Xcode create a universal library. Basically you add an aggregate target with a bash script build phase to build the separate targets and lipo them together.
I have my own small script (which works because of how I named my targets) but for some reason lipo can't find the files;
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't open input file: /Users/username/Projects/project/plugins/build/Release-iphoneos/libproject-plugins.a /Users/username/Projects/project/plugins/build/Release-macos/libproject-plugins.a (No such file or directory)
However when I
lipo
in my script with a simple ls
, the files are there.So I'm not sure what goes wrong, it doesn't seem like xcodebuild
only creates the files after lipo is called (as I first thought).
The script;
targets=$(xcodebuild -list | sed -n '/Targets/,/^$/p' | grep -v -e 'Targets:\|all\|^$')
target_results=""
for target in $targets; do
xcodebuild ${ACTION} -target $target -configuration ${CONFIGURATION}
target_results="$target_results ${PROJECT_DIR}/build/${CONFIGURATION}-$target/libproject-plugins.a"
done
xcrun lipo -create "$target_results" -o "${PROJECT_DIR}/plugins-universal.a"
Upvotes: 3
Views: 1033
Reputation: 21893
Technically this is not an answer to your question. But I would like to recommend that you choose a different option to what you are doing unless you really need to do it.
Building universal static libraries in this fashion is a very old way of doing things and as you are finding out, complicated and quite problematic to get working well.
A more current and much simpler approach (IMHO) is to build a framework. XCode has templates for frameworks. Frameworks are easier to work with and do not require you to do any of the messing around with multiple targets, bash and lipo as you are.
Further, you can then employ Carthage to manage them as dependencies for other projects with very little effort.
Upvotes: -1
Reputation: 23880
This is a bash problem/mistake.
You're passing all the file names as a single argument to lipo
, so it's gonna look for a single file named /Users/username/Projects/project/plugins/build/Release-iphoneos/libproject-plugins.a /Users/username/Projects/project/plugins/build/Release-macos/libproject-plugins.a
.
You should use an array for the file names instead.
()
instead of ""
.+=(...)
instead of ="$var ..."
.lipo
with "${var[@]}"
instead of "$var"
.Applied to your script:
targets=$(xcodebuild -list | sed -n '/Targets/,/^$/p' | grep -v -e 'Targets:\|all\|^$');
target_results=();
for target in $targets; do
xcodebuild ${ACTION} -target $target -configuration ${CONFIGURATION};
target_results+=("${PROJECT_DIR}/build/${CONFIGURATION}-$target/libproject-plugins.a");
done;
xcrun lipo -create "${target_results[@]}" -o "${PROJECT_DIR}/plugins-universal.a";
Upvotes: 0