Setting Xcode Build Settings Terminal - xcode

I want to change build settings of a .xcodeproj without using Xcode IDE but through terminal commands (Codesigning Identity and Provisioning Profile to be exact).
I have searched all over but only found commands to build/archive the project from terminal, which I Do Not Want. What I want is to just change the settings, so that when I open the project in Xcode, it has the signing identities and provisioning profile set to what I had set in Terminal.
Xcodebuild command just builds/archives the project using what I pass as parameters, it doesn't set them as values in build settings of project.
Running xcodebuild -target <target-name> -showBuildSettings in terminal, where my project resides, gives me complete build settings of the project but I didn't get any method to set them.
Also I read here about using -setObject, but that also didn't help me as it also builds the code using parameters values I gave instead of actually setting them.
Currently using Xcode 6.3 and Xcode 7.
Any kind of help will be appreciated.

All Xcode settings is actually store in <project-name>.xcodeproj/project.pbxproj .
It looks like
buildSettings = {
CODE_SIGN_ENTITLEMENTS = "";
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
...
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SKIP_INSTALL = YES;
};
Code Signing Identity is controlled by CODE_SIGN_IDENTITY key and Provisioning Profile is controlled by PROVISIONING_PROFILE key.
The project.pbxproj is a text file that can be edited by traditional text processing tools in CLI, such as sed with
sed -ie 's/CODE_SIGN_IDENTITY = "iPhone Developer"/CODE_SIGN_IDENTITY = ""/g' <project-name>.xcodeproj/project.pbxproj
sed -ie 's/PROVISIONING_PROFILE = ""/PROVISIONING_PROFILE = "1c28c979-6bef-4917-aa34-92aecd91315c";/g' <project-name>.xcodeproj/project.pbxproj
You can get the list of available Signing Identities with
security find-identity -v -p codesigning
For PROVISIONING_PROFILE, it's a UUID of provisioning file, it can be fetched with
grep -aA1 UUID /path/to/mobileprovision

Related

Why Xcode can not attach to some programs?

i had to reinstall my MacBook Pro. I have installed the newest macOS & Xcode version so
macOS Monterey 12.0.1 (21A559)
and
Version 13.1 (13A1030d)
I'm programming Audio plugins so to test my plugins I'm normally running a DAW (Digital Audio Workstation) in my case I'm working the most of the time with Ableton or Bitwig.
So if I start the debuging process, I get the follow error:
Could not attach to pid XXXXXX
attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries, when the attach failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)
If I have an eye to the console.app the the following lines:
[LaunchAttach] (3277) about to task_for_pid(2930)
error: [LaunchAttach] MachTask::TaskPortForProcessID
task_for_pid(2930) failed: ::task_for_pid ( target_tport = 0x0203, pid
= 2930, &task ) => err = 0x00000005 ((os/kern) failure)
macOSTaskPolicy: (com.apple.debugserver) may not get the task control
port of (BitwigStudio) (pid: 2930): (BitwigStudio) is hardened,
(BitwigStudio) doesn't have get-task-allow, (com.apple.debugserver) is
a declared debugger(com.apple.debugserver) is not a declared read-only
debugger
1 +0.000000 sec [0ccd/0103]: error: ::task_for_pid ( target_tport =
0x0203, pid = 2930, &task ) => err = 0x00000005 ((os/kern) failure)
err = ::task_for_pid ( target_tport = 0x0203, pid = 2930, &task ) =>
err = 0x00000005 ((os/kern) failure) (0x00000005)
I have done some research and found this:
Stackoverflow link about What does get-task-allow do
get-task-allow, when signed into an application, allows other
processes (like the debugger) to attach to your app. Distribution
profiles require that this value be turned off, while development
profiles require this value to be turned on (otherwise Xcode would
never be able to launch and attach to your app).
So there is nothing I can do to debug my programs with that software. Is that correct? :(
You can debug but you have to set the "Code Signing Inject Base Entitlements" to "Yes" for debugging
And then you have to add a provisioning profile. Go to developer.apple.com then select "Certificates, IDs & Profiles" to create a provisioning profile for the bundle ID you are testing.
This solved it for me on terminal
sudo DevToolsSecurity -enable
When you don't have access to the original source code or don't want to rebuild it, such as when developing plug-ins for another app (a DAW in your case), you can easily change the entitlements of the application as follows to enable debugging:
Read the current entitlements as follows (replace daw.app with the actual app name):
codesign --display --xml --entitlements daw.entitlements daw.app
Note: Run this in the Terminal app. It will create a file named daw.entitlements in the current folder. Run the command only once or delete any previously created daw.entitlements; otherwise the command keeps appending to the same file.
Open daw.entitlements in any text editor and insert the following text just before </dict></plist> at the end of the file:
<key>com.apple.security.get-task-allow</key><true/>
Note: If there’s already an entry with the same name, change its value from false to true instead of adding a new one.
Apply the new entitlements as follows (replace daw.app with the actual app name):
codesign -s - --deep --force --options=runtime --entitlements daw.entitlements daw.app
This should do it. In the unlikely chance that you already have a file named daw.entitlements in the same folder, use a different file name in all steps.
I tried all of these and had no luck until I figured out that I also had to disable SIP (system integrity protection) to attach to the audio server plugin I am working on.
Hopefully this helps someone to not lose a whole day on it as I did.

Automatic appended .xctrunner in my XCUITest bundle id while running on device

After updating to Xcode 11.3, my all test cases stopped working because of the unnecessary text .xctrunner appended with bundle id.
Example- If I am giving bundle id as abc.com then it's showing abc.com.xctrunner at run time.
XCode 11 changed the format for building xcuitest. To run UI test on device create AppId and Profiles for "$YOUR_TEST_BUNDLE_ID.xctrunner".
Set bundle Id for test target without xctrunner like "$YOUR_TEST_BUNDLE_ID"
Here is my Fastlane match config for iOS and Catalyst.
PRODUCT_BUNDLE_IDENTIFIER = com.test
PROVISIONING_PROFILE_SPECIFIER[sdk=*] = match Development com.test.xctrunner
PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*] = match Development com.test.xctrunner catalyst
One Annoying Xcode issues is, Signing & Capabilities for UITest target shows status error. Because profiles don't match but no build error and UI test works just fine. Status error is bit hidden but love to resolve it.

Xcode building application from command line

I'm using this script for building application from command line:
#!/bin/bash
TARGET="signtest"
CONFIGURATION="Debug"
SDK="iphoneos"
IDENTITY="iPhone Developer: Marcin Zyga (CLJR93MXJ6)"
KEYCHAIN="/Users/admin/Library/Keychains/login.keychain"
PASSWORD="admin"
security unlock-keychain -p ${PASSWORD} ${KEYCHAIN}
xcodebuild -target "${TARGET}" -configuration ${CONFIGURATION} -sdk iphoneos CODE_SIGN_IDENTITY="${IDENTITY}" PROVISIONING_PROFILE="94D99766-0268-4E0E-B8D1-053063BB2DA1" OTHER_CODE_SIGN_FLAGS="--keychain ${KEYCHAIN}"
I'm trying to compile application and sign it with my provisioning profile. I'm getting:
Build settings from command line:
CODE_SIGN_IDENTITY = iPhone Developer: Marcin Zyga (CLJR93MXJ6)
OTHER_CODE_SIGN_FLAGS = --keychain /Users/admin/Library/Keychains/login.keychain
PROVISIONING_PROFILE = 94D99766-0268-4E0E-B8D1-053063BB2DA1
SDKROOT = iphoneos5.0
=== BUILD NATIVE TARGET signtest OF PROJECT signtest WITH CONFIGURATION Debug ===
Check dependencies
[BEROR]Code Sign error: The identity 'iPhone Developer: Marcin Zyga (CLJR93MXJ6)' doesn't match any valid certificate/private key pair in the default keychain
** BUILD FAILED **
This is when I'm invoking as sudo su - probably I'm missing a valid configuration in my keychain.
When I'm invoking this build script as admin user I've got this:
Build settings from command line:
CODE_SIGN_IDENTITY = iPhone Developer: Marcin Zyga (CLJR93MXJ6)
OTHER_CODE_SIGN_FLAGS = --keychain /Users/admin/Library/Keychains/login.keychain
PROVISIONING_PROFILE = 94D99766-0268-4E0E-B8D1-053063BB2DA1
SDKROOT = iphoneos5.0
=== BUILD NATIVE TARGET signtest OF PROJECT signtest WITH CONFIGURATION Debug ===
Check dependencies
[BEROR]Code Sign error: Provisioning profile '94D99766-0268-4E0E-B8D1-053063BB2DA1' can't be found
** BUILD FAILED **
My provisioning profile definitly exists.
You've got two problems. The first is there's something in Xcode 4 and later that is changing what I believe is the search path or access rights of the command line build settings, because I, ALSO, am failing with the same codesign [BEROR] when building from command line but not Xcode directly.
I wish I knew the answer to the first problem. I've tried explicitly setting the developer identity, using the generic "iPhone Developer", updating the project settings to have the [sdk-iphoneos*]="", etc., and I have to yet discover the solution.
Did this used to work for you and then you did a Mac OS/Xcode update and now it doesn't? That's my dilemma.
ANYWAY, your second problem is easily fixable: Pass the entire path and filename for the PROVISIONING PROFILE, a-la "/Users/zyga/Library/MobileDevice/ProvisioningProfiles/94D99766-0268-4E0E-B8D1-053063BB2DA1.mobileprovision"
...A

Xcode 3.2.5 fail to create IPA file

I'm trying to create an IPA file for my application using XCode 3.2.5 (iOS SDK 4.0). But after doing the "Build and Archive" I try to "Save to disk..." the ipa file and nothing happens. The message "Generating IPA file" just dissapears.
I took a look into the console of the Mac and I think I found the issue but no idea how to fix it. These what I found on the console:
May 13 15:29:58 Jorge-Martin-Garcias-MacBook-Pro Xcode[246]: Running /usr/bin/xcrun with (\n "-sdk",\n iphoneos,\n PackageApplication,\n "-v",\n "/Users/jgarci17/Library/Application Support/Developer/Shared/Archived Applications/16A09235-185F-4F1E-9BFC-A935CAA5699E.apparchive/mWorkf.app",\n "-o",\n "/var/folders/pD/pDPQGhivGCCVBsrZpH0VaU+++TI/-Tmp-/D6E45F6F-264A-4714-955A-1EC44E78DFC0-246-0000AFED061085C5/mWorkf.ipa",\n "--sign",\n "iPhone Distribution: MyCompany LLC",\n "--embed",\n "/Users/jgarci17/Library/MobileDevice/Provisioning Profiles/48D38306-E65F-4D2B-A60A-B94CCD3D518A.mobileprovision"\n)
That seems to be fine, but later ...
May 13 15:29:58 Jorge-Martin-Garcias-MacBook-Pro [0x0-0x16016].com.apple.Xcode[246]: Arguments: embed=/Users/jgarci17/Library/MobileDevice/Provisioning Profiles/48D38306-E65F-4D2B-A60A-B94CCD3D518A.mobileprovision verbose=1
==>output_dir=/var/folders/pD/pDPQGhivGCCVBsrZpH0VaU+++TI/-Tmp-/D6E45F6F-264A-4714-955A-1EC44E78DFC0-246-0000AFED061085C5/mWorkf.ipa <===
sign=iPhone Distribution: MyCompany LLC
May 13 15:29:58 Jorge-Martin-Garcias-MacBook-Pro [0x0-0x16016].com.apple.Xcode[246]: Output directory: '/var/folders/pD/pDPQGhivGCCVBsrZpH0VaU+++TI/-Tmp-/D6E45F6F-264A-4714-955A-1EC44E78DFC0-246-0000AFED061085C5/mWorkf.ipa
As you see the output directory is including the ipa file name ! ... so later when the zip command wants to run, fails:
zip error: Could not create output file (/var/folders/pD/pDPQGhivGCCVBsrZpH0VaU+++TI/-Tmp-/D6E45F6F-264A-4714-955A-1EC44E78DFC0-246-0000AFED061085C5/mWorkf.ipa/mWorkf.ipa)
When the correct command should have been:
zip error: Could not create output file (/var/folders/pD/pDPQGhivGCCVBsrZpH0VaU+++TI/-Tmp-/D6E45F6F-264A-4714-955A-1EC44E78DFC0-246-0000AFED061085C5/mWorkf.ipa)
Any ideas?
To me it looks like the ipa file is being duplicated when it is being generated. The best thing I could suggest is clearing the archive in the organiser and trying to 'share' the application and re-saving the project.
Also, check all your provisioning profiles are installed in the organiser and the distribution certificate is installed in the keychain because this can also disrupt the exporting of an ipa file.

Command /usr/bin/codesign failed with exit code 1

I am trying to test a app on my phone. I keep getting this error:
Command /usr/bin/codesign failed with exit code 1
I have added the Provisioning profile and went through the set up on the apple iPhone portal.
I have been looking at this for a little over an hour and a half and I still can't figure it out.
Any ideas why this isn't working and why I am getting this error? Thanks!
Edit:
Here's some information on my build:
CodeSign build/Debug-iphoneos/TableView.app
cd "/flashPics_iPhone BACKUP 2:27"
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
setenv _CODESIGN_ALLOCATE_ /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
/usr/bin/codesign -f -s "iPhone Developer: Coulton Vento (LVEE98KDSF)" "--resource-rules=/flashPics_iPhone BACKUP 2:27/build/Debug-iphoneos/TableView.app/ResourceRules.plist" --entitlements "/flashPics_iPhone BACKUP 2:27/build/TableView.build/Debug-iphoneos/TableView.build/TableView.xcent" "/flashPics_iPhone BACKUP 2:27/build/Debug-iphoneos/TableView.app"
/flashPics_iPhone BACKUP 2:27/build/Debug-iphoneos/TableView.app: object file format invalid or unsuitable
Command /usr/bin/codesign failed with exit code 1
This is a good resource in figuring out how to setup the provisioning:
http://mobiforge.com/developing/story/deploying-iphone-apps-real-devices
You must download the provisioning profile, the certificate and make sure your iPhone's UDID is registered on those accounts. Then for the Distribution profile you need to specifically tell it in it's setting to use a Distribution Profile to make it build it.
Edit:
Under Project Settings > Select the Configuration your using (Debug, Release, or Distribution) and make sure under Code Signing your Profile appears there.
I fixed that error. The steps are:
GOTO project
select Edit Project setting
in genatel tab project Format select your current Compatible Xcode version and select based SDK for your currunt iPhone Device; for example (iphone device 4.0) then...
build tab:
configuration : Distribution
Base SDK : choose your latest xcode SDK Device
Code signing identity : choose your provisional portal that you alredy created in iPhone Devloper center and you installed so select that particular provisioning.
Any iPhone OS Device : select same as Code signing identity (as mentioned above)
Then next step is go scrolling at below that find Product Name
Product Name : give Product name exactly same as your prodoct name. That's it.
Follow the same steps in configuration :Debug and Release

Resources