bitcode-build-tool using wrong sdk on exportArchive

Hello!


I am running xcodebuild on a test app to first archive and then convert it to an .ipa via -exportArchive. All my configurations are working fine, except when I try to generate the bitcode version of it.


This is a Unity app, which means I have to generate the xcode project first via Unity and then run xcode. I have double checked and the project looks fine on my MacBook if I run everything manually - in fact, I can do the export myself - but this is not the case when running it on our Jenkins server.


These are the steps we are doing:



xcodebuild archive -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk -scheme Unity-iPhone -archivePath ../.xcarchive.xcarchive DEVELOPMENT_TEAM=XXXXXXXXXX CODE_SIGN_STYLE=Manual 'CODE_SIGN_IDENTITY=yadda yadda' PROVISIONING_PROFILE=provprofile PRODUCT_BUNDLE_IDENTIFIER=bundleID ENABLE_BITCODE=YES OTHER_LDFLAGS=-ObjC



xcodebuild -exportArchive -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk -archivePath ~/Work/toro-app/.xcarchive.xcarchive -exportPath ~/Work/toro-app/ -exportOptionsPlist ~/Work/toro-app/iOSBuild/ExportOptions.plist



The archive itself works fine, but -exportArchive fails with the following:


Undefined symbols for architecture armv7:

"_OBJC_CLASS_$_UNNotificationRequest", referenced from:

objc-class-ref in 3014.o

"_OBJC_CLASS_$_UNNotificationSound", referenced from:

objc-class-ref in 3014.o

"_OBJC_CLASS_$_UNMutableNotificationContent", referenced from:

objc-class-ref in 3014.o

"_OBJC_CLASS_$_UNCalendarNotificationTrigger", referenced from:

objc-class-ref in 3014.o

"_OBJC_CLASS_$_UNUserNotificationCenter", referenced from:

objc-class-ref in 3014.o

objc-class-ref in 3015.o

objc-class-ref in 3016.o

ld: symbol(s) not found for architecture armv7


The names of the undefined symbols make me think that the UserNotifications framework is not being correctly added (even though it is part of the project). Upon closer inspection of the logs, I found:


2018-06-13 16:56:25 +0000 Validating IPA structure...

2018-06-13 16:56:41 +0000 Compiling bitcode...

2018-06-13 16:56:43 +0000 /Applications/Xcode.app/Contents/Developer/usr/bin/bitcode-build-tool -v -t /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin --sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk -o /var/folders/bf/x1888_rd13b4ppwq55pssbv80000gn/T/ipatool20180613-22643-muq2gs/thinned/armv7/Payload/test.app/test --generate-dsym /var/folders/bf/x1888_rd13b4ppwq55pssbv80000gn/T/ipatool20180613-22643-muq2gs/thinned/armv7/Payload/test.app/test.dSYM --strip-swift-symbols /var/folders/bf/x1888_rd13b4ppwq55pssbv80000gn/T/ipatool20180613-22643-muq2gs/thinned/armv7/Payload/toro.app/toro


Which made me wonder, why is bitcode-build-tool using iPhoneOS9.3.sdk, even when I am passing iPhoneOS11.2.sdk to xcodebuild? I am not entirely sure of what am I doing wrong.


When running it on my mac (xcode version 9.4, instead of 9.2) against my installed iPhoneOS SDK (11.4 instead of 11.2) everything works fine.


Thank you!