Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding firebase to flutter project and getting FAILURE: Build failed with an exception error

Tags:

flutter

for [this flutter library][1] as barcode scanner i should to adding firebase to project, but after doing that i get this error and i cant fix that yet

Launching lib\main.dart on WAS LX1A in debug mode... Initializing gradle... Resolving dependencies... * Error running Gradle: ProcessException: Process "E:\Projects\Flutter\barcode_scanner\android\gradlew.bat" exited abnormally:

FAILURE: Build failed with an exception.

  • Where: Build file 'E:\Projects\Flutter\barcode_scanner\android\app\build.gradle' line: 14

  • What went wrong: A problem occurred evaluating project ':app'.

    ASCII

  • 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

BUILD FAILED in 6s Command: E:\Projects\Flutter\barcode_scanner\android\gradlew.bat app:properties

Finished with error: Please review your Gradle project setup in the android/ folder.

line 14 is:

apply plugin: 'com.android.application'

I'm not sure whats problem and this is my implementation about that

pabspec.yaml content:

version: 1.0.0+1
environment:
  sdk: '>=2.0.0-dev.28.0 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  firebase_core: ^0.4.0
  ...
...

android/build.gradle content:

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.3.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

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

android/app/build.gradle content:

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 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "barcodescanner.pishguy.barcode_scanner"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.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'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    androidTestImplementation 'androidx.test:runner:1.3.0-alpha01'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01'
}
apply plugin: 'com.google.gms.google-services'

running flutter command:

E:\Projects\Flutter\barcode_scanner>flutter pub get
Running "flutter pub get" in barcode_scanner...                     2.7s


  [1]: https://github.com/facundomedica/fast_qr_reader_view
like image 424
DolDurma Avatar asked Jul 14 '19 13:07

DolDurma


2 Answers

There is problem with 'com.google.gms:google-services:4.3.0'.
Switch it to 'com.google.gms:google-services:4.2.0', it's worked for me.

like image 77
namnh Avatar answered Oct 05 '22 12:10

namnh


This is my same exact problem; I managed to solve this problem on my end.

Here is the changes I had made on my code:

On AppName/Android/gradle/build.gradle:

buildscript {
    ext.kotlin_version = '1.3.50' //had to changed it previously 1.2.71
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1' //had to changed previously 3.2.1
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.2'
    }
}

then on AppName/Android/gradle/wrapper/gradle-wrapper.properties I had just changed this line:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip //it was peviously gradle-4.10.2-all.zip

after all those changes my app works.

like image 33
David B. Avatar answered Oct 05 '22 13:10

David B.