Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can not find flutter android version code

I was able to build the release version of my app and uploaded to play store, Now I want to update it and I need to change the versionCode. However when I look in my <android/app/build.gradle> the part which says version which is supposed to be an integer is now something like flutterVersionCode.toInteger() and versionName flutterVersionName is a bit confusing for me and I dont know where to change it from.

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    throw new GradleException("versionCode not found. Define flutter.versionCode in the local.properties file.")
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    throw new GradleException("versionName not found. Define flutter.versionName in the local.properties file.")
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.someApp"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile file(keystoreProperties['storeFile'])
        storePassword keystoreProperties['storePassword']
    }
}
buildTypes {
    release {
        signingConfig signingConfigs.release
        minifyEnabled true
        useProguard true

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        
    }
}
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    //implementation 'com.google.firebase:firebase-core:15.0.2'
    //compile 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-core:15.0.2'

}

apply plugin: 'com.google.gms.google-services'
like image 209
Norbert Avatar asked Jun 12 '19 15:06

Norbert


2 Answers

int generateVersionCode(String versionName) {
   def parts = versionName.split("\\.").collect { it.toInteger() }
   return parts[0] * 10000 + parts[1] * 100 + parts[2]
}

here is a nice method to generate the version from he flutterVersionName

defaultConfig {
   [...]
   versionCode generateVersionCode(flutterVersionName)
   versionName flutterVersionName
}
like image 34
volkersfreunde Avatar answered Oct 10 '22 23:10

volkersfreunde


You don't need to modify manually your build.gradle.

Open your pubspec.yaml and you will find an entry like this:

version: 1.0.0+1

Flutter uses semantic versioning so what do you need is modify that entry:

version: 1.0.1+2

In this case the version name will be 1.0.1 and the version code will be 2

like image 139
Roberto Manfreda Avatar answered Oct 10 '22 22:10

Roberto Manfreda