When building WebTRC XCFramework for iOS I get "A library with the identifier 'ios-arm64' already exists." - xcode

I'm trying to build an XCFramework for our use of WebRTC and am using an Apple Silicon Mac (Mac Studio). I've downloaded the WebRTC stuff from Google and installed all their tools and used their tools to generate an Xcode project version. I can run Xcode and build a framework library. I've set the "arch" in Xcode to be the $ARCHS_STANDARD plus x86_64 (for simulator use by our developers still using Intel based Macs)
Using the documentation at https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle I create an archive for iOS and one for iOS Simulator
% xcodebuild archive -project all.xcodeproj -scheme framework_objc_signed_bundle -destination "generic/platform=iOS" -archivePath "archives/WebRTC"
% xcodebuild archive -project all.xcodeproj -scheme framework_objc_signed_bundle -destination "generic/platform=iOS Simulator" -archivePath "archives/WebRTC_simulator" ONLY_ACTIVE_ARCH=NO SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
First issue is it doesn't seem to create an X86 version for simulator based on running "% lipo -archs" on the actual binary library in the WebRT_simulator.framework, which only shows "arm64", though I don't know if that is valid.
My question is really this one:
Then when I try and create the XCFramework using
% xcodebuild -create-xcframework -archive archives/WebRTC.xcarchive -framework WebRTC.framework -archive archives/WebRTC_simulator.xcarchive -framework WebRTC.framework -output WebRTC.xcframework
I end up with this: A library with the identifier 'ios-arm64' already exists.
I found a post asking about this result (on the Apple Developer Forums) but unfortunately it linked to another post for an answer and that post no longer exists.
What am I doing wrong and how can I go about creating the WebRTC XCFramework that runs on device, and both architectures simulators?
Following the Apple docs ends up with an error that I don't understand. I've tried various searched on SO and in my search engine of choice but have not gotten anywhere.

Related

Running tests for Swift package using xcodebuild: Error tests must be run on a concrete device

I am trying to run tests for my Swift package (defined by Package.swift) by using xcodebuild:
xcodebuild -scheme "package-name-Package" -configuration "Debug" -sdk "iphonesimulator14.5" -arch "x86_64" test`
Unfortunately, I keep getting this error:
xcodebuild: error: Failed to build workspace package-name with scheme package-name-Package.
Reason: Cannot test target “Target1Tests” on “Any iOS Simulator Device”: Tests must be run on a concrete device
Cannot test target “Target2Tests” on “Any iOS Simulator Device”: Tests must be run on a concrete device
Cannot test target “Target3Tests” on “Any iOS Simulator Device”: Tests must be run on a concrete device
I'm not sure what -sdk to use. I've read the output of xcodebuild -showsdks and chosen appropriately (I need to build/ test for iOS). I've tried iphoneos iphonesimulator, iphoneos15.0, iphonesimulator15.0, iphonesimulator14.5, iphoneos14.5 as the sdk. (both Xcode 12 and Xcode 13 beta, by using xcode-select)
Thanks for the upvote kind stranger, I did manage to figure it out: There are 2 ways.
The main solution is to use -destination instead of -sdk. Okay, 🧠 _dump:
Swift Package inside an Xcode Workspace (WorkspaceName.xcworkspace)
My preferred option: I ended up putting the Swift Package in an Xcode workspace. By this I mean dragging the root directory containing the Swift Package (and also the Workspace) into the Xcode project navigator/ workspace.
The advantage is the Xcode schemes are not generated every time you launch Xcode, but are associated with the workspace instead. This means your modifications are not reset every time you launch Xcode (e.g. adding environment variables).
xcodebuild -workspace ./WorkspaceName.xcworkspace -scheme SchemeName -destination 'platform=iOS Simulator,name=iPhone 12' test
Notes:
If you want to build the project, just set the correct scheme and replace test with build
Here is a list of destinations available on Xcode 13 Beta. An example is: { platform:iOS Simulator, id:FD90A730-A1D5-4BBC-B61A-0324400EE9EA, OS:15.0, name:iPhone 12 }
you can get SchemeName from the Xcode workspace or by running xcodebuild -list
The destination used is platform=iOS Simulator,name=iPhone 12. You can get a list of destinations from xcodebuild -workspace ./WorkspaceName.xcworkspace -scheme SchemeName -showdestinations in a directory that contains an Xcode project, workspace or package.
I got it working by just selecting the platform and name properties, without specifying OS or `ID. This is nice because the CI system might right a different Xcode with different OS, though you might prefer to specify it.
You need to format the destination correctly, xcodebuild prints them out in json, but you should provide them in comma separated with equals signs.
Swift Package without an Xcode Workspace
If you don't have a workspace, you can do:
Run xcodebuild -list
Pick the scheme that makes the most sense (probably the scheme that says your-package-name-is-here-Package)
Run:
xcodebuild -scheme SchemeName -destination 'platform=iOS Simulator,name=iPhone 12' test
Caveat: Actually make sure you don't have a workspace in the same directory. (i.e. one that doesn't contain your Swift Package, because Xcode gets confused.) If it sees a workspace, it won't detect the autogenerated Xcode schemes based on the Package.swift in the current directory.

the ipa created by command-line is smaller than create by xcode6,why?

The command-line script:
xcodebuild
xcodebuild -verbose ARCHS="armv7 arm64" VALID_ARCHS="armv7 armv7s arm64" ONLY_ACTIVE_ARCH=NO DEPLOYMENT_POSTPROCESSING=YES \
-configuration Release PROVISIONING_PROFILE="${profilename}" CODE_SIGN_IDENTITY="${codesign}" \
clean build OBJROOT=${distDir}/Obj.root SYMROOT=${distDir}/Sym.root
# ipa
appname=$(basename ${distDir}/Sym.root/Release-iphoneos/*.app*)
target_name=$(echo $appname | awk -F. '{print $1}')
mkdir -p $project_path/package/Products
xcrun -sdk iphoneos PackageApplication -v "${distDir}/Sym.root/Release-iphoneos/${target_name}.app" -o "$project_path/package/Products/${ipaName}" --embed "${profile}"
And the result is: command-line's ipa is 8M smaller than xcode one, Why?
Sadly, ipa files generated from the command line are not identical to those from the Xcode app.
As you already noted, the command line one has a few missing items.
In addition to Symbols, if your app is written in Swift, there will be a SwiftSupport folder with a few libraries in the ipa generated by the Xcode app but not the command line one. Similarly, if your app includes a Watch App, there will be a missing WatchKitSupport folder.
Some of these missing items will be problematic when it comes to uploading an ipa to iTunes Connect. You will find numerous posts about these issues and the workarounds being adopted - but it all boils down to this issue of command line builds lacking all the required content for app distribution.
Luckily, the new version of xcodebuild within Xcode 7 has a solution to most of these issues but is not yet documented. Here's some details on it if you are interested.

Linking to third party framework with xcodebuild

I have a third party framework (which I have developed) as a sub-project of a command line application in Xcode.
If I build my command-line app in Xcode, it builds the framework, then builds the application, links to the framework.
When I run the built application it correctly looks for framework in the application's current working directory. So:
otool -L my_application
Gives:
#executable_path/MyFramework.framework/Versions/A/MyFramework
However, if I build my application from the command line with xcodebuild, the built application looks in /Library/Frameworks/ for the framework and I get the following runtime error:
dyld: Library not loaded: /Library/Frameworks/MyFramework.framework/Versions/A/MyFramework
Referenced from: /path/to/my_application
Reason: image not found
So, basically xcodebuild seems to be not running the necessary command (install_name_tool -change?) to update the executable's link to #executable_path/..
My xcodebuild command is of the form:
xcodebuild -project path/to/project.xcodeproj -scheme my_scheme -configuration Release CONFIGURATION_BUILD_DIR=`pwd`/project
This is with Xcode 4.6 on OS X 10.8.4

xcrun doesn't embed provisioning profile into ipa

I am writing a build script for my phonegap-ios program. I am experiencing some problems during the code signing process. I use my script to build and code signing the project and generate ipa file. But the ipa failed to install to my iphone via iTunes. And I compared the ipa file which generated by my build script and the ipa file generated from Xcode organizer. The build script doesn't contain embedded.mobileprovision and resourceRules.plist. So anyone can tell me anything wrong with my build script? I have made sure paths are right. I use Xcode 4.6.3 (4H1503) and my Mac OS is 10.8.4. My build script is listed below. Thanks.
xcodebuild -project $PROJECT_NAME.xcodeproj -arch i386 -target $PROJECT_NAME -configuration Release -sdk $SDK clean build VALID_ARCHS="i386" CONFIGURATION_BUILD_DIR="$PROJECT_PATH/build"
codesign -f -v -s "$CODE_SIGN" "$PROJECT_PATH/$APP"
xcrun -log -sdk iphoneos PackageApplication -v "$PROJECT_PATH/$APP" -o "$PROJECT_PATH/build/$PROJECT_NAME.ipa" --embed "$PROFILE"
I had same problem while trying to automate my build of iOS app. Apparently xcrun in order to embed provisioning profile, requires an --sign "iPhone Distribution: ..." option to be specified on command line.

xcodebuild: build Mac OS app

I'd like to do automating for my Mac App project.
My environment is Mac OS 10.8.3; Xcode 4.6.
I use the following command in the terminal:
xcodebuild -project pro.xcodeproj -target MyProject -configuration Debug CODE_SIGN_IDENTITY='Mac Developer: xxxxxx'
It ran well and I could see the MyProject.app was created in the workspace: /build/Debug.
Then I just copied it to the Jenkins configurations, like:
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer/
xcodebuild -project pro.xcodeproj -target MyProject -configuration Debug CODE_SIGN_IDENTITY='Mac Developer: xxxxxx'
However, the build always failed with :
Code Sign error: Provisioning profile 'EADA149E-1A30-4C3C-B42B-75DEA77308DF' can't be found
What makes me strange is that I could not find the "wrong" profile.
I find a same question Distributing .app file after command line xcodebuild call. But the "archive" is invalid in xcode 4.6.
So please help me about how can I do the automating for Mac App.
Thanks!
I find it and it is the same problem like "provison not found".
What you need to do is delete the referred provision file in prom.xcodeproj/project.pbxproj.
You can find the same answers here Codesign error: Provisioning profile cannot be found after deleting expired profile

Resources