50

Ok so I run my program without importing firebase core, firebase auth and cloud firestore, and my code runs just fine but I register my app with firebase and it still runs fine but as soon as I import Firebase_auth, Firebase_core and cloud_Firestore... I get the following error

Note: C:\appflutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core-0.7.0\android\src\main\java\io\flutter\plugins\firebase\core\FlutterFirebaseCorePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\appflutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.16.0\android\src\main\java\io\flutter\plugins\firebase\firestore\streamhandler\TransactionStreamHandler.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
D8: Cannot fit requested classes in a single dex file (# methods: 89543 > 65536)
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
The number of method references in a .dex file cannot exceed 64K.

Please help me.

dm_tr
  • 4,265
  • 1
  • 6
  • 30
Fred_Wolfe
  • 658
  • 1
  • 7
  • 18

13 Answers13

24

I was having the same problem today and I found the solution here on Github

First, get the latest versions of your dependencies from pub.dev

Current latest versions are these:

  1. firebase_auth: ^0.20.0+1
  2. firebase_core: ^0.7.0

Then run these 3 commands in the terminal:

$ flutter pub upgrade

$ flutter pub get

$ flutter clean

And then run your project

$ flutter run

This will hopefully help you.

Muhammad Sarib
  • 429
  • 4
  • 9
  • 2
    This doesn't work for me. Which Dart SDK do you use? – José Pulido Mar 12 '21 at 06:06
  • 2
    This doesn't help me too. any other solutions please? minSdkVersion 27 targetSdkVersion 30 compileSdkVersion 30 Flutter version 2.2.0 dependencies: firebase_core: ^1.2.0 firebase_messaging: ^10.0.0 flutter_local_notifications: ^5.0.0+4 Error g\firebase_core-1.2.0\android\src\main\java\io\flutter\plugins\firebase\core\FlutterFirebaseCorePlugin.java:71: warning: [deprecation] Registrar in PluginRegistry has been deprecated public static void registerWith(PluginRegistry.Registrar registrar) { – anand May 20 '21 at 17:58
  • This worked for me. When I ran the first three commands I got several errors throughout my project. but with "flutter run" everything has been fixed. Thanks! – Tony_Bielo Oct 01 '21 at 00:14
  • Didn't 100% fix the issue, but taught me some stuff and got me there. Thank you! – Jonathan E. Emmett May 12 '22 at 12:54
13

Seems it is a bug in Firebase plugins: https://github.com/FirebaseExtended/flutterfire/issues/3876. However setting min SDK to 23 does not show the warning.

Sangam
  • 317
  • 2
  • 7
8

it worked for me to change my sdkVersion to 23:

just go to android>app>build.gradle and change the minSdkVersion-line in defaultConfig{} to .. minSdkVersion 23

Dilsoz
  • 81
  • 1
  • 2
4
$ flutter pub get

Just Do it in your Terminal it will work

4

Enable multidex in android project & run again. I am suggesting this according to the last part of the error message you've posted.

According to this guide: https://firebase.flutter.dev/docs/installation/android#enabling-multidex

However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library and make the following modifications to your app project

Harshvardhan Joshi
  • 2,855
  • 2
  • 18
  • 31
  • For mine I was missing this even though I had multiDexEnabled true: `dependencies { implementation 'com.android.support:multidex:1.0.3` }' – cVer Mar 14 '21 at 21:31
2

In android - app - build.gradel file

  1. add - implementation 'com.android.support:multidex:1.0.3' in dependencies section
  2. add - multiDexEnabled true in default config section enter image description here

enter image description here

2

Suffered the error of FlutterFirebaseCorePlugin.java uses or overrides a deprecated API. for two days. finally solved it by changing minSdkVersion to 21 in app/build.gradle and run the app with flutter run --no-sound-null-safety.

Found that the error comes from the sound null safety implementation which grey lists all incompatible API

1

There are two issues here, -Xlint and multidex.

For -Xlint, @Sarib's solution worked for me and both the -Xlint errors disappeared after running flutter pub upgrade, flutter pub get and flutter clean. You can find them under Tools > Flutter in Android Studio if you are not familiar with Terminal.

For multidex, according to the Android Studio User Guide, multidex is enabled by default if your minSdkVersion is 21 or higher. While @Joshi suggests enabling multidex, I think it is simpler to update the minSdkVersion in android/app/build.gradle file to 21 or higher, rather than mess with more variables and adding more dependencies, assuming you're building an app that targets Android21 or higher.

keymistress
  • 138
  • 9
1

For this error:

Note: locationInD\flutter\plugins\firebase\core\FlutterFirebaseCorePlugin.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.

The solution I found was to replace this line in android/app/build.gradle:

implementation 'com.google.firebase:firebase-analytics-ktx'

with

implementation 'com.google.firebase:firebase-analytics'

John
  • 1,018
  • 12
  • 19
  • For me works when i change this and enable multidex https://firebase.flutter.dev/docs/installation/android/#enabling-multidex – wbelarmino Oct 16 '21 at 20:21
0

For me i changed one of my implementation version from implementation platform('com.google.firebase:firebase-bom:27.1.0') to

implementation platform('com.google.firebase:firebase-bom:26.6.0') at the moment there are some bugs in this current version "27.1.0" and after running the application it worked

//To help someone my project needed this implementation for my ads #admob

Futurealex
  • 9
  • 1
  • 2
0

change to minSdkVersion 24 in android/app/build.gradle

dependencies {
//add this in your dependencies
    implementation "androidx.multidex:multidex:2.0.0"
}

then

$ flutter clean
$ flutter run
0

I had the same issue and combined two suggested fixes to get it to finally work:

minSdkVersion 21, change to 23 run "flutter pub upgrade" = issues fixed!

To double-check what the fix was:

I also reverted back to 21 and invalidated + flutter clean and the issue appeared again. Then I changed to 23 and the warnings disappeared!

kamran khan
  • 597
  • 3
  • 10
-1

Check your minSDK, it works fine for 23