Firebase implementation in flutter issues - firebase

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.

Related

How to connect/use Firebase in Intellij Idea?

If anyone can explain how to use Firebase in Intellij Idea, it would be very useful as I am unable to find any resource to refer to.
I found that following is the process for Android Studio but I need to do it in Intellij Idea.
First make sure you have installed Google Repository version 26 or higher, using the following steps:
Click Tools > SDK Manager.
Click the SDK Tools tab.
Check the Google Repository checkbox, and click OK.
Click OK to install.
Click Background to complete the installation in the background, or wait for the installation to complete and click Finish.
You can now open and use the Assistant window in Android Studio by following these steps:
Click Tools > Firebase to open the Assistant window.
Click to expand one of the listed features (for example, Analytics), then click the Get Started tutorial to connect to Firebase and add the necessary code to your app.
It's not as difficult as it may seem.
This explains all the proccess.
Your choose is the Option 1. After step 4 your project-level build.gradle should look like (of course sdk, java, libreries versions can be different)
all sub-projects/modules.
buildscript {
repositories {
google()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.12'
}
}
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
allprojects {
repositories {
google()
}
}
and app-level build.gradle(app/build.gradle) like
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "io.devmartynov.bulletinboard"
minSdk 30
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation platform('com.google.firebase:firebase-bom:30.2.0')
implementation 'com.google.firebase:firebase-database'
}
apply plugin: 'com.google.gms.google-services'
Don't foget to add implementation 'com.google.firebase:firebase-database' in you app-level build.gradle(app/build.gradle), because steps 1-4 don't mention it.
After that sync gradle files changes. While syncing you may face with error Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'. This explains and solves the problem.
Next you should create Realtime Database. It's pretty simple!
You also must place google-services.json file to your app directory. You can download this file in settings->project settings->your apps->google-services.json
After that you can try to write to you DB.
Add this test code to onCreate method and start app.
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("messages");
myRef.setValue("Hello, World!");

* 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

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.

Failed to capture fingerprint of input files for task ':app:preDebugBuild' property 'compileManifests' during up-to-date check

I'm setting firebase on my project and when I add inappmessaging-display lib this error appears:
Dependency resolved to an incompatible version:
Dependency(fromArtifactVersion=ArtifactVersion(groupId=com.google.firebase,
artifactId=firebase-messaging, version=17.3.2),
toArtifact=Artifact(groupId=com.google.firebase,
artifactId=firebase-iid), toArtifactVersionString=[17.0.2]) FAILURE:
Build failed with an exception.
What went wrong: Failed to capture fingerprint of input files for task ':app:preDebugBuild' property 'compileManifests' during
up-to-date check. In project 'app' a resolved Google Play services
library dependency depends on another at an exact version (e.g.
"[17.0. 2]", but isn't being resolved to that version. Behavior
exhibited by the library will be unknown.
Dependency failing: com.google.firebase:firebase-messaging:17.3.2 -> com.google.firebase:firebase-iid#[17.0.2], but fire base-iid version was 17.0.3.
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 onto
com.google.firebase:firebase-iid#17.0.3 -- Project 'app' depends
onto com.google.firebase:firebase-messaging#17.3.2 -- Project 'app'
depends onto com.google.firebase:firebase-ads#17.1.2 -- Project
'app' depends onto
com.google.firebase:firebase-inappmessaging-display#17.0.4 --
Project 'app' depends onto
com.google.firebase:firebase-analytics#16.0.6 -- Project 'app'
depends onto com.google.firebase:firebase-analytics-impl#16.2.4 --
Project 'app' depends onto
com.google.firebase:firebase-inappmessaging#17.0.4 -- Project 'app'
depends onto com.google.firebase:firebase-core#16.0.6 -- Project
'app' depends onto
com.google.firebase:firebase-measurement-connector-impl#17.0.4 --
Project 'app' depends onto com.google.firebase:firebase-config#16.1.3
-- Project 'app' depends onto com.google.firebase:firebase-crash#16.2.1 -- Project 'app' depends
onto com.google.firebase:firebase-abt#16.0.1 -- Project 'app'
depends onto com.google.firebase:firebase-perf#16.2.3 -- Project
'app' depends onto
com.google.android.gms:play-services-measurement-api#16.0.4
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 build.gradle
file.
project file
buildscript {
ext.kotlin_version = '1.3.11'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.2.0'
classpath ('com.google.firebase:firebase-plugins:1.1.5')
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id 'com.gradle.build-scan' version '1.16'
}
ext {
support_library_version = '28.0.0' //use the version of choice
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app gradle file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
buildScan {
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
licenseAgree = 'yes'
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.myapp.pocapp"
minSdkVersion 25
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:animated-vector-drawable:$support_library_version"
implementation "com.android.support:exifinterface:$support_library_version"
implementation "com.android.support:cardview-v7:$support_library_version"
implementation "com.android.support:customtabs:$support_library_version"
implementation "com.android.support:support-media-compat:$support_library_version"
implementation "com.android.support:support-v4:$support_library_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.support:appcompat-v7:$support_library_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
//Play services dependencies
implementation('com.google.android.gms:play-services-plus:15.0.1')
implementation('com.google.android.gms:play-services-gcm:15.0.1')
implementation('com.google.android.gms:play-services-maps:15.0.1')
implementation('com.google.android.gms:play-services-ads:15.0.1')
implementation('com.google.android.gms:play-services-location:15.0.1')
implementation('com.google.android.gms:play-services-analytics:16.0.3')
implementation('com.google.android.gms:play-services-basement:15.0.1')
implementation('com.google.android.gms:play-services-auth:16.0.0')
implementation('com.google.android.gms:play-services-drive:15.0.1')
//General google dependencies
implementation('com.android.installreferrer:installreferrer:1.0')
implementation('com.android.billingclient:billing:1.2')
//Firebase dependencies
implementation('com.google.firebase:firebase-core:16.0.6')
implementation('com.google.firebase:firebase-perf:16.2.3')
implementation('com.google.firebase:firebase-ads:17.1.2')
implementation('com.google.firebase:firebase-crash:16.2.1')
implementation('com.google.firebase:firebase-config:16.1.3')
implementation('com.google.firebase:firebase-messaging:17.3.2')
implementation('com.google.firebase:firebase-inappmessaging:17.0.4')
implementation('com.google.firebase:firebase-inappmessaging-display:17.0.4')
}
apply plugin: 'com.google.gms.google-services'
I already updated all libs to latest versions.
I am also facing same issue,
At finally got a Solution.
Please remove Cordova-plugin-firebase and
Use the latest major releases just by running: cordova plugin add cordova-plugin-firebase-lib
Simply follow the following link: https://www.npmjs.com/package/cordova-plugin-firebase-lib
Check your internet connection.
If you are connected,try to use a proxy server (using hotspot shield,PSiphone, etc.)
The problem was on firebase libs versions, Just update every lib to fix this.
cd android
./gradlew clean
try this

cloud_firestore and firebase_auth compatiblity issue in Flutter

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 !

Resources