Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get version number for Android using Fastlane

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?

like image 208
Elliot Pohath Avatar asked Sep 14 '25 08:09

Elliot Pohath


1 Answers

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",
               }
           ]
       }
)
like image 144
Akif Avatar answered Sep 16 '25 22:09

Akif