"xcodebuild test" keeps breaking my info.plist file - ios

I am trying to test my Unity application on a simulator from command line but when I try to do it, the info.plist file is broken by xcodebuild test.
Here is how I try to do it :
#!/usr/bin/env bash
set -e
xcodebuild \
-project "Tests.ios/Unity-iPhone.xcodeproj" \
-scheme "Unity-iPhone" \
-sdk iphonesimulator \
-derivedDataPath Tests \
-destination "platform=iOS Simulator,name=iPhone 11,OS=13.4" \
test
ENABLE_BITCODE=NO
The error I get is this one :
Testing failed:
Unity-iPhone Tests:
tests.app encountered an error (Failed to install or launch the test runner. (Underlying error: Failed to install the requested application. The bundle identifier of the application could not be determined.))
When I look in the info.plist after the xcodebuild test, there is only two lines :
LastAccessedDate
WorkspacePath
The info.plist was correct before the xcodebuild.
When I try to do it directly from xcode (Product => Test, with the simulator), it succeeds perfectly.
However, when I try to do it directly from xcode after trying to do it with xcodebuild, it fails with the same error than xcodebuild.
Does someone knows how to get rid of this error ?

Related

xcodebuild -create-xcframework - BCSymbolMaps missing - on M1 Xcode 14.0

I use the same bash script for building the XCFramework for at least 2 years and everything worked successfully until the moment I switched my Mac to M1 and my Xcode is 14.0.
The script is pretty standard (see below).
On MacPro M1, Xcode 14.0 I get the following error (the same script works just fine on Xcode 13.1).
error: the path does not point to a valid debug symbols file: /Users/*******/build/Release-iphoneos.xcarchive/BCSymbolMaps/*
Indeed when I look at build/Release-iphoneos.xcarchive folder - the BCSymbolMaps is not there. I verified that the Xcode setting "debug information format" is dwarf with dsym file.
Can someone please help me understand what is this error? and why it started happening on M1, Xcode 14.0 ?
Thank you
See my bash build script below.
# Build the framework for device and for simulator (using
# all needed architectures).
xcodebuild archive -scheme "${TARGET_NAME}" -destination="iOS" -sdk iphonesimulator SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES -archivePath "${SRCROOT}/build/Release-iphonesimulator"
xcodebuild archive -scheme "${TARGET_NAME}" -destination="iOS" -sdk iphoneos SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES -archivePath "${SRCROOT}/build/Release-iphoneos"
ls -l "${SRCROOT}/build/"
# https://developer.apple.com/forums/thread/655768
# First, get all the UUID filepaths for BCSymbolMaps, because these are randomly generated and need to be individually added as the `-debug-symbols` parameter. The dSYM path is always the same so that one is manually added
echo "XCFramework: Generating IPHONE BCSymbolMap paths..."
IPHONE_BCSYMBOLMAP_PATHS=(${SRCROOT}/build/Release-iphoneos.xcarchive/BCSymbolMaps/*)
IPHONE_BCSYMBOLMAP_COMMANDS=""
for path in "${IPHONE_BCSYMBOLMAP_PATHS[#]}"; do
IPHONE_BCSYMBOLMAP_COMMANDS="$IPHONE_BCSYMBOLMAP_COMMANDS -debug-symbols $path "
echo $IPHONE_BCSYMBOLMAP_COMMANDS
done
echo "XCFramework: Generating IPHONE BCSymbolMap paths... --> Done"
# XCFramework with debug symbols - see https://pspdfkit.com/blog/2021/advances-in-xcframeworks/#built-in-support-for-bcsymbolmaps-and-dsyms
xcodebuild -create-xcframework -allow-internal-distribution \
-framework "${SRCROOT}/build/Release-iphoneos.xcarchive/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework" \
-debug-symbols "${SRCROOT}/build/Release-iphoneos.xcarchive/dSYMs/${FRAMEWORK_NAME}.framework.dSYM" \
$IPHONE_BCSYMBOLMAP_COMMANDS \
-framework "${SRCROOT}/build/Release-iphonesimulator.xcarchive/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework" \
-debug-symbols "${SRCROOT}/build/Release-iphonesimulator.xcarchive/dSYMs/${FRAMEWORK_NAME}.framework.dSYM" \
-output "${SF_RELEASE_DIR}/${FRAMEWORK_NAME}.xcframework"
bit code is not supported by xcode14 so bcsymbolmaps are no more relevant for xcode14

xcodebuild: error: Failed to build workspace. Reason: A build only device cannot be used to run this target

I'm trying to build and test on device (iPhone) using command line:
xcodebuild \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-destination 'generic/platform=iOS,id=iPhoneUUID' \
clean test
But I'm getting this error:
xcodebuild: error: Failed to build workspace MyApp with scheme MyApp.
Reason: A build only device cannot be used to run this target.
Any of you knows why I'm getting this error?
I'll really appreciate any help.
Cut off the generic part in your -destination value. Else Xcode won't try to build for your device, but for the generic build only device:
xcodebuild \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-destination 'platform=iOS,id=iPhoneUUID' \
clean test

Travis builds failing - Reason: The run destination iPad 2 is not valid for Testing the scheme 'UIKitPlus-Example'

I'm having some trouble with my cocoapods running Travis CI. Everything seems to install correctly, but the xcodebuild script fails
$ set -o pipefail && xcodebuild test -workspace Example/UIKitPlus.xcworkspace -scheme UIKitPlus-Example -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty -c
xcodebuild: error: Failed to build workspace UIKitPlus with scheme UIKitPlus-Example.
Reason: The run destination iPad 2 is not valid for Testing the scheme 'UIKitPlus-Example'.
The command "set -o pipefail && xcodebuild test -workspace Example/UIKitPlus.xcworkspace -scheme UIKitPlus-Example -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty -c" exited with 70.
https://travis-ci.org/JamieREvans/UIKitPlus/builds/54649639
I'm not sure why this is failing, because I can run my tests on the iPad 2 simulator, using that scheme, without any issues.
Is this a Travis issue or is my Travis script wrong?
I've managed to get it build by adding a destination to the xcodebuild command line, e.g. -destination "platform=iOS Simulator,name=iPhone 6"

Not able to run GHUnit test from command line

I am trying to run GHUnitTest cases from command line.
Following all steps from Here
My GHUnitTest target name is GHUnitTests. And I using following script on command line
default:
\# Set default make action here
\# xcodebuild -target GHUnitTests -configuration MyMainTarget -sdk iphonesimulator build
clean:
-rm -rf build/*
test: GHUNIT_CLI=1 xcodebuild -target GHUnitTests -configuration Debug -sdk iphonesimulator build`
Runnig it using $ make test on terminal.
But getting the following error always.
make: * No rule to make target `test'. Stop.>
How to fix it.
Plz help
I think you're probably just running "make test" from the wrong directory.
The first step to getting 'make test' to work is to be in your project directory, next to your Makefile.
Your makefile should look something like this (which I see it does in your example):
https://github.com/gh-unit/gh-unit/blob/master/Project-iOS/Makefile.example
If your project directory is ~/ios/app/MyApp/,
then you should have saved the Makefile to ~/ios/app/MyApp/Makefile
then
cd ~/ios/app/MyApp
then
make test

Xcodebuild's .app crashes immediately? But Xcode's .app runs successfully

I'm using xcodebuild to build and install my app on the simulator (by copying the .app to ~/Library/Application Support/iPhone Simulator/6.1/Applications/UUID/) from the command line. I use:
xcodebuild -target MyApp
-configuration Debug
CPU_ARCHITECTURE=iphonesimulator6.1
install DSTROOT=Products
The .app is produced in /project_root/Products/Applications/MyApp.app However, every time I run the .app on my simulator, it crashes immediately.
I compared the .app that is created from Xcode's Run to xcodebuild's output from above. The two MyApp.apps are pretty much identical, but the MyApp binary inside of MyApp.app differ (the Xcode one is almost twice the memory footprint). I even tried copying the binary from Xcode's MyApp.app to xcodebuild's, and that worked too.
Any ideas why xcodebuild's .app is crashing?
Though there was no explicit "answer" to my question that I can mark as correct, here's my solution just in case anybody else has the same problem. Props to Richard for pointing me in the right direction. I played around with different settings for VALID_ARCHS and set it to "i386" (the simulator's architecture). Additionally, the syntax was wrong for CPU_ARCHITECTURE. xcodebuild uses the -sdk option instead. The following worked for me:
xcodebuild -target MyApp
-configuration Debug
-sdk iphonesimulator6.1
VALID_ARCHS="i386"
install DSTROOT=Products
This is my script that makes .app for simulator :
(Replace "MyApp" with your app name)
XCODE_WORKSPACE=/Users/MacBook/iOS/MyApp.xcworkspace
xcrun xcodebuild \
-scheme MyApp \
-workspace $XCODE_WORKSPACE \
-configuration Debug \
-destination 'platform=iOS Simulator,name=iPhone 8,OS=11.2' \
-derivedDataPath \
build

Resources