CocoaPods / Xcodeproj

Create and modify Xcode projects from Ruby.

Home Page:http://rubygems.org/gems/xcodeproj

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] How do I get MARKETING_VERSION or CURRENT_PROJECT_VERSION

AdrianBinDC opened this issue · comments

I've been trying to figure out how to extract APP_STORE_VERSION, MARKETING_VERSION, and CURRENT_PROJECT_VERSION from either the command line or in a Ruby script (fastlane). I'm only able to get APP_STORE_VERSION using xcodeproj.

From terminal, when I type xcodeproj show and I see everything I need in there. I know it's there, I just can't figure out to get a specific value.

My project is configured as follows:

  • My Project
    • Target A
    • Target B
    • Target C

Each target has several configurations pointing at different environments, build flags, etc. (that I didn't set up).

Here's my fastlane script:

  lane :scratchpad do |options|
    project_path = '../myApp.xcodeproj'
    project = Xcodeproj::Project.open(project_path)

    UI.message project.to_s

    # Works for getting the app version
    ['Test_Release [Target A]', 'Test_Release [Target B]', 'Test_Release [Target C]'].each do |config|
      # This works for getting the public version number
      build_settings = project.build_settings(config)
      UI.success "APP_STORE_VERSION: #{build_settings['APP_STORE_VERSION']}\n"
      UI.success "MARKETING_VERSION: #{build_settings['MARKETING_VERSION']}"
      UI.success "CURRENT_PROJECT_VERSION: #{build_settings['CURRENT_PROJECT_VERSION']}\n"
    end
  end

It prints out the correct APP_STORE_VERSION for each target.

However, when I attempt to get the MARKETING_VERSION or CURRENT_PROJECT_VERSION using the following lines, I get empty values...

[22:55:09]: APP_STORE_VERSION: 1.8
[22:55:09]: MARKETING_VERSION: 
[22:55:09]: CURRENT_PROJECT_VERSION: 

[22:55:09]: APP_STORE_VERSION: 3.0
[22:55:09]: MARKETING_VERSION: 
[22:55:09]: CURRENT_PROJECT_VERSION: 

[22:55:09]: APP_STORE_VERSION: 2.2
[22:55:09]: MARKETING_VERSION: 
[22:55:09]: CURRENT_PROJECT_VERSION: 

[22:55:09]: APP_STORE_VERSION: 3.1
[22:55:09]: MARKETING_VERSION: 
[22:55:09]: CURRENT_PROJECT_VERSION: 

What am I missing?

@AdrianBinDC The way these are actually determined is through the Info.plist file. In other words, there is no consistent way to determine those parameters for an arbitrary project.

However, if you can edit the project file to change it, you can decide for yourself that you're gonna keep the MARKETING_VERSION there. After you do this, you will need to edit the Info.plist as follows:

<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>

Same for the project version, which I assume is the name for the bundle version:

<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>

Hope this helps.

@igor-makarov Thank you! It appears there's already a key there for it. I'm encountering the same issue trying to use agvtool. I suspect there's a minor misconfiguration in the project which is generating this issue.

@AdrianBinDC closing the issue then.