首页 > 解决方案 > 使用 Fastlane 获取 Android 的版本号

问题描述

我正在使用 Fastlane 为我的 React Native 应用程序自动化我的 iOS 和 Android 版本。效果很好,一旦部署了应用程序,我只是在努力让当前的 Android 版本号传递到 Slack 消息中。以下是我目前的 Android 车道:

lane :deploy_staging do
    gradle(task: "clean")

    puts "CONFIG: #{ENV['CONFIG']}"

    gradle(
        task: 'bundle',
        build_type: 'Release',
        print_command: false,
    )

    upload_to_play_store(track: 'internal')

   slack(
       message: "Test successfully deployed to Play Store",
       success: true,
       slack_url: "https://hooks.slack.com/services/test",
       attachment_properties: {
           fields: [
               {
                   title: "Environment",
                   value: "Staging",
               }
           ]
       }
   )
end

对于 iOS,我运行以下命令来获取版本号:

  {
           title: "Version number",
           value: get_version_number(target:"testapp"),
  }

但是Android似乎没有这个方法调用,有没有一种简单的方法可以让我提取版本号?

标签: androidreact-nativegradlefastlane

解决方案


您可以将版本代码和版本名称设置为局部变量,然后手动将它们传递给您的 gradle 方法。然后在你的松弛方法中使用它们,也是。尝试这样的事情:

versionCode = 100
versionName = "1.0.0"

#...

gradle(
        task: 'bundle',
        build_type: 'Release',
        print_command: false,
        properties: {
              "versionCode" => versionCode,
              "versionName" => versionName,             
            }
      )
#...

slack(
       message: "Test version code: #{versionCode} and version name: #{versionName} successfully deployed to Play Store",
       success: true,
       slack_url: "https://hooks.slack.com/services/test",
       attachment_properties: {
           fields: [
               {
                   title: "Environment",
                   value: "Staging",
               }
           ]
       }
)

推荐阅读