Passing dart environment variables in xcodebuild build-for-testing command - ios

I'm trying to run my flutter integration tests on firebase test lab. Therefore I'm using dart environment variables to set my login credentials. To setup the ios test version I need to run the following command:
xcodebuild -workspace Runner.xcworkspace -scheme Runner -config Flutter/Release.xcconfig -derivedDataPath ../build/ios_integ -sdk iphoneos build-for-testing
My question is now how to set the dart environment variables in this command? On the android gradle task it works when I pass the variable as base64 string -Pdart-defines="${BASE64_STRING}". But that doesn't work for me on iOS.

Run flutter build ios in config-only mode passing your dart defines:
flutter build ios --config-only -t integration_test/example_test.dart --debug --dart-define MY_KEY=MY_VALUE
If it succeeds, you should be able to see your dart defines in Flutter/Generated.xcconfig file (encoded in base64):
$ cat ios/Flutter/Generated.xcconfig | grep DART_DEFINES
DART_DEFINES=TVlfS0VZPU1ZX1ZBTFVF
$ printf 'TVlfS0VZPU1ZX1ZBTFVF' | base64 -d
MY_KEY=MY_VALUE
If you do xcodebuild build-for-testing now, the dart defines will be compiled into your app.

Related

using Jenkins for iOS build

I am new to jenkins, I am trying to build my iOS application on simulator via jenkins. I am using this command,
xcrun xcodebuild -project Name.xcodeproj \
-scheme Name \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,OS=15.5,name=iPhone 12' \
CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO \
build
The build is successful but I can't see the application built on my simulator. And How can I build the same app on real device via jenkins?
The command that you are running will build the application FOR the simulator (this usually means that it will build the application for the 64-bit architecture).
That doesn't mean that it will actually copy/install the application to the simulator for you, its literally just building the application with that architecture so that it is compatible with the simulator.
To build for device, replace your destination with -destination generic/platform=iOS you would also need code signing

create UI Test in Xcode 8 via terminal

Is there a way to actually create UI Tests in Xcode8 via the terminal? I am aware that UI Tests are usually created via Xcode itself but i would like to do it via the terminal and automate the whole process. Thanks!
you can use xcodebuild command to run the test in Xcode.
like:
xcodebuild -workspace ${WORKSPACE_NAME} \
-scheme ${SCHEME_NAME} \
-destination "${DESTINATION}" \
-derivedDataPath "${OUT_PATH}" \
test
do not forget to set the scheme shared.

Build and run an app on simulator using xcodebuild

I have the following goal to achieve: build and run an .app application using xcodebuild and ios-sim.
I'm using the following script to build the application.
xcrun xcodebuild \
-scheme $XCODE_SCHEME \
-project $XCODE_PROJECT \
-configuration Debug \
-destination generic/platform=iOS \
-derivedDataPath \
build
Then for running it, I'm using
ios-sim launch MyApp.app/ --devicetypeid "iPhone-6-Plus, 9.1"
Each time I receive the following message:
Program specified by service does not contain one of the requested
architectures: ?
What is happening, that the app doesn't run?
Note: if I run the second command (ios-sim...) against the .app built from Xcode (the one contained in derived data) the procedure works fine.
Ok. Figured out the issue.
You need to specify the correct destination. For example.
xcrun xcodebuild \
-scheme $XCODE_SCHEME \
-project $XCODE_PROJECT \
-configuration Debug \
-destination 'platform=iOS Simulator,name=iPhone 6 Plus,OS=9.1' \
-derivedDataPath \
build
In this way Xcode will create the folder (called build) containing your products (in particular look at Debug-iphonesimulator). The build dir is created within the dir you are running the xcodebuild command.
Now you can point that folder in order to run the ios-sim command (see ios-sim for more references) or simctl (see iOS 8: Building custom simulators and Build And Run iOS Apps In Commmand Line for more info).

Unable to auto detect APP_BUNDLE_PATH for Calabash + Jenkins

I have integrated iOS project with Jenkins. To run the automation test cases I am using the below code in shell script.
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer/
export CODESIGN_ALLOCATE=`xcode-select -print-path`/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
xcodebuild -alltargets clean
xcodebuild -alltargets
xcodebuild -sdk iphonesimulator \
-project Myapp.xcodeProj \
-scheme Myapp-cal \
ONLY_ACTIVE_ARCH=NO \
CONFIGURATION_BUILD_DIR="$WORKSPACE/build" \
clean build
cucumber
The automation testing is working fine in xcode where as with Jenkins getting the below error.
Unable to auto detect APP_BUNDLE_PATH. Have you built your app for
simulator? Searched dir:
/Users/test/Library/Developer/Xcode/DerivedData/Myapp-fayplezntrxmdqeteknsfkkvtzla/Build/Products
Please build your app from Xcode You should build the -cal target.
Help appreciated
I believe all you need to do is export your APP_BUNDLE_PATH in your script before you call cucumber.
Something like this:
export APP_BUNDLE_PATH="${WORKSPACE}/build/Build/Products/Debug-iphonesimulator/Myapp-cal.app"
cucumber
To see an example of this in the wild see the briar-ios-example repo. [1]
FYI/BTW APP and APP_BUNDLE_PATH are interchangeable. [2]
[1] https://github.com/jmoody/briar-ios-example/blob/master/Briar/jenkins-calabash.sh
[2] http://calabashapi.xamarin.com/ios/file.ENVIRONMENT_VARIABLES.html
Deleting the contents of /Library/Developer/Xcode/DerivedData and compiling again solved this problem for me. I did not wanted to hardcode the APP_BUNDLE_PATH as I have multiple targets.
My error message was Unable to auto detect APP_BUNDLE_PATH.

Build/run iOS Xcode project from Terminal

I want to build a Xcode project from Terminal and then run it as required, also from Terminal.
I have been looking for a way to do this for a while now but only managed to find a method which works for the iPhone Simulator, not for the actual device it self.
Is this even possible? The reason I want to a Xcode project on a device from Terminal is because the application runs a series of automated tests and I would prefer to automate this process using a bash script.
Thanks
To build your xcode project from the command line using a bash script use:
/usr/bin/xcodebuild -target TargetYouWantToBuild -configuration Debug
Look at the man page for xcodebuild for more options.
We do this for our unit test suite target, and we use GHUnit.
This is the section of our build script for running the tests:
export GHUNIT_CLI=1
export WRITE_JUNIT_XML=1
clean
echo "Building Bamboo GHUnit Tests..."
OUTPUT=`/usr/bin/xcodebuild -target BambooAutomatedUnitTest -configuration Debug -sdk iphonesimulator4.3 build`
RESULT=`echo "$OUTPUT" | grep "\\*\\* BUILD "`
if [ "$RESULT" != "** BUILD SUCCEEDED **" ]
then
echo "$OUTPUT"
exit 1
fi
echo "${RESULT}\n"

Resources