Flutter app crashes on start using fire base? - firebase

Started a new flutter project and trying to use firestore.
After following all step to add project to fire base.
Adding all plugins to pubspec.yaml and then running the project.
The log cat shows this:
04-04 14:54:56.061 24084-24084/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.firestoreflutterchat, PID: 24084
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.example.firestoreflutterchat-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.firestoreflutterchat-2, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:4869)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4461)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4401)
at android.app.ActivityThread.access$1500(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.example.firestoreflutterchat-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.firestoreflutterchat-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.ActivityThread.installProvider(ActivityThread.java:4854)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4461) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4401) 
at android.app.ActivityThread.access$1500(ActivityThread.java:139) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5097) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
at dalvik.system.NativeStart.main(Native Method
Before adding cloud firestore plugin the newly project was running after adding this i am having issue.
This is the Pubspec.yaml file :
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.13.4+2
permission_handler: ^5.0.0+hotfix.3
firebase_auth: ^0.15.5+3
google_sign_in: ^4.4.0
cupertino_icons: ^0.1.3
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true

the problem did not resolve with multidex , only way was to remove it and follow this link
resolve multidex issue
it worked by removing these in your gradle
multiDexEnabled true
and
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
and changing from this
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
to this
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
useProguard true
}
debug{
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
and in your path: /android/app
right click and create a file named proguard-rules.pro
and put these files inside the file
#Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }

It seems some setups are still remaining for Firebase.
Checkout this link and set up the .json and .plist file accordingly in project.
If you further still facing the issue,
I would recommend some steps.
1) Delete all the build files of the project, invalid cache and restart android studio.
2) Follow the below changes in your project.
build.gradle file
android {
.....
defaultConfig {
......
multiDexEnabled true//add this line
}
......
dependencies{
compile 'com.android.support:multidex:1.0.1'//add this line
}
AndroidManifest.xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
....
<application
....
android:name="android.support.multidex.MultiDexApplication"
...>
<activity />
...
</application>
</manifest>

Related

Included Firebase in flutter and got errors while building (warning i had pasted all the error code i got so please be calm)

I am trying to do a chat app and I included the
Firebase core, firebase auth and Firebase firestore.
When I run the app it shows the following errors. Do I need to post any other code files?
D8: Cannot fit requested classes in a single dex file (# methods: 91691 > 65536)
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:132)
at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:119)
at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:102)
at com.android.build.gradle.internal.tasks.DexMergingTaskRunnable.run(DexMergingTask.kt:432)
at com.android.build.gradle.internal.tasks.Workers$ActionFacade.run(Workers.kt:242)
at org.gradle.workers.internal.AdapterWorkAction.execute(AdapterWorkAction.java:57)
at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:67)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:63)
at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:97)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:63)
at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195)
at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:62)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$call$2(DefaultBuildOperationExecutor.java:76)
at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.callWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:54)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:76)
at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:60)
at org.gradle.workers.internal.DefaultWorkerExecutor.lambda$submitWork$2(DefaultWorkerExecutor.java:200)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, position: null
at Version.fakeStackEntry(Version_2.1.62.java:0)
at com.android.tools.r8.utils.Y.a(SourceFile:78)
at com.android.tools.r8.D8.run(D8.java:11)
at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:117)
... 36 more
Caused by: com.android.tools.r8.utils.b: Cannot fit requested classes in a single dex file (# methods: 91691 > 65536)
at com.android.tools.r8.utils.T0.error(SourceFile:1)
at com.android.tools.r8.utils.T0.a(SourceFile:2)
at com.android.tools.r8.dex.P.a(SourceFile:740)
at com.android.tools.r8.dex.P$h.a(SourceFile:7)
at com.android.tools.r8.dex.b.a(SourceFile:14)
at com.android.tools.r8.dex.b.b(SourceFile:25)
at com.android.tools.r8.D8.d(D8.java:133)
at com.android.tools.r8.D8.b(D8.java:1)
at com.android.tools.r8.utils.Y.a(SourceFile:36)
... 38 more
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
* 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 34s
[!] The shrinker may have failed to optimize the Java bytecode.
To disable the shrinker, pass the `--no-shrink` flag to this command.
To learn more, see: https://developer.android.com/studio/build/shrink-code
Exception: Gradle task assembleDebug failed with exit code 1
This is my pubspec.yml file where i included the dependencies in of the Firebase core,Firebase auth and Firebase firestore and others that are need for the project
name: flash_chat
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
animated_text_kit: ^4.2.1
cloud_firestore: ^1.0.7
firebase_auth: ^1.1.2
firebase_core: ^1.1.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
This is a multidex issue, you have two solution, or you can set the minSDKVersion to 21 or add multidex in your dependencies in build.gradle:
https://developer.android.com/studio/build/multidex
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
...
}
dependencies {
implementation "androidx.multidex:multidex:2.0.1"
}
Or just:
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 28
}
...
}
Add Multi Dex :
Here is the Code : Go to Android->app->build.gradle
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.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
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.bahokboy"
minSdkVersion 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.3'
}

Firebase_database plugin for flutter is not working (resolve android.arch.core:common:1.1.1.)

I am new to flutter development. I want to use the firebase database. I was able to connect to firebase using the firebase analytics plugin but I was not successful in using the firebase database.
I tried to add the plugin on a time to knew where did the issue come from and know I am sure it is the firebase_database plugin.
I have successfully added the following package:
firebase_core: ^0.4.0+9
firebase_analytics: ^5.0.2
firebase_auth: ^0.14.0+5
but when I add
firebase_database: ^3.1.0
I get the below error
Finished with error: Gradle task assembleDebug failed with exit code 1
This error appears when I run the default flutter application (The counter app) on my Android mobile.
So I open the Android module in Android Studio to get more details about the error.
I got the following error
ERROR: Unable to resolve dependency for ':firebase_database#debug/compileClasspath': Could not resolve android.arch.lifecycle:runtime:1.1.1.
Show Details
Affected Modules: firebase_database
ERROR: Unable to resolve dependency for ':firebase_database#debug/compileClasspath': Could not resolve android.arch.lifecycle:common:1.1.1.
Show Details
Affected Modules: firebase_database
ERROR: Unable to resolve dependency for ':firebase_database#debug/compileClasspath': Could not resolve android.arch.lifecycle:runtime:{strictly 1.0.0}.
Show Details
Affected Modules: firebase_database
ERROR: Unable to resolve dependency for ':firebase_database#debug/compileClasspath': Could not resolve android.arch.lifecycle:common:{strictly 1.0.0}.
Show Details
Affected Modules: firebase_database
ERROR: Failed to resolve: com.google.firebase:firebase-common:16.0.6
Show in Project Structure dialog
Affected Modules: firebase_database
ERROR: Unable to resolve dependency for ':firebase_database#debug/compileClasspath': Could not resolve android.arch.core:common:{strictly 1.0.0}.
Show Details
Affected Modules: firebase_database
ERROR: Unable to resolve dependency for ':firebase_database#debug/compileClasspath': Could not resolve android.arch.core:common:1.1.1.
Show Details
Affected Modules: firebase_database
ERROR: Unable to resolve dependency for ':firebase_database#debug/compileClasspath': Could not resolve android.arch.lifecycle:runtime:1.0.0.
Show Details
Affected Modules: firebase_database
This is my pubspec.yaml file
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
firebase_core: ^0.4.0+9
firebase_analytics: ^5.0.2
firebase_auth: ^0.14.0+5
firebase_database: ^3.1.0
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
Also, below is my project level my build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.google.gms:google-services:4.3.3'
}
}
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
}
Below is my app level build.gradle
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.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
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.labstabs.riskometer"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.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'
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'
replace with this
classpath 'com.google.gms:google-services:4.2.0'

Android App - using multidex and firebase - app crashes

In my app I'm using a barcode reader from play-services-vision. Because of added firebase messages dependencies, I had to add multidex suppport. But as soon as I add the firebase dependencies, the app crashes on my Galaxy S8 (Andriod 9). When I run the app and like to start the barcode functionality, the ap crashes with a class not found exception:
I did the steps to add multidex and firebase dependency adding step by step, as soon as I add firebase dependency - the crash occurs in the app.
exception:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: info....app, PID: 15574
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/internal/zzsb;
at com.google.android.gms.vision.barcode.internal.client.zzd.zzchw(Unknown Source:13)
at com.google.android.gms.vision.barcode.internal.client.zzd.<init>(Unknown Source:20)
at com.google.android.gms.vision.barcode.BarcodeDetector$Builder.build(Unknown Source:6)
at com.google.android.gms.samples.vision.barcodereader.BarcodeCaptureActivity.createCameraSource(BarcodeCaptureActivity.java:184)
at com.google.android.gms.samples.vision.barcodereader.BarcodeCaptureActivity.onCreate(BarcodeCaptureActivity.java:105)
at android.app.Activity.performCreate(Activity.java:7327)
at android.app.Activity.performCreate(Activity.java:7318)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3094)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7050)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.internal.zzsb" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/info....app-wZywn7WMb4zo51Qz3E_qpg==/base.apk"],nativeLibraryDirectories=[/data/app/info....app-wZywn7WMb4zo51Qz3E_qpg==/lib/arm64, /system/lib64, /system/vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.google.android.gms.vision.barcode.internal.client.zzd.zzchw(Unknown Source:13)
at com.google.android.gms.vision.barcode.internal.client.zzd.<init>(Unknown Source:20)
at com.google.android.gms.vision.barcode.BarcodeDetector$Builder.build(Unknown Source:6)
at com.google.android.gms.samples.vision.barcodereader.BarcodeCaptureActivity.createCameraSource(BarcodeCaptureActivity.java:184)
at com.google.android.gms.samples.vision.barcodereader.BarcodeCaptureActivity.onCreate(BarcodeCaptureActivity.java:105)
at android.app.Activity.performCreate(Activity.java:7327)
at android.app.Activity.performCreate(Activity.java:7318)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3094)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7050)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
build.gradle excerpt:
compileSdkVersion 27
defaultConfig {
applicationId "info....app"
minSdkVersion 16
targetSdkVersion 27
versionCode 101
versionName "1.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.configrelease
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-compat:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
// Important - the CameraSource implementation in this project requires version 8.1 or higher.
implementation 'com.google.android.gms:play-services-vision:9.4.0+'
implementation 'com.android.support:design:27.1.1'
// firebase
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-inappmessaging-display:17.0.4'
}

Flutter - FirebaseApp with name [DEFAULT] doesn't exist

I'm working on a flutter application using firebase authentication system and Firestore. I worked for 3 months and I didn't encounter this error before. Now I published my application on play store and I found this error also for debug version with the emulator. I think to have configured properly the system because firebase worked for a while.
I think that this error occurs for all the apk that I builded after the upgrade of flutter.
Some suggestion to solve my problem?
Thanks
I enter my bundle ID on firebase and download the google-service.json file, copy and paste on android/app folder and build. I also tried to clean (as mentioned here https://github.com/flutter/flutter/issues/28003 ) and build the project and to enter some SHA1 and SHA-256 fingerprints to try if it was this the problem but I'm not sure which SHA1 enter on firebase. ReDownloaded the google-service.json and clean - build the project.
Other codes to initialise the FirebaseApp seems pretty old and I don't think that it can work for me like here (java.lang.IllegalStateException: FirebaseApp with name [DEFAULT]) .
I just authenticate a user using this code
user = await FirebaseAuth.instance
.signInWithEmailAndPassword(email: _email, password: _password);
and do some try catch to manage the output.
android/build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "27.1.1"
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
android/app/build.gradle
android {
compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
applicationId "com.luxywebdesign.pocketstcw"
minSdkVersion 18
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
signingConfigs {
release {
storeFile file("my-release-key.keystore")
storePassword "StorePassword"
keyAlias "KeyAlias"
keyPassword "Password"
}
}
buildTypes {
release {
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
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-core:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
pubspec.yaml
environment:
sdk: ">=2.1.0 <3.0.0"
firebase_storage:
dependencies:
flutter:
sdk: flutter
firebase_auth: 0.8.2
file_picker: ^1.3.3
firebase_storage: ^2.1.0+1
firebase_core: 0.3.1+1
cloud_firestore: ^0.9.7
permission_handler: ^2.2.0
path_provider: ^0.5.0+1
http: ^0.12.0+1
url_launcher: ^5.0.2
open_file: ^2.0.1+2
datetime_picker_formfield: ^0.1.8
share:
git:
url: https://github.com/d-silveira/flutter-share.git
flutter_launcher_icons: ^0.7.0
image_picker: ^0.6.0+1
modal_progress_hud: ^0.1.3
flutter_keychain: ^1.0.0
pdf: ^1.3.7
image: ^2.0.7
flutter_local_notifications: ^0.6.1
auto_size_text: ^2.0.1
shared_preferences: ^0.5.3+1
Error message :
D/FirebaseApp(23461): Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.
at the start after the installation of the apk and ...
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): Failed to handle method call
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common##16.1.0:280)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.getAuth(FirebaseAuthPlugin.java:76)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.onMethodCall(FirebaseAuthPlugin.java:108)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:643)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at android.app.ActivityThread.main(ActivityThread.java:6669)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#plugins.flutter.io/firebase_auth(23461): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I think the problem is you didn't make right the configuration settings. make sure to follow these steps :
Add your google-service.json file
Add apply plugin: 'com.google.gms.google-services' (app-level grade)
Add apply plugin: 'com.android.application' (app-level grade)
Add classpath 'com.google.gms:google-services:4.3.3' (project-level gradle)
After all this steps your problem should be solved. I also had the same problem once then I realise I didn't add step 2. Good Luck!

Flutter: Build failed with an exception

I am trying to use FirebaseAuth in a flutter application. I can use Firestore service but when i include firebase_auth depedency in pubspec.yaml file i got the following exception.
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
* Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get
more log output.
* Get more help at https://help.gradle.org
here is my pubspec.yaml file
dependencies:
flutter:
sdk: flutter
intl: ^0.15.6
#firebase_core: ^0.2.2
google_sign_in:
git:
url: http://github.com/jahirhstu/flutter_plugins.git
path: packages/google_sign_in
#firebase_analytics:
# git:
# url: http://github.com/jahirhstu/flutter_plugins.git
# path: packages/firebase_analytics
firebase_auth:
git:
url: http://github.com/jahirhstu/flutter_plugins.git
path: packages/firebase_auth
cloud_firestore:
git:
url: http://github.com/jahirhstu/flutter_plugins.git
path: packages/cloud_firestore
cupertino_icons: ^0.1.0
shrine_images: 1.0.0
dev_dependencies:
flutter_test:
sdk: flutter
Well, I was trying to solve it and what I did was:
*1.-Reinstall Flutter
2.-Reinstall Dart SDK
3.-Download Gradle 5.1.1
4.-Create a new Application with Firebase and include dependencies
5.-Compile again*
And all of these didnt work.
Then I did:
6.-Copy next lines at the end of gradle.properties
android.useAndroidX=true
android.enableJetifier=true
7.-Changes on file app\build.gradle
android {
compileSdkVersion 28
...
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
...
}
}
8.-Optionally you can add code inside subproject{} in file android\build.gradle
subprojects {
...
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
}
}
}
9.-Go to terminal and launch command
flutter clean
10.-Run your app.
Hope will be helpful
In your Project folder > android > app > build.gradle:
add the following Line in defaultConfig { .... multiDexEnabled true }
try doing this in the /android/app/build.gradle file:
android {
defaultConfig {
// ...
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true
}
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
If none of the above technique works simply downgrade your gradle build level. This will solve your problem.
dependencies {
`classpath` '`com.android.tools.build:gradle:**3.5.0**`'
}

Resources