The executable 'the.app' is not a Position Independent Executable. Please ensure that your build settings are configure

昨天2013-07-17上傳後收到蘋果的一封信,重點如下: 

The executable 'ott.app' is not a Position Independent Executable. Please ensure that your build settings are configured to create PIE executables.

在網上找了一下,有些解法,但不完全,試了多次,最終把問題解了,解法如下:

首先,我用Xcode4.6.2。

(A)先講答案:

  1. 在Xcode中打開organizer,找到「the.app」的archive"the",右鍵點archive"the",點Show in Finder,出現"the.xcarchive",右鍵點"the.xcarchive",點"打開套件的應用程式/終端機",在終端機畫面中:
  2. 鍵入"ls"(表示顯示資料夾內容),會看到有個"Products",這也是個資料夾,鍵入"cd Products"(注意大小寫)
  3. 鍵入"ls"(表示顯示資料夾內容),會看到有個"Applications",這也是個資料夾,鍵入"cd Applications"(注意大小寫)
  4. 鍵入"ls"(表示顯示資料夾內容),會看到有個"the.app",這也是個資料夾,鍵入"cd the.app"(注意大小寫)
  5. 鍵入"ls"(表示顯示資料夾內容),會看到有個"the"(在最後),鍵入"otool -vh the"(注意大小寫)

the:

Mach header

magic         cputype   cpusubtype  caps    filetype      ncmds   sizeofcmds      flags

MH_MAGIC       ARM        V7         0x00   EXECUTE    24        2968             NOUNDEFS DYLDLINK TWOLEVEL PIE

 重點是最後一行最右邊的"NOUNDEFS DYLDLINK TWOLEVEL PIE",一定要是這樣才能解決「The executable 'ott.app' is not a Position Independent Executable. Please ensure that your build settings are configured to create PIE executables.」這問題。
PIE

(B) 問題所在:新版Xcode必需要Deployment iOS4.3以上才行,否則蘋果就會通知"not a Position Independent Executable"

Deployment >= 4.3

(C) 作法:在Product/Archive前,

  1. 點PROJECT下的the,點Build Setting,再找到Deployment下的"iOS Deployment Target",點選4.3以上(含4.3)。找到Linking下的"Don't Create Position Independent Executables",點選NO,找到Apple LLVM Compiler 4.2 - Code Generation"下的"Generate Position-Dependent code",點選NO。
    Don't create PIE

    Generate Position-Dependent code

  2. 點TARGET下的the,點Build Setting,再找到Deployment下的"iOS Deployment Target",點選4.3以上(含4.3)。找到Linking下的"Don't Create Position Independent Executables",點選NO,找到Apple LLVM Compiler 4.2 - Code Generation"下的"Generate Position-Dependent code",點選NO。
  3. 現在假如你在Project/the/info中已做好Distribution,點Product/Scheme/Edit Scheme/Run/Info,將Build Configuration改選為Distribution,Debugger改為GDB,點OK。

    Product/Scheme/Edit Scheme/Run/Info

  4. 點PROJECT下的the,點Build Setting,再找到Architectures,確認Build Active Architecture Only下的Debug為No,Distribution為Yes,Release為No。
    iOS Deployment Target
  5. 點TARGET下的the,點Build Setting,再找到Architectures,確認Build Active Architecture Only下的Debug為No,Distribution為Yes,Release為No。
  6. 確認Xcode4.6.2左上方的Scheme選擇為iOS Device。

Product/Archive後organizer內會自動出現產生的archive,再如(A)檢查此archive,應是OK,此時可開始上app store,先validate,再Distribute。

 ---------------------------------------------------

雖然一切OK,但是如果,你仍有以下warning:

Application failed codesign verification.  The signature was invalid, contains disallowed entitlements, or it was not signed with an iPhone Distribution Certificate. (-19011)

做下列設定可消除該warning:

點Product/Scheme/Edit Scheme/Archive,將Build Configuration改選為Distribution,點OK。

Product/Scheme/Edit Scheme/Archive