Search code examples
androidflutterdebuggingrelease

Why do I keep receiving an error that I uploaded an APK that was signed in debug mode?


"You uploaded an APK that was signed in debug mode. You need to sign your APK in release mode"

Folks, I think I am loosing it. I am trying, for the first time, to upload an app to the Google Play Store, and I keep getting the error message above.

I have followed the relevant guides for generating a signed release version of my app (i.e., I have set up a jks file, adapted the build.gradle file and connected both via the key.properties file). It really seems all in order. Please help me here!

My config is as follows:

My build.gradle file in the directory /android/app:

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

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

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

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

android {
    namespace "XXX"
    compileSdkVersion flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "XXX"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion 29 
        targetSdkVersion 34
        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 {
           signingConfig signingConfigs.release
       }
   }
}

flutter {
    source '../..'
}

dependencies {}

My key.properties file in the directory /android

storePassword=XXX
keyPassword=XXX
keyAlias=upload
storeFile=upload-keystore_CBT.jks

My upload-keystore_CBT.jks file is in the directory /android

I have performed the commands

flutter clean

and then

flutter build appbundle --release

The commands run without error, and I get a file app-release.aab in the \build\app\outputs\bundle\release folder as expected. I then upload to Google, where I am welcomed with the error.

Why do I keep getting this error? Many thanks in advance!


Solution

  • Following the helpful comment by Michael, I was able to get it running by moving the upload-keystore.jks file into the android/app folder (instead of the android folder).

    I encountered additional problems by not saving all open files in visual studio code (i.e., from modifying the build.gradle) and by not running flutter clean before each time building the appbundle/apk.

    So make sure to do this in order to avoid spending as much time on this as I did...

    Sidenote: In general, I found the following guide the most helpful: https://docs.flutter.dev/deployment/android

    In other posts on this error, problems often resulted from not changing signingConfigs from debug to release (but this was not the issue here).