Dart Flutter FAILURE: Build failed with an exception. Error

Issue

I took a few steps to publish my app on Play Store. Since making them, I’ve been getting errors when converting codes to APK.

I did the steps here: https://docs.flutter.dev/deployment/android#configure-signing-in-gradle


Error:

PS C:\Users\emiry\Desktop\KelimeOgren\kelimeogrenmeuygulamasi> flutter build appbundle

 Building with sound null safety 


FAILURE: Build failed with an exception.

Execution failed for task ':app:validateSigningRelease'.
> Keystore file not set for signing config release

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BU�LD FAILED in 3s
Running Gradle task 'bundleRelease'...                              4,8s
Gradle task bundleRelease failed with exit code 1

enter image description here

key.properties:

storePassword=secure
keyPassword=secure
keyAlias=key
storeFile=/key.jks

android/app/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.")
}

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

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

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

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

android {
    compileSdkVersion flutter.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        applicationId "com.example.secureAppId"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    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 {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
    implementation "androidx.multidex:multidex:2.0.1"
    implementation 'com.google.firebase:firebase-analytics:19.0.2'
    implementation 'com.google.firebase:firebase-messaging:22.0.0'
    implementation platform("com.google.firebase:firebase-bom:29.2.1")
}

android/build.gradle:

buildscript {
    ext.kotlin_version = '1.5.0'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I will publish the app on Google Play Store.
https://docs.flutter.dev/deployment/android#configure-signing-in-gradle I did the ones in this link.

What is the problem? How can I solve it? Thank you very much in advance for the help.

Solution

Put both key.properties and key.jks files directly to the android folder , not inside src. And, in the key.properties file, do the following:

storePassword=secure
keyPassword=secure
keyAlias=key
storeFile=../key.jks

Answered By – thisisyusub

Answer Checked By – Katrina (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *