cloud_firestore and firebase_auth compatiblity issue in Flutter - firebase

I am developing a Flutter app. My app works fine with cloud_firestore and firebase_auth packages when I use them separately. However, when I include both of them together in my pubspecs.yaml file, the build fails and the following message is shown:
Note: /home/saber/Code/mobile_dev/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.7.4/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /home/saber/Code/mobile_dev/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth-0.5.18/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /home/saber/Code/mobile_dev/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth-0.5.18/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /home/saber/Code/mobile_dev/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.2.5/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Here are the depenencies that I have in my pubspec.yaml file:
dependencies:
flutter:
sdk: flutter
firebase_auth: ^0.5.18
cloud_firestore: ^0.7.4
I checked the version of packages and they both seem to be at the latest version.
Any help on resolving this issue would be appreciated!
This might be connected to this issue, but I am not sure.

Update your gradle version. I was facing the same issue,i have solved it by using below steps.
Step 1:
in app/build.gradle
apply plugin: 'com.google.gms.google-services'
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
****multiDexEnabled true****
}
Step 2:
change gradle version dependencies in android/build.gradle
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:3.2.0'
Step 3:
latest version of firebase_auth and cloud_firestore in pubspec.ymal
cloud_firestore: ^0.12.5+1
firebase_auth: ^0.11.1+6
google_sign_in: ^4.0.2

For me work just change the minSDKVersion to 23 in the app build.gradle.

You need to follow this setup:
Open android/app/build.gradle and add at the bottom of the file:
apply plugin: 'com.google.gms.google-services'
and in the android/build.gradle add the following:
buildscript {
repositories {
// ,,,
}
dependencies {
// ...
classpath 'com.google.gms:google-services:3.2.1'
}
}

Use only this dependencies in android/build.gradle and remove any other dependencies
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:3.2.1'
You have to use this versions in pubspec.yaml
firebase_auth: 0.5.11
google_sign_in: 3.0.4
cloud_firestore: 0.7.3
Because these versions have updated gradle tooling.

Following update should resolve the issue:
Update android/gradle/wrapper/gradle-wrapper.properties
to distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
and update the dependencies and versions
in android/build.gradle
to dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms:google-services:4.3.2'
and android/build.gradle yet
buildscript {
ext.kotlin_version = '1.3.61'
in pubspec.yaml
firebase_core: ^0.4.2+1
cloud_firestore: ^0.12.11

Upgrade your gradle in app/build.gradle
run flutter pub upgrade to get latest dependencies !

Related

Flutter Android build fails with firebase dependencies (Could not find com.google.firebase:firebase-common)

I've been struggling a lot with the following build error after upgrading Firebase libs on pubspec.yaml. It is related to https://github.com/FirebaseExtended/flutterfire/issues/17, but no solution so far. Can anyone help me please?
What went wrong:
Execution failed for task ':firebase_core:generateReleaseRFile'.
> Could not resolve all files for configuration ':firebase_core:releaseCompileClasspath'.
> Could not find com.google.firebase:firebase-common:.
Required by:
project :firebase_core
(I am facing this too: It stops recognizing the GradleException inside of a build.gradle)
Flutter doctor
[✓] Flutter (Channel stable, 2.0.3, on macOS 11.2.3 20D91 darwin-x64)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Android Studio (version 4.1)
Pubspec
firebase_auth: ^1.0.1
cloud_firestore: ^1.0.1
firebase_database: ^6.1.0
firebase_core: 1.0.1
google_sign_in: ^5.0.1
Dependencies on build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.5'
}
Dependencies on app/build.gradle
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-bom:26.8.0'
implementation 'com.google.android.gms:play-services-base:17.6.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.google.firebase:firebase-core:11.0.4'
implementation 'com.google.firebase:firebase-auth:19.7.0'
implementation 'com.google.firebase:firebase-database:19.7.0'
implementation 'com.google.firebase:firebase-firestore:19.7.0'
}
I have already tried, but nothing worked:
decrease to classpath 'com.google.gms:google-services:3.2.1'
flutter clean and packages upgrade
Invalidaded Caches/Restart
Can anyone help me please? 2 days in a row and 0 evidence of what could be causing this. Thanks in advance!
removed external firebase SDK version set in build.gradle file
rootProject.ext {
set('FlutterFire', [
FirebaseSDKVersion: '25.12.0'
])
}
after removing these file it work's for me

* Error running Gradle: ProcessException: Process "E:\Flutter\login_demo\android\gradlew.bat" exited abnormally:

So guys i'am newbie at Flutter and i have my Flutter Project using Firebase Auth for user login. I have following the tutorial from youtube: https://www.youtube.com/watch?v=aaKef60iuy8 by guy called Andrea Bizzotto. I have follow 3 part of his videos regarding to this Firbase Auth tutorial. He suggest to latest firebase_auth dependecies, and according to pub.dev the latest dependecies of firebase_auth is
0.15.0+1, but he use the 0.5.4. However, if i use the 0.15.0+1 one i got some error at FirebaseAuth.instance, so i use the 0.5.4 dependecies. But it caused error to my gradle when building the project. The debug console throw me this:
[Debug Console Error Message][1]
And before make this post, i have tried to find any solution regarding to this error. So what have tried to do is:
Adding
classpath 'com.google.gms:google-services:4.3.2' and changing classpath 'com.android.tools.build:gradle:3.2.1' to
classpath 'com.android.tools.build:gradle:3.5.1' in (android/build.gradle)
Adding
multidexEnabled = true at defaultConfig, implementation 'com.google.firebase:firebase-analytics:17.2.0' implementation
'com.google.firebase:firebase-firestore:19.0.0' implementation
'com.android.support:multidex:1.0.3' at dependencies also apply
plugin: 'com.google.gms.google-services' at the bottom of
(android\app\buid.gradle) file
I'm also adding
android.useAndroidX=true
android.enableJetifier=true
org.gradle.daemon=true
org.gradle.parallel=true in gradle.properties file
Here is my flutter doctor -v result
[Flutter doctor -v Result][2]
Any Help is very much appreciated.
[1]: https://i.stack.imgur.com/60j9S.png [2]:
https://i.stack.imgur.com/9G8ug.png
you can try to update the build.grade from project root like this:
buildscript {
ext.kotlin_version = '1.3.50'
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.3'
}
}
and then the distributionUrl in grade-wrapper.properties like this:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
I got the answer from here: https://github.com/flutter/flutter/issues/41492

Firebase implementation in flutter issues

I am having a lot of issues with implementing firebase in my flutter project, I had to revert back from 4.3 to 4.2 because of gradle errors. Now it is taking forever to load it on my emulator, I switched to an actual device but that install wont open. Has anyone implemented firebase messaging in a flutter project recently? I’m about to scrap the whole idea of using it.
Ive added the required lines to build.gradle and app/build.gradle and to my yaml file and thats it.
I have it working as of today (2019-09-27 20:00 UTC, because flutter builds can break at any moment), and I'll let you know what I have in my build in order to get it to work (bit too long for a comment). I have tested that it works in both iOS and Android and builds correctly for release.
Firstly, switch to the flutter master channel flutter channel master. This is to fix a gradle appbundle naming issue.
pubspec.yaml
dependencies:
firebase_messaging: ^5.1.6
android/build.gradle (note the change in gradle version)
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/gradle.properties (change for AndroidX)
android.enableJetifier=true
android.useAndroidX=true
android/gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
android/app/build.gradle
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.firebase:firebase-messaging:20.0.0'
}
apply plugin: 'com.google.gms.google-services'
In the same file make sure in the defaultConfig section you've changed the testInstrumentationRunner as follows:
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
android/app/src/main/AndroidManifest.xml
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Make sure you've added your google-services.json to android/app folder. I assume at some point this will all be nicely documented but at the moment it's a bit wild-west.

How to fix 'Dependency failing' when building Flutter application on Android

I am trying to use Google Sign in with my Flutter application. However, I am unable to build the application due to some issues with dependencies. I have updated all of my dependencies to the latest version but to no avail. How do I resolve these dependencies so I can build the application?
This is for a simple flutter application using google sign in running on a connected OnePlus 6 android phone.
I have tried updating my dependencies to the latest version as well as changing the code to match the latest version of the google_sign_in dependency found here: https://pub.dartlang.org/packages/google_sign_in
I also tried adding firebase_core to the list of dependencies as the error message said that the app relied on firebase_core. This did nothing to change the error message.
Project 'pubspec.yaml' dependencies
dependencies:
flutter:
sdk: flutter
duration: ^2.0.0
firebase_core: ^0.3.2
cloud_firestore: ^0.9.11
firebase_auth: ^0.8.4
google_sign_in: ^4.0.1+3
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
Project Level build.gradle (android/build.gradle):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// Google Services class path
classpath 'com.google.gms:google-services:4.2.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
}
App Level build.gradle (android/app/build.gradle):
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 "com.example.recipe_app"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
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 {
implementation 'com.google.firebase:firebase-core:16.0.1'
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'
}
apply plugin: 'com.google.gms.google-services'
The output of 'flutter run':
Launching lib/main.dart on ONEPLUS A6003 in debug mode...
Initializing gradle... 1.0s
Resolving dependencies... 4.0s
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
FAILURE: Build failed with an exception.
* What went wrong:
Failed to capture fingerprint of input files for task ':app:checkDebugClasspath' property 'compileClasspath' during up-to-date check.
> In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[15.0.
1]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.
Dependency failing: com.google.android.gms:play-services-stats:15.0.1 -> com.google.android.gms:play-services-basement#[
15.0.1], but play-services-basement version was 16.1.0.
The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the art
ifact with the issue.
-- Project 'app' depends on project 'cloud_firestore' which depends onto com.google.firebase:firebase-firestore#18.2.0
-- Project 'app' depends onto com.google.firebase:firebase-core#16.0.1
-- Project 'app' depends on project 'firebase_auth' which depends onto com.google.firebase:firebase-auth#16.0.5
-- Project 'app' depends on project 'google_sign_in' which depends onto com.google.android.gms:play-services-auth#16.0.1
For extended debugging info execute Gradle from the command line with ./gradlew --info :app:assembleDebug to see the dep
endency paths to the artifact. This error message came from the google-services Gradle plugin, report issues at https://
github.com/google/play-services-plugins and disable by adding "googleServices { disableVersionCheck = false }" to your b
uild.gradle file.
* 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 2s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 2.9s
Gradle task assembleDebug failed with exit code 1
I expected the application to build successfully so I could test if Google Sign in worked. However, the application does not build successfully and I am at a loss as to what to do.
I attempted to recompile using verbose mode and was informed about AndroidX being the cause.
I followed this link and downgraded all of the dependencies to the versions before the AndroidX migration as listed in the article. This fixed the issue.

Flutter Firebase Auth not working in Ecommerce app

I was trying out the firebase auth but when I added the dependencies I got some error.
Could you please check what the error?
This is the error that I got :
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:processDebugResources'.
Android resource linking failed
Output: D:\App\dipam\build\app\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
And this the dependencies that I added to the pubspec.yaml file :
dependencies:
flutter:
sdk: flutter
carousel_slider: ^1.0.1
cloud_firestore: 0.8.2+3
firebase_auth: 0.6.6
google_sign_in: ^3.2.4
shared_preferences:
fluttertoast:
The error you posted is a result of conflicting android.support and AndroidX versions. Make sure you're targeting API version 28.
In your app's build.gradle check if you have following values set
android {
compileSdkVersion 28 // <-- Make sure you target API 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// ...
targetSdkVersion 28 // <-- You need to update this value as well, or you might encounter runtime errors
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
// ...
}
// ...
}
Also, make sure your not using old android.support libraries in your dependencies, but new AndroidX packaged. Check this article for further references

Resources