Search code examples
fluttercode-signinggoogle-play-console

My first Android app was going great until I tried getting it signed


I've been developing using Flutter/Dart in Android Studio since December and want to finally open it up to others for internal testing. Whenever I upload my app, it says The Android App Bundle was not signed.

I guess there's supposed to be an option to sign a bundle in the Build menu, but I have no such menu item. I can see no way in Android Studio to set up signing.

I've seen other help on this site that recommends changing build.gradle from "signingConfig signingConfigs.debug" to "signingConfig signingConfigs.release". All variants of that I've seen cause a build error that 'release' is an unknown option.

Hopefully someone can help me solve in 2 minutes what I've been working on for the last 5 hours.

My setup:

Android Studio Bumblebee | 2021.1.1 Patch 3 Build #AI-211.7628.21.2111.8309675, built on March 16, 2022 Runtime version: 11.0.11+9-b60-7590822 amd64 VM: OpenJDK 64-Bit Server VM by Oracle Corporation Windows 10 10.0 GC: G1 Young Generation, G1 Old Generation Memory: 1280M Cores: 12 Registry: external.system.auto.import.disabled=true Non-Bundled Plugins: Dart (211.7817), org.jetbrains.kotlin (211-1.6.21-release-334-AS7442.40), io.flutter (66.0.1), org.intellij.plugins.markdown (211.7142.37)


Solution

  • I was also stuck in the same error for a few hours at least and that's how I solved it.

    Type the below command in the terminal to get the .jks file

    If on Mac/Linux

    keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload
    

    for windows

    keytool -genkey -v -keystore c:\Users\USER_NAME\upload-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload
    

    Then you will be asked for some details and enter them, then you will get a .jks file, copy and paste it into [project]/android/app/ folder to keep it handy. Don't forget to add it in .gitignore if your code is public.

    After that create a file named [project]/android/key.properties which is actually a reference to your keys and paste below key properties there:

    storePassword=<password you used to create .jks file>
    keyPassword=<key password you used to create .jks file>
    keyAlias=upload
    storeFile=../app/upload-keystore.jks
    

    After you have created the key.properties, you need to configure [project]/android/app/build.gradle files:

    1.

    def keystoreProperties = new Properties()
    def keystorePropertiesFile = rootProject.file('key.properties')
    if (keystorePropertiesFile.exists()) {
       keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
    }
    android {
          ...
    }
    
    signingConfigs {
    release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? 
           file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
    }
    buildTypes {
       release {
           signingConfig signingConfigs.release
       }
    }
    

    Lastly, flutter clean and rebuild the app bundle using the command:

    flutter build appbundle
    

    Congratulations your app bundle is Signed and ready to be released on the play store.