XCBuild shows error while calling fastlane gym - ios

I have an app with multiple targets and try to configure fastlane's gym. Also, we use pretty extensively compiler flags in the app.
I get this error FIXME: Implement XCBuild support for macros in overriding parameters with condition sets: DEVELOPMENT_TEAM[config=Release] = ***.
The error appears after gym executes this xcodebuild command:
set -o pipefail && xcodebuild -workspace Workspace.xcworkspace -scheme Scheme -xcconfig Config.xcconfig -sdk 'iphoneos14.5' -destination 'generic/platform=iOS' -archivePath archivePath.xcarchive archive | tee Myapp.log | xcpretty
The app is native, no Ionic or ReactNative or any of that stuff.
Do you have any idea where does come from? Or how I can solve it?
Thanks for the help.

For anybody stumbling upon this question, I found the solution in this blog. Quoting from the blogpost:
Example:
CURRENT_PROJECT_VERSION_app = 15.3.9 // Application version number
CURRENT_PROJECT_VERSION_xctest = 1.0.0 // Unit Test version number
CURRENT_PROJECT_VERSION = $(CURRENT_PROJECT_VERSION_$(WRAPPER_EXTENSION))
where in my case WRAPPER_EXTENSION would be CONFIGURATION variable.

Related

Xcode 9 - Xcodebuild error - UI tests not running, Timed out waiting for AX loaded notification

My tests do not start executing, and always timeout every time I try to use an xcodebuild command.
The command that I used is the following:
xcodebuild -workspace App.xcworkspace -scheme 'AppName' -sdk iphonesimulator -configuration 'UI_Automation' CODE_SIGN_STYLE='Manual' CODE_SIGN_IDENTITY='iPhone Developer: John Smith (XXXXXXXX)' PROVISIONING_PROFILE_SPECIFIER='John Smith PP Name' DEVELOPMENT_TEAM='ABC Company Apple DEV' -destination 'platform=iOS Simulator,name=iPhone 8,OS=11.2' -destination-timeout 600 -only-testing:AppUITests clean test
It goes through a process where the app is built, but then the tests do not start executing. As a matter of fact, the Simulator does not even start, and I get the following error.
Testing failed:
Timed out waiting for AX loaded notification If you believe this error represents a bug, please attach the log file at /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/com.apple.dt.XCTest/IDETestRunSession-60333F56-66CA-4C34-8460-3846DCF59C14/AppUITests-F74C4FDD-17EE-44AD-A2BA-DDB1BC0A1D7E/Session-AppUITests-2017-12-28_150211-qwlao1.log
Does anyone know how to fix this? I have been racking my brain around this for the past 2 weeks and can't figure it out.
xcode build command changed since xcode 9. So you have to change your build command.
Follow the mentioned steps:
First build the project. Command for build app is
xcodebuild build-for-testing -workspace "Your.xcworkspace" -scheme "UpgradeAll" -destination "platform=iOS Simulator,name=iPad Air,OS=11.0" -derivedDataPath "All"
Then execute the test command using this.
xcodebuild test-without-building -xctestrun "All/Build/Products/UpgradeAll_iphonesimulator11.0-x86_64.xctestrun" -destination "platform=iOS Simulator,name=iPad Air,OS=11.0" '-only-testing:YourTestbundleName' -derivedDataPath 'build/reports/bundleName' | tee xcodebuild.log | ios-sim start --devicetypeid "iPad-Air, 11.0"
I got this error when trying to run my UI Tests through jenkins. What I did was:
Set up Jenkins as a Launch Agent instead of a daemon. (more info here https://medium.com/#ved.pandey/setting-up-jenkins-on-mac-osx-50d8fe16df9f)
Grant the jenkins user admin privileges under System Preferences -> Users & Groups -> Jenkins user -> 'Allow user to administer this computer'.
Rebooted my Mac Mini and the UI Tests work now.

Xcode 8 and exportPath

Starting with Xcode 8, my TeamCity builds no longer create an Artifact with the proper name. Here is my command line to export archive:
xcodebuild -project "${XCODE_PROJECT}" -exportArchive \
-archivePath "${ARTIFACT_DIR}${ARTIFACT_NAME}.xcarchive" \
-exportPath "${ARTIFACT_DIR}${ARTIFACT_NAME}.ipa" \
-exportOptionsPlist ./export-appstore.plist
If ARTIFACT_DIR and ARTIFACT_NAME result in "/builds/myApp-1.0.1.ipa", for example, xcodebuild will actually create "/builds/myApp-1.0.1.ipa/myApp.ipa".
The "man" documentation for '-exportPath' says "Specifies the destination for the exported product, including the name of the exported file". But clearly it's assuming the file name from the Xcode project and using the entire parameter just for the path.
Is this a known bug that will be fixed, or did they remove functionality with this latest version of Xcode?

Define a preprocessor macro value from a shell script in iOS

We have an app that we want uploaded to a site with a different app id based on the the environment it's being built in. In the project we have a Release preprocessor macro set to MY_CONFIGURATION=$(MY_CONFIGURATION) and we set a default value to 3 in the user-defined settings. In our define where we assign the app id string value based off the macro define, we also have the fallback that if the value is not defined, use the value 1. The problem is when we build off Jenkins, the script assigned value (2) is overwritten by the default value from the user-defined settings (3).
Here's the line we are using in the build.sh file
xcodebuild -scheme ${SCHEME} -sdk ${SDK} -destination generic/platform=iOS CODE_SIGN_IDENTITY="${PROFILE}" MY_CONFIGURATION="${BUILD_ENV}" build
I know the correct value is being placed, as the console output from Jenkins shows the following
10:58:46 + xcodebuild -scheme MGO -sdk iphoneos9.0 -destination generic/platform=iOS 'CODE_SIGN_IDENTITY=X' MY_CONFIGURATION=2 build
10:58:47 Build settings from command line:
10:58:47 CODE_SIGN_IDENTITY = X
10:58:47 MY_CONFIGURATION = 2
10:58:47 SDKROOT = iphoneos9.0
The build uploads to the correct environment, build the #define within the code that sets the app id based on the value set displays the default value set (3) instead of the script value set (2). Any tips or help would be appreciated.
Note: I've also tried
xcodebuild -scheme ${SCHEME} -sdk ${SDK} -destination generic/platform=iOS CODE_SIGN_IDENTITY="${PROFILE}" OTHER_CFLAGS="-DMY_CONFIGURATION="${BUILD_ENV}"" build
I use xctool to build and it works perfect.
I think it works the same way in your situation and you can give it a try. Here's what I do.
xctool -workspace productname.xcworkspace -scheme "$scheme" archive -archivePath $archivePath GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS="MY_CONFIGURATION=2 MY_ANOTHER_CONFIGURATION=1"
What makes it work is GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS.
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS="MY_CONFIGURATION=2 MY_ANOTHER_CONFIGURATION=1"
You can try to append this line above to your command. Make sure the value is a number. I failed when tried to use a string value. And there's another related keyword GCC_PREPROCESSOR_DEFINITIONS in the doc.

xcodebuild command line ignoring GCC_PREPROCESSOR_DEFINITIONS

I'm trying to launch xcodebuild with different preprocessing macros.
I've tried :
xcodebuild -scheme myscheme \
-configuration "Archive" \
-sdk "iphoneos5.1"
archive \
CONFIGURATION_BUILD_DIR=../build \
GCC_PREPROCESSOR_DEFINITIONS=ADHOC
but i got a compilation error due to the fact the preprocessor was not used:
I couldn't see it with the -D flag of the compilation command
But it is displayed at the beginning of the script
Build settings from command line:
CONFIGURATION_BUILD_DIR = ../build
GCC_PREPROCESSOR_DEFINITIONS = ADHOC
SDKROOT = iphoneos5.1
The code at the origin of the compilation error is:
#ifdef ADHOC
NSUInteger toto = 0;
#endif
but i get a use of undeclared identifier error for toto
ps : if i do define Preprocessor Macros in Xcode, then these values are used, mine are overridden, and archiving is done. But I do want to make several builds based on different preprocessor definitions (which sounds a better idea than creating new build configurations or schemes to me)
I have to use double quote and remove the $value.
I had,
GCC_PREPROCESSOR_DEFINITIONS='$value ${e}',
which did not work, but
GCC_PREPROCESSOR_DEFINITIONS="${e}"
works.
Where, e is variable inside a loop,
environments=("TEST1" "TEST2" "TEST3" "TEST4" "TEST5" "PROD")
for e in "${environments[#]}"
do
....... commands
done
If I use
GCC_PREPROCESSOR_DEFINITIONS='$value ${e}'
Then I have to use like,
GCC_PREPROCESSOR_DEFINITIONS='$value ADHOC=1'
This worked in one of build script.

Find the ${PROJECT_DIR} for an Xcode project

How do I figure out what my absolute ${PROJECT_DIR} path is for my Xcode project? Is there a way to print this in Terminal? How?
Build Settings -> Preprocess Macros
PROJECT_DIR=#\""$PROJECT_DIR"\"
BUILD_ROOT=#\""$(BUILD_ROOT)"\"
Then you can log it directly
NSLog(#"project dir=%#, BUILD_ROOT_=%#", PROJECT_DIR, BUILD_ROOT);
Run this from Terminal
For a project:
xcodebuild -project yourProject.xcodeproj -target yourTarget -showBuildSettings | grep PROJECT_DIR
For a workspace:
xcodebuild -workspace yourWorkspace.xcworkspace -scheme yourScheme -showBuildSettings | grep PROJECT_DIR
As you can see, you can retrieve any other build settings value
Another interesting method is using a Run Script Phase in Build phases:
Then paste this script that will modify a swift file in your project
fileContent="// DO NOT EDIT,
// THIS IS AUTOMATICALLY GENERATED FILE
// params.swift
//
import Foundation
class Params {
static let srcRoot: String = \"${PROJECT_DIR}\"
}"
echo "${SRCROOT}/YourProjectFolderName/params.swift"
echo "$fileContent" > ${SRCROOT}/YourProjectFolderName/params.swift`
Make sure you added Params.swift in you project.

Resources