Home > other >  Get version number for Android using Fastlane
Get version number for Android using Fastlane

Time:11-10

I'm using Fastlane to automate my iOS and Android releases for my React Native app. It works great I'm just struggling to get the current Android version number to pass into a Slack message once the app has been deployed. Below is my current Android lane:

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

With iOS I run the following to get the version number:

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

But there doesn't seem to be this method call for Android, is there an easy way for me to pull in the version number?

CodePudding user response:

You can set the version code and version name as a local variable and pass them manually to your gradle method. Then use them in your slack method, too. Try something like this:

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",
               }
           ]
       }
)
  • Related