Version vs build in Xcode Ask Question

Version vs build in Xcode Ask Question

I have an app that I developed with Xcode 3 and recently started editing with Xcode 4. In the target summary I have the iOS application target form with fields: identifier, version, build, devices, and deployment target. The version field is blank and the build field is 3.4.0 (which matches the version of the app from when I was still editing with Xcode 3).

My questions are:

  1. What is the difference between the version and build fields?

  2. Why was the version field blank after I upgraded to Xcode 4?

ベストアンサー1

Apple sort of rearranged/repurposed the fields.

Going forward, if you look on the Info tab for your Application Target, you should use the "Bundle versions string, short" as your Version (e.g., 3.4.0) and "Bundle version" as your Build (e.g., 500 or 1A500). If you don't see them both, you can add them. Those will map to the proper Version and Build textboxes on the Summary tab; they are the same values.

When viewing the Info tab, if you right-click and select Show Raw Keys/Values, you'll see the actual names are CFBundleShortVersionString (Version) and CFBundleVersion (Build).

The Version is usually used how you appear to have been using it with Xcode 3. I'm not sure on what level you're asking about the Version/Build difference, so I'll answer it philosophically.

There are all sorts of schemes, but a popular one is:

{MajorVersion}.{MinorVersion}.{Revision}

  • Major version - Major changes, redesigns, and functionality changes
  • Minor version - Minor improvements, additions to functionality
  • Revision - A patch number for bug-fixes

Then the Build is used separately to indicate the total number of builds for a release or for the entire product lifetime.

Many developers start the Build number at 0, and every time they build they increase the number by one, increasing forever. In my projects, I have a script that automatically increases the build number every time I build. See instructions for that below.

  • Release 1.0.0 might be build 542. It took 542 builds to get to a 1.0.0 release.
  • Release 1.0.1 might be build 578.
  • Release 1.1.0 might be build 694.
  • Release 2.0.0 might be build 949.

Other developers, including Apple, have a Build number comprised of a major version + minor version + number of builds for the release. These are the actual software version numbers, as opposed to the values used for marketing.

Xcodeメニュー > Xcode について に移動すると、バージョン番号とビルド番号が表示されます。 詳細情報...ボタンをクリックすると、さまざまなバージョンが表示されます。詳細情報...ボタンは Xcode 5 で削除されたため、この情報は、Appleメニュー >この Mac について>システムレポート...を開いて表示されるシステム情報アプリのソフトウェア > 開発元セクションからも入手できます。

たとえば、Xcode 4.2 (4C139) です。マーケティング バージョン 4.2 は、ビルド メジャー バージョン 4、ビルド マイナー バージョン C、ビルド番号 139 です。次のリリース (おそらく 4.3) は、ビルド リリース 4D になる可能性があり、ビルド番号は 0 から始まり、そこから増加します。

iPhone シミュレーターのバージョン/ビルド番号は、iPhone、Mac などと同様です。

  • 3.2: (7W367a)
  • 4.0: (8A400)
  • 4.1: (8B117)
  • 4.2: (8C134)
  • 4.3: (8H7)

更新: リクエストに応じて、Xcode でアプリをビルドするたびに実行され、ビルド番号を読み取り、それを増分し、アプリの{App}-Info.plistファイルに書き戻すスクリプトを作成する手順を以下に示します。バージョン/ビルド番号をファイルに書き込む場合は、オプションの追加手順がありますSettings.bundle/Root*.plist

これはハウツー記事の延長ですここ

Xcode 4.2 - 5.0の場合:

  1. Xcode プロジェクトをロードします。
  2. 左側のペインで、階層の最上部にあるプロジェクトをクリックします。これにより、プロジェクト設定エディターが読み込まれます。
  3. 中央のウィンドウ ペインの左側で、[TARGETS]見出しの下にあるアプリをクリックします。プロジェクト ターゲットごとにこの設定を構成する必要があります。
  4. ビルド フェーズタブを選択します。
    • Xcode 4 では、右下にある「ビルドフェーズを追加」ボタンをクリックし、「実行スクリプトを追加」を選択します。
    • Xcode 5 では、エディターメニュー >ビルド フェーズの追加>実行スクリプト ビルド フェーズの追加 を選択します。
  5. 新しいスクリプト実行フェーズをドラッグ アンド ドロップして、バンドル リソースのコピーフェーズの直前(app-info.plist ファイルがアプリにバンドルされるとき) に移動します。
  6. 新しいスクリプト実行フェーズで、Shell :を設定します/bin/bash
  7. 整数ビルド番号のスクリプト領域に以下をコピーして貼り付けます。

    buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
    buildNumber=$(($buildNumber + 1))
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
    

    @Bdebeezが指摘したように、Apple 汎用バージョン管理ツール( agvtool) も利用できます。代わりにこれを使用したい場合は、まずいくつか変更する必要があります。

    • ビルド設定タブを選択します。
    • [バージョン管理]セクションで、[現在のプロジェクト バージョン]を、使用する初期ビルド番号 (例: 1)に設定します。
    • [ビルド フェーズ]タブに戻り、ビルド番号を含むソース ファイルのビルドと更新の両方を試行するときに競合状態を回避するために、[スクリプトの実行]フェーズを [バンドル リソースのコピー] フェーズの後にドラッグ アンドドロップします。

    この方法では、エラーなしでビルドが失敗/キャンセルされる可能性が定期的に発生する可能性があることに注意してくださいagvtool。このため、agvtoolこのスクリプトでの使用はお勧めしません。

    ただし、スクリプトの実行フェーズでは、次のスクリプトを使用できます。

    "${DEVELOPER_BIN_DIR}/agvtool" next-version -all
    

    引数next-versionはビルド番号 (bumpも同じもののエイリアスです) を増分し、新しいビルド番号で-all更新します。Info.plist

  8. また、バージョンとビルドを表示する設定バンドルがある場合は、スクリプトの最後に次のコードを追加してバージョンとビルドを更新できます。注:PreferenceSpecifiers設定に合わせて値を変更してください。は、plist ファイルの配列PreferenceSpecifiers:2の下のインデックス 2 にある項目を確認することを意味しますPreferenceSpecifiers。つまり、0 から始まるインデックスの場合、それは配列の 3 番目の設定になります。

    productVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFOPLIST_FILE")
    /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:2:DefaultValue $buildNumber" Settings.bundle/Root.plist
    /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:1:DefaultValue $productVersion" Settings.bundle/Root.plist
    

    agvtoolを直接読み取る代わりにを使用している場合はInfo.plist、代わりにスクリプトに以下を追加できます。

    buildNumber=$("${DEVELOPER_BIN_DIR}/agvtool" what-version -terse)
    productVersion=$("${DEVELOPER_BIN_DIR}/agvtool" what-marketing-version -terse1)
    /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:2:DefaultValue $buildNumber" Settings.bundle/Root.plist
    /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:1:DefaultValue $productVersion" Settings.bundle/Root.plist
    
  9. iPad と iPhone 用のユニバーサル アプリをお持ちの場合は、iPhone ファイルの設定も行うことができます。

    /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:2:DefaultValue $buildNumber" Settings.bundle/Root~iphone.plist    
    /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:1:DefaultValue $productVersion" Settings.bundle/Root~iphone.plist
    

おすすめ記事