39

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
        }
    }
}

7 Answers 7

31

Flutter has the option to build an appbundle:

flutter build appbundle

My reference is from this github project.

Sign up to request clarification or add additional context in comments.

Comments

22

Try modifying your buildTypes block.

buildTypes {
    release {
        signingConfig signingConfigs.release
    }
}

1 Comment

did this. now the build fails with the following error message from gradle: Could not get unknown property 'release' for SigningConfig container of type org.gradle.api.internal.FactoryNamedDomainObjectContainer
17

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

1 Comment

Thanks @mike-dubs. following the link you added worked for me perfectly.
3

add in 'android/app/build.gradle' your buildTypes block

buildTypes {
    release {
        signingConfig signingConfigs.release
    }
}

run flutter clean flutter pub get then flutter build appbundle --release

Comments

2

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
        }
    }

Comments

1

Now as we are using gradle.kts so we need to use the newer version of it.

Here is the details

inside build.gradle.kts

import java.util.Properties
import java.io.FileInputStream


val keystorePropertiesFile = rootProject.file("key.properties")
val keystoreProperties = Properties()
keystoreProperties.load(FileInputStream(keystorePropertiesFile))

android {

signingConfigs {
        create("release") {
            storeFile = file(keystoreProperties["storeFile"] as String)
            storePassword = keystoreProperties["storePassword"] as String
            keyAlias = keystoreProperties["keyAlias"] as String
            keyPassword = keystoreProperties["keyPassword"] as String
        }
    }

    buildTypes {
        release {
            signingConfig = signingConfigs.getByName("release")
        }
    }
}

Need to use this type then it will work.

Comments

0

let me explain little bit in BuildTypes section in release the line "signingConfig signingConfigs.debug" is used for debugging it create a dubugging apk

but when you want to create an apk or an appbundle for release you will change or also will add this line "signingConfig signingConfigs.release" so when you run command for creating apk file or appbundle it will be create for release

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.