Graddle error when adding firebase to flutter - flutter

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
The flutter projects works fine without firebase but when I add firebase it makes this error
Finished with error: Gradle task assembleDebug failed with exit code 1

Should update gms google service. Could you try this and let me know if it worked for you
classpath 'com.google.gms:google-services:4.2.0'

Related

FAILURE: Build failed with an exception. in Flutter project

Hello I am new to flutter , and I have this error while trying to run my project.
Can someone help me with it ?
Thank you.
If faced same issue, this solution worked for me
In android/build.gradle file:
in buildscript change the following:
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.13'
}
and in android\gradle\wrapper\gradle-wrapper.properties file:
add this line:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip

Could not create an instance of type org.gradle.invocation.DefaultGradle

I'm unable to build and run my flutter project. Every time I run the project it gives me this error
FAILURE: Build failed with an exception.
What went wrong:
Could not create an instance of type org.gradle.invocation.DefaultGradle.
Could not configure services using GradleScopeCompileServices.configure().
I searched and tried the following solution but nothing has worked so far:
Clean & Build Project
Deleted .gradle & .dart_tools folder
Downgraded Gradle version
I'm using Android studio 4.2.1. Let me know if you need anything else. Thanks in advance!
I tried many solutions but the following worked for me:
Downgraded flutter version from 2.2.3 to 2.2.2
Deleted ~/.android folder and then run the flutter project. Everything worked just fine.
I am use Flutter 2.5, same issue.
set ./android/build.gradle file to newer version:
classpath 'com.android.tools.build:gradle:7.0.0'
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

classpath does not match in build.gradle

Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
Failed to notify dependency resolution listener.
Problems reading data from Binary store in C:\Users\abc\AppData\Local\Temp\gradle11645302661581564201.bin offset 628139 exists? true
Problems reading data from Binary store in C:\Users\abc\AppData\Local\Temp\gradle11645302661581564201.bin offset 628139 exists? true
finally 5 hours of research I got solution of this,
I changed project level build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0' //old gradle
classpath 'com.android.tools.build:gradle:3.5.3' //new gradle
}
after that change gradle-wrapper.properties which is located in yourprojectPath/android/gradle/wrapper/gradle-wrapper.properties
change last line
distributionUrl=https://services.gradle.org/distributions/gradle-5.6.2-all.zip //old url
distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip // new url

Firebase Messaging gives gradle build error immediately

Trying to get up and running with a simple flutter app using the firebase_messaging package. Following the steps as per the instructions I changed the following files:
pubspec.yaml
dependencies:
flutter:
sdk: flutter # This is 1.7.8+hotfix.4
firebase_messaging: ^5.1.5
android/build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.3.0'
}
android/app/build.gradle
apply plugin: 'com.google.gms.google-services' # to the very bottom
Add the google-services.json to android/app/google-services.json and that's it.
Run using flutter run and the following error is returned:
* Error running Gradle:
ProcessException: Process "C:\...\android\gradlew.bat" exited abnormally:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\...\android\app\build.gradle' line: 24
* 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 0s
Command: C:\...\android\gradlew.bat app:properties
Please review your Gradle project setup in the android/ folder.
The instructions are pretty vague so perhaps I've missed something but I would've thought that should work. This is on Windows 10, I have a feeling it might be platform related.
Upgraded to 5.1.6 and Flutter 1.9.1+2.
In addition to the online instructions I had to make some additional changes to get it to compile:
android/build.gradle
buildscript {
ext.kotlin_version = '1.3.41'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.2'
}
}
android/app/build.gradle
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-messaging:20.0.0'
}
apply plugin: 'com.google.gms.google-services'
android/gradle/wrapper/gradle-wrapper-properties
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

Error while cloning flutter project from Github

I am trying to clone the following Flutter project from Github.
https://github.com/rxlabz/flutter_dropcity
But I am getting the following error in build.gradle using VS Code terminal.
What went wrong: A problem occurred evaluating root project 'android'.
A problem occurred configuring project ':app'.
Failed to notify project evaluation listener.
com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V
Please help me out here. Thanks in advance!
It seems from the discussion at https://github.com/flutter/flutter/issues/10236 that the problem can be fixed with using a newer build version.
For this go to build.gradle file in Android/gradle folder. Now change android build.gradle version from 2.2.3 (as in the original github repo) to 2.3.3 like so:
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
to
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}