NOCSML70
NOCSML70

Reputation: 1

FAILURE: Build failed with an exception. build.gradle issue

I'm going to use flutter and firebase together. And I'm going to finish setting firebase and try to run the app again, but I get the following error.

FAILURE: Build failed with an exception.

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.

BUILD FAILED in 1s Running Gradle task 'assembleDebug'... 2,064ms Error: Gradle task assembleDebug failed with exit code 1

I've already been trying to solve the problem for about three hours. I've seen solutions to similar problems, but I couldn't apply them because I didn't understand them well.

It seems certain to some extent that there is something wrong with the following 2 codes.

app/build.gradle

plugins {
    id "com.android.application"
    // START: FlutterFire Configuration
    id 'com.google.gms.google-services'
    // END: FlutterFire Configuration
    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'
}

android {
    namespace "com.example.kyunggi_life"
    compileSdk flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion
    ndkVersion "26.1.10909125"

    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 "com.example.kyunggi_life"
        // 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 flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

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

tasks.whenTaskAdded { task ->
    if (task.name == 'processDebugGoogleServices') {
        task.mustRunAfter 'mapDebugSourceSetPaths'
    }
}

flutter {
    source '../..'
}

dependencies {}

apply plugin: 'com.google.gms.google-services'

android/build.gradle

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.4'
        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')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

I tried the following with an internet search.

Add ndkVersion "26.1.10909125", apply plugin: 'com.google.gms.google-services',

tasks.whenTaskAdded { task ->
    if (task.name == 'processDebugGoogleServices') {
        task.mustRunAfter 'mapDebugSourceSetPaths'
    }
}

at app/build.gradle

Check

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.4'
        classpath 'com.google.gms:google-services:4.3.10'
    }
}
```,
in android/build.gradle

Upvotes: 0

Views: 256

Answers (1)

Rishan Shrestha
Rishan Shrestha

Reputation: 76

Go to settings.gradle and add

id 'com.google.gms.google-services' version 'version_code' apply false

replace version_code 4.3.10 in your case, apply latest if possible

Remove from app/build.gradle

apply plugin: 'com.google.gms.google-services'

More information at https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply

Upvotes: 0

Related Questions