Melih Durmaz
Melih Durmaz

Reputation: 349

Flutter release apk not accepted by Google Play Console

I created a key and keystore and signed my apk, following the instructions step by step from the official flutter page.

But when I try to upload it to Google Play Console, I get this error:

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

A similar question is asked before, but it did not solve my issue.

Here is the relevant part of my app/build.gradle:

android {
compileSdkVersion 28

lintOptions {
    disable 'InvalidPackage'
}

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

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

Here is the screenshot of my Android Studio versions (Android SDK being red is not relevant.):

Screenshot of Android Studio showing the used versions.

My output.json file:

[
  {
    "outputType": {
      "type": "APK"
    },
    "apkInfo": {
      "type": "MAIN",
      "splits": [
        
      ],
      "versionCode": 1,
      "versionName": "1.0.0",
      "enabled": true,
      "outputFile": "app-release.apk",
      "fullName": "release",
      "baseName": "release"
    },
    "path": "app-release.apk",
    "properties": {
      
    }
  }
]

Upvotes: 10

Views: 8390

Answers (4)

Melih Durmaz
Melih Durmaz

Reputation: 349

No suggestions seemed to be working. Then, a

flutter clean

and all issues were solved. I could create an apk either through Android Studio or the command line. Thanks to VikaS and Harsha pulikollu

Upvotes: 10

Vicky Salunkhe
Vicky Salunkhe

Reputation: 10985

Try

flutter clean

flutter clean command is really helpful in many scenario whenever some absurd behavior is shown by the app.

Upvotes: 0

Ricardo Gonçalves
Ricardo Gonçalves

Reputation: 5094

flutter clean did not work for me either. So I manually signed the apk and it was accepted by Google Play Console. Found the directions here https://developer.android.com/studio/publish/app-signing#sign-manually

How to manually sign apk

To manually sign the apk you need to run the following commands in a terminal o in command prompt in Windows.

1 - Make sure the apk is signed with debug keys:

<build-tools-path>/<sdk-vesion>/apksigner verify --print-certs app-release.apk (replace "app-release.apk" with your apk filename"

If it is signed with debug keys, the output will be similar to

Signer #1 certificate DN: C=US, O=Android, CN=Android Debug
Signer #1 certificate SHA-256 digest: 384cf54f892877ea6d934bbc335bf3aa61b8dd3d89e27feb49c0bc7e62b0bbb7
Signer #1 certificate SHA-1 digest: c7a8384ff8fe2d1e99dbdba45db93180ed53b9ff
Signer #1 certificate MD5 digest: ca13ad2688257283319bf2596f360f8c

2 - Run zipalign to align first byte and reduce RAM usage

<build-tools-path>/<sdk-vesion>/zipalign -v -p 4 app-release.apk app-aligned.apk

It will list the files and finish with a Verification succesful message.

3 - Run appsigner to sign the app:

<build-tools-path>/<sdk-vesion>/apksigner sign --ks <path to .jks file> --out app-signed.apk app-aligned.apk

It will prompt for the keystore password and silently finish the job.

4 - Verify if it is signed with your keys:

<build-tools-path>/<sdk-vesion>/apksigner verify --print-certs app-signed.apk

If it is correctly signed, the output will be similar to the fist step, but instead of "Android Debug" it will output your certificate's data.

Upvotes: 2

VikaS GuttE
VikaS GuttE

Reputation: 1704

You need to select release option while building APK

For Windows

enter image description here

For Apple

enter image description here

Upvotes: 2

Related Questions