16
votes

I've been using Google Play app signing, Flutter and VS Code without problems for a while now but since yesterday, every release build for every single Flutter project I'm working on keeps hitting an error and reporting that I'm trying to upload a debug build.

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

Even a new app is having same problem

I've cleaned the build folder out, I've used the --release flag, neither option worked.

One thing I'd like to try is manually compiling app, manually signing then uploading but can't work out how to do this.

Any suggestions? Tearing hair out as I can't think of any changes recently that could affect this.

flutter doctor output - only bit of weirdness is that VS Code flutter extension is missing - it's not :-/

✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.6 17G65, locale en-GB) • Flutter version 0.5.1 at /Users/kenwen/Dev Tools/flutter • Framework revision c7ea3ca377 (10 weeks ago), 2018-05-29 21:07:33 +0200 • Engine revision 1ed25ca7b7 • Dart version 2.0.0-dev.58.0.flutter-f981f09760

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.1) • Android SDK at /Users/kenwen/Library/Android/sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-28, build-tools 28.0.1 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01) • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 9.4.1, Build version 9F2000 • ios-deploy 1.9.2 • CocoaPods version 1.5.2

[✓] Android Studio (version 3.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 27.0.1 • Dart plugin version 173.4700 • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[!] VS Code (version 1.25.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension not installed; install from https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[!] Connected devices ! No devices available

! Doctor found issues in 2 categories.

build.gradle

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

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location 
with flutter.sdk in the local.properties file.")
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID 
(https://developer.android.com/studio/build/application-id.html).
        applicationId "uk.co.kenliu.meanfitfoxes"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 21
        versionName "1.7.9"
        testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
    }

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

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    }

apply plugin: 'com.google.gms.google-services'
5
Could you share your app/build.gradle file ?diegoveloper
Done, just added. AFAIK no changes have been made to anything, I discovered this a day or so ago and it affects every single Flutter project I'm working on, even a new project from scratchkenwen

5 Answers

37
votes

You have to create your signing config for release mode, in your current file your are using signing config from debug.

 buildTypes {
    release {
        signingConfig signingConfigs.debug   //for this reason google doesn't allow you to upload the apk
    }
}

Create a signing configuration inside your gradle file :

        android {
            ...
            signingConfigs {
                release {
                    storeFile file("release.keystore")
                    storePassword "******"
                    keyAlias "******"
                    keyPassword "******"
                }
            }
            buildTypes {
                release {
                    signingConfig signingConfigs.release
                }
            }
        }
7
votes

You also need to change

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

to

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

in the file android/app/build.gradle

6
votes

The problem is marked in red. You have copied the first part, which is signedConfigs. But didn't changed 'debug' to 'release'. NASA revealed that this happens when you are in a real hurry and can't see some of the minute details in the documentation and need to build and release the project as soon as possible. I was like that.

Screenshot from the documentation page, https://flutter.dev/docs/deployment/android

Flutter build

2
votes

In android/app/build.gradle change the signingConfig signingConfigs.debug to signingConfig signingConfigs.release which you can find under buildTypes

0
votes

You'll have to generate an upload key and keystore.

In the menu bar, click Build > Generate Signed Bundle/APK.

In the Generate Signed Bundle or APK dialog, select Android App Bundle or APK and click Next.

Below the field for Key store path, click Create new.

Fill-in the required fields : path, password, key, password, validity years, certificate details (name, org unit, etc.)

Click Ok.

To build, go to menu > Build > Generate Signed Bundle/APK.

Select release mode and don't forget to check on both V1 and V2 enter image description here

The above information is taken from Android Developer User Guide