# Xcode11 版號問題

* **問題**
  * CFBundleShortVersionString 變成 $(MARKETING\_VERSION)
  * CFBundleVersion 變成 $(CURRENT\_PROJECT\_VERSION)
* **原因**
  * 此為 Xcode11 雷點之一
* **造成影響**
  * 透過 jenkins 部署時，Export 路徑無法正確產生&#x20;
  * 透過 fastlane 上傳 Binary 至 Apple Store 時，版號會變成 $(MARKETING\_VERSION)&#x20;

![](https://1934061725-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4XrCDvjc3xNfiB-3eT%2F-M4Y-TstkTXMD9Y8W9l7%2F-M4Y03bA9UKgihq8WahH%2FExportPath.png?alt=media\&token=3ccf66dd-0dcb-4f9d-883c-bfb197895467)

![](https://1934061725-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4XrCDvjc3xNfiB-3eT%2F-M4Y-TstkTXMD9Y8W9l7%2F-M4Y03b49dRs2qwJb8h2%2FAppleStore_Version.png?alt=media\&token=70f6dcc2-7442-4456-ac96-8ed378b81205)

* **解法**
  * 透過 fastlane 取得正確的值，並回寫到 info.plist

```ruby
version_number = get_version_number(xcodeproj: project+".xcodeproj")
build_number = get_build_number(xcodeproj: project+".xcodeproj")

# 將 version number 和 build number 回寫 info.plist
lane :sync_version_and_build_number_to_info_plist do
    update_plist( 
      plist_path: "path/to/Info.plist",
      block: proc do |plist|
        plist["CFBundleShortVersionString"] = version_number
        plist["CFBundleVersion"] = build_number
      end
    )
end

desc "Firebase App_distribution"
  lane :distribute do |values|

    sync_version_and_build_number_to_info_plist     # 加入此行

    build_ios_app(
        ....do your project configure
    )

end

desc "export archive and ipa"
  lane :export do
  path = "Export/" + version_number + "/" + build_number

    sync_version_and_build_number_to_info_plist     # 加入此行

    gym(
        ....do your project configure
    )

  end
```
