title: Xcode building application to ipa from command line
body: <p>I'm unable to build ipa signed file from command line. First a few words about my environment:</p>
  
  <p><strong>1. Application</strong>
  I've prepared a simple application for iPad from template "Master-Detail Application". Changed nothing in code, changed nothing in settings. Just plain new project.</p>
  
  <p><strong>2. Build script</strong>
  Here is my build "script"</p>
  
  <pre><code>cd /Users/admin/Desktop/signtest/signtest/
  
  xcodebuild -target signtest -configuration Debug -sdk iphonesimulator4.3 clean build
  
  /usr/bin/xcrun -sdk iphoneos PackageApplication -v /Users/admin/Desktop/signtest/signtest/build/Debug-iphonesimulator/signtest.app -o /Users/admin/Desktop/binaries/signtest.ipa --sign "iPhone Developer: Marcin Zyga (CLJR93MXJ6)" --embed "/Users/admin/Library/MobileDevice/Provisioning\ Profiles/94D99766-0268-4E0E-B8D1-053063BB2DA1.mobileprovision"
  </code></pre>
  
  <p><strong>3. Problem</strong></p>
  
  <p>Application is builded, and then I'm trying to make an ipa file from the build. But I've got this:</p>
  
  <pre><code>** BUILD SUCCEEDED **
  
  Packaging application: '/Users/admin/Desktop/signtest/signtest/build/Debug-iphonesimulator/signtest.app'
  Arguments: embed=/Users/admin/Library/MobileDevice/Provisioning\ Profiles/94D99766-0268-4E0E-B8D1-053063BB2DA1.mobileprovision  verbose=1  output=/Users/admin/Desktop/binaries/signtest.ipa  sign=iPhone Developer: Marcin Zyga (CLJR93MXJ6)  
  Environment variables:
  HOME = /Users/admin
  SUDO_GID = 20
  DISPLAY = /tmp/launch-vj2zx7/org.x:0
  VERSIONER_PERL_PREFER_32_BIT = no
  MAIL = /var/mail/root
  SSH_AUTH_SOCK = /tmp/launch-YPyQMl/Listeners
  PWD = /Users/admin/Desktop/signtest/signtest
  LANG = pl_PL.UTF-8
  USER = root
  LOGNAME = root
  __CF_USER_TEXT_ENCODING = 0x0:29:42
  USERNAME = root
  SHLVL = 1
  OLDPWD = /SMT/ci_shell_scripts
  _ = /usr/bin/xcrun
  PATH = /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
  LSCOLORS = GxFxCxDxBxegedabagaced
  SUDO_USER = admin
  SHELL = /bin/bash
  TERM = xterm-256color
  SUDO_COMMAND = ./sign_test_ipa.sh
  VERSIONER_PERL_VERSION = 5.12
  SUDO_UID = 502
  
  Output directory: '/Users/admin/Desktop/binaries/signtest.ipa'
  Temporary Directory: '/tmp/eiJTk08At3'  (will NOT be deleted on exit when verbose set)
  + /bin/cp -Rp /Users/admin/Desktop/signtest/signtest/build/Debug-iphonesimulator/signtest.app /tmp/eiJTk08At3/Payload
  Program /bin/cp returned 0 : []
  ### Checking original app
  + /usr/bin/codesign --verify -vvvv /Users/admin/Desktop/signtest/signtest/build/Debug-iphonesimulator/signtest.app
  Program /usr/bin/codesign returned 1 : [/Users/admin/Desktop/signtest/signtest/build/Debug-iphonesimulator/signtest.app: object file format unrecognized, invalid, or unsuitable
  ]
  error: Codesign check fails : /Users/admin/Desktop/signtest/signtest/build/Debug-iphonesimulator/signtest.app: object file format unrecognized, invalid, or unsuitable
  </code></pre>
  
  <p>The important part is here:</p>
  
  <pre><code>  Program /usr/bin/codesign returned 1 : [/Users/admin/Desktop/signtest/signtest/build/Debug-iphonesimulator/signtest.app: object file format unrecognized, invalid, or unsuitable
      ]
      error: Codesign check fails : /Users/admin/Desktop/signtest/signtest/build/Debug-iphonesimulator/signtest.app: object file format unrecognized, invalid, or unsuitable
  </code></pre>
  
  <p>I'm unable to find solution.</p>
  
  <p><strong>4. What I've already done</strong>
  Here is a list of what I've already tried to do. However if you are sure that things that I've already tried is solution for my problem please write step by step how to do this (maybe I've done something wrong earlier).</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/7425840/that-codesign-returned-1-object-ifile-format-invalid-or-unsuitable-problem-aga">That codesign returned 1 (object ifile format invalid or unsuitable) problem again</a> - added propsed line of code, no effect at all </li>
  <li><a href="https://stackoverflow.com/questions/7138525/xcode-sharing-app-packageapplication-failed-with-exit-code-1">Xcode - Sharing app - PackageApplication failed with exit code 1</a> - setted in build settings Code Signing Resource Rules Path to $(SDKROOT)/ResourceRules.plist</li>
  <li><p><a href="https://stackoverflow.com/questions/4842717/iphone-codesign-object-file-format-invalid-or-unsuitable">iPhone Codesign object file format invalid or unsuitable</a> - invoke commands</p>
  
  <p>sudo mv /usr/bin/codesign_allocate /usr/bin/codesign_allocate_old
  sudo ln -s /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate /usr/bin</p></li>
  </ul>
  
  <p><strong>5. What I'm trying to achive</strong>
  I'm trying to generate an ipa file signed with developer certificate so I can upload ipa file via iTunes to test it on device.</p>
  
  <p><strong>6. Response to answers from below</strong></p>
  
  <ul>
  <li><p>I've changed the build command line to:</p>
  
  <p>xcodebuild -target signtest -configuration Debug -sdk iphoneos clean build</p></li>
  </ul>
  
  <p>But now I'm getting:</p>
  
  <pre><code>=== 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 **
  </code></pre>
  
  <p>I've manually setted provisioning profiles in xcode for this project. I've double checked and they are there. What I'm a doing wrong here? Moreover when I'm building with attached device it all goes fine and application start on my iPad.</p>