sbd2
sbd2

Reputation: 79

Flutter appbundle building using older version

I want to upload the second version of my Flutter app to the internal test channel on Google Play (I am just working with the Android version for now).

I could upload the first version 1.0.0+1 but when trying to upload the second version 1.0.1+2 Google Play Console is rejecting my appbundle with error message

You need to use a different version code for your APK because you already have one with version code 1.

I have already tried the sequence:

flutter clean to delete build and temp folders.

Modifying version line on pubspec.yaml from 1.0.0+1 to 1.0.1+2.

flutter pub get to rebuild flutter needed files.

flutter build appbundle to get the bundle built.

Since I have been already able to build and publish the first version of the app I assume that the rest of the build configuration is OK.

Most of the solutions aim to clean project, modify pubspec.yaml and then rebuild but this seems not to be working for me.

EDIT:

tried to modify build.gradle file using values flutterVersionName = '1.0.1' and flutterVersionCode = '2' and I am still getting an appbundle with versionCode 1.

Upvotes: 0

Views: 1762

Answers (3)

Atakan Akbulut
Atakan Akbulut

Reputation: 729

The accepted answer prevents the version from being managed by flutter.

After changing the version you should run the flutter pub upgrade command.

Upvotes: 0

sbd2
sbd2

Reputation: 79

Found a workaround good enough and that is building the appbundle not using Flutter sdk, but using Android Studio.

In order to achieve that do the following:

Open Android Studio > Open android project (android folder in your Flutter project)

Then modify your app level build.gradle as follows:

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "<YOUR_APP_ID>"
    minSdkVersion 21
    targetSdkVersion 28
    versionCode 2     // Manually add your desired version code
    versionName "1.0.1"      // Manually add your desired version name
//        versionCode flutterVersionCode.toInteger()
//        versionName flutterVersionName
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Then go to Build > Generate Signed Bundle / APK... to generate your bundle or APK as if you were building a native app (further instructions to generate a signed app bundle can be found here

Please note that this does not fully solve the issue since the bundle still cannot be correctly generated using Flutter sdk.

Upvotes: 0

Ricardo Gon&#231;alves
Ricardo Gon&#231;alves

Reputation: 5114

Android app version code and version name are defined in android/app/build.gradle. Take a look at this file and check if these lines are included

...
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}      

 def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}
...
 defaultConfig {
    applicationId "net.myapp"
    minSdkVersion 18
    targetSdkVersion 28
    versionCode flutterVersionCode.toInteger() //<-this line defines versionCode
    versionName flutterVersionName
...

If everything is ok, take a look at android/local.properties file. This file is updated when Flutter build the app. It should have these lines, generated from your pubspec.yaml data:

flutter.versionName=1.1.1
flutter.versionCode=9

If both files are ok, run a flutter build apk to regenerate local.properties data.

Upvotes: 1

Related Questions