fastlane: Version overrides do not work on Gradle 7.3+

New Issue Checklist

Issue Description

Version name and version number are not being updated when building using Gradle versions 7.3+. Everything works as expected on 7.2 and earlier.

Command executed

bundle exec fastlane mvde_build_dev

Complete output when running fastlane, including the stack trace and command used
Nothing interesting here, it completes successfully but the version of the APK is just the defaults set in build.gradle, not the overrides set in the Fastfile

Environment

✅ fastlane environment ✅

Stack

Key Value
OS debian_based bullseye/sid
Ruby 2.7.0
Bundler? false
Git git version 2.25.1
Installation Source /usr/local/bin/fastlane
Host Ubuntu 20.04.3 LTS debian_based bullseye/sid (5.10.104-linuxkit)
Ruby Lib Dir /usr/lib
OpenSSL Version OpenSSL 1.1.1f 31 Mar 2020
Is contained false
Is homebrew false
Is installed via Fabric.app false

System Locale

Variable Value
LANG en_US.UTF-8
LC_ALL en_US.UTF-8
LANGUAGE en_US.UTF-8

fastlane files:

`./fastlane/Fastfile`
# frozen_string_literal: true

# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools

import("Egnytefile")

default_platform(:android)

platform :android do
  version_number = "222.0.0" # keep updated
  build_number = ENV['CI_PIPELINE_ID']

  build_properties_dev = {
    "android.injected.version.name" => version_number,
    "android.injected.version.code" => build_number,
    'android.injected.signing.store.file' => 'mvde/config/upload_keystore',
    'android.injected.signing.store.password' => ENV['ANDROID_KEYSTORE_PASS'],
    'android.injected.signing.key.alias' => 'keyalias',
    'android.injected.signing.key.password' => ENV['ANDROID_KEY_PASS']
  }

  # MVDE build
  lane :mvde_build_dev do
    build_android_app(
      task: 'clean :mvde:assemble',
      flavor: 'devStandard',
      build_type: 'Release',
      properties: build_properties_dev,
      flags: "--quiet"
    )
  end
end

No Appfile found

fastlane gems

Gem Version Update-Status
fastlane 2.207.0 ✅ Up-To-Date

Loaded fastlane plugins:

Plugin Version Update-Status
fastlane-plugin-firebase_app_distribution 0.3.4 ✅ Up-To-Date
Loaded gems
Gem Version
did_you_mean 1.4.0
atomos 0.1.3
CFPropertyList 3.0.5
claide 1.0.3
colored2 3.1.2
nanaimo 0.3.0
rexml 3.2.5
xcodeproj 1.21.0
rouge 2.0.7
xcpretty 0.3.0
terminal-notifier 2.0.0
unicode-display_width 1.8.0
terminal-table 1.8.0
plist 3.6.0
public_suffix 4.0.6
addressable 2.8.0
multipart-post 2.0.0
word_wrap 1.0.0
optparse 0.1.1
tty-screen 0.8.1
tty-cursor 0.7.1
tty-spinner 0.9.3
artifactory 3.0.15
babosa 1.0.4
colored 1.2
highline 2.0.3
commander 4.6.0
excon 0.89.0
faraday-em_http 1.0.0
faraday-em_synchrony 1.0.0
faraday-excon 1.1.0
faraday-httpclient 1.0.1
faraday-net_http 1.0.1
faraday-net_http_persistent 1.2.0
faraday-patron 1.0.0
faraday-rack 1.0.0
ruby2_keywords 0.0.5
faraday 1.8.0
unf_ext 0.0.8
unf 0.1.4
domain_name 0.5.20190701
http-cookie 1.0.4
faraday-cookie_jar 0.0.7
faraday_middleware 1.2.0
fastimage 2.2.5
gh_inspector 1.1.3
mini_magick 4.11.0
naturally 2.2.1
rubyzip 2.3.2
security 0.1.3
xcpretty-travis-formatter 1.0.1
dotenv 2.7.6
simctl 1.6.8
jwt 2.3.0
uber 0.1.0
declarative 0.0.20
trailblazer-option 0.1.2
representable 3.1.1
retriable 3.1.2
mini_mime 1.1.2
memoist 0.16.2
multi_json 1.15.0
os 1.1.4
signet 0.16.0
googleauth 1.1.0
httpclient 2.8.3
google-apis-core 0.4.1
google-apis-playcustomapp_v1 0.6.0
google-apis-androidpublisher_v3 0.14.0
google-cloud-env 1.5.0
google-cloud-errors 1.2.0
google-cloud-core 1.6.0
google-apis-iamcredentials_v1 0.8.0
google-apis-storage_v1 0.10.0
digest-crc 0.6.4
google-cloud-storage 1.35.0
emoji_regex 3.2.3
jmespath 1.4.0
aws-partitions 1.540.0
aws-eventstream 1.2.0
aws-sigv4 1.4.0
aws-sdk-core 3.124.0
aws-sdk-kms 1.52.0
aws-sdk-s3 1.109.0
uri 0.10.0
json 2.6.1
bundler 2.2.33
webrick 1.7.0
rake 13.0.6
forwardable 1.3.1
logger 1.4.2
cgi 0.1.0
date 3.0.0
timeout 0.1.0
stringio 0.1.0
ipaddr 1.2.2
openssl 2.1.2
zlib 1.1.0
mutex_m 0.1.0
ostruct 0.2.0
strscan 1.0.3
io-console 0.5.3
delegate 0.1.0
fileutils 1.4.1
etc 1.1.0
singleton 0.1.0
open3 0.1.0
yaml 0.1.0
psych 3.1.0
fastlane-plugin-firebase_app_distribution 0.3.4

generated on: 2022-07-12

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 19
  • Comments: 16 (2 by maintainers)

Commits related to this issue

Most upvoted comments

For me what worked is: in app/build.gradle versionCode project.hasProperty(‘versionCode’) ? Integer.parseInt(project.versionCode) : 58

and in fastfile

gradle(… properties: { “versionCode” => next_build_number,

This is still an issue today

Plugins based solution works well.

bundle exec fastlane add_plugin increment_version_code
bundle exec fastlane add_plugin increment_version_name
    increment_version_code(
      gradle_file_path: "./android/app/build.gradle",
      version_code: ENV["CI_BUILD_ID"]
    )

    increment_version_name(
      gradle_file_path: "./android/app/build.gradle",
      version_name: package['version']
    )

Downgrading Gradle is a temporary solution, faster or later you’ll be forced out of it.

Here’s how I solved it:

Fastfile:

desc "Deploy a new internal version to Google Play"           
lane :internal do                         
  # <...>                    

  gradle(                                                     
    task: "bundleRelease",                                    
    project_dir: "..",                                        
    properties: {                                             
      "versionCode" => build_number,                          
      "versionName" => build_name,                            
    },                                                        
  )                                                           
                                                              
  # <...>
end

and in my build.gradle.kts:

defaultConfig {                                                                
    applicationId = "pl.baftek.spitfire"                                      
    minSdk = 21                                                               
    targetSdk = 33                                                            
    versionCode = (findProperty("versionCode") as? String)?.toIntOrNull() ?: 1
    versionName = findProperty("versionName") as? String ?: "1.0.0"           
}                                                                             

Do you have an alternative?

Plugins based solution works well.

bundle exec fastlane add_plugin increment_version_code
bundle exec fastlane add_plugin increment_version_name
    increment_version_code(
      gradle_file_path: "./android/app/build.gradle",
      version_code: ENV["CI_BUILD_ID"]
    )

    increment_version_name(
      gradle_file_path: "./android/app/build.gradle",
      version_name: package['version']
    )

saved my time thanks

I am seeing the same behavior. My project works fine and updates the versionCode using this in my Fastfile gradle command:

 "android.injected.version.code" => code

when I’m using (Gradle 7.2)

 classpath 'com.android.tools.build:gradle:7.1.3'

however, it does not work when I’m using (Gradle 7.3)

 classpath 'com.android.tools.build:gradle:7.2.1'

This fixed it for me, using the previous version. Give it a try guys.