flutter building appbundle in release mode

Viewed 24178

I have built an app in flutter using android studio and am trying to release it on the play store.

According to https://flutter.dev/docs/deployment/android#reviewing-the-build-configuration, "Run flutter build appbundle (Running flutter build defaults to a release build.)" enter image description here enter image description here

However, when I try to upload this on the play console, I get the error message that "You uploaded an APK or Android App Bundle that was signed in debug mode. You need to sign your APK or Android App Bundle in release mode." enter image description here

What should I do differently?

From my gradle.build:


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

android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.rtterror.custom_snooze_alarm"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}
4 Answers

Try modifying your buildTypes block.

buildTypes {
    release {
        signingConfig signingConfigs.release
    }
}

Flutter has the option to build an appbundle:

flutter build appbundle

My reference is from this github project.

Make sure you have your keystore file properly set up and referenced in "Android/key.properties". Here is the command to create the keystore: keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload

Then run flutter clean && flutter build appbundle --release

If you get the same error, then try this helpful walkthrough: https://medium.com/@psyanite/how-to-sign-and-release-your-flutter-app-ed5e9531c2ac

you have debug in front of signingConfigs just change it to release

  buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
Related