Fred_Wolfe
Fred_Wolfe

Reputation: 812

FlutterFirebaseCorePlugin.java uses or overrides a deprecated API

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.

Upvotes: 52

Views: 52106

Answers (14)

Priyanshu Sidar
Priyanshu Sidar

Reputation: 146

If you are facing this error means your app has a minSdk of API 20 or lower and your app and the libraries it references exceed 65,536 methods.

These error conditions display a common number: 65536

To learn more about why this error occurs reference the following [Link][1]

[1]: https://developer.android.com/build/multidex#groovy:~:text=Android%20app%20(APK,your%20own%20code.

To fix this you can by changing minSdkVersion to >=21 in app/build.gradle

(This will enabled multidex by default and you don't need the multidex library.)

Otherwise, you can keep minSdkVersion <=20 and modify your app/build.gradle as follows:

    android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 33
        multiDexEnabled true
    }
    ...
}

dependencies {
    implementation "androidx.multidex:multidex:2.0.1"
}

Use latest version of multidex.

If the program asks for enabling multidex, you can do it manually using the following command:

flutter run --debug 

When prompted, enter y.

To learn more about why this error occurs reference the following : https://docs.flutter.dev/deployment/android#enabling-multidex-support

After this you might encounter Unhandled Exception: PlatformException(null-error, Host platform returned null) firebase

To solve this follow the following youtube video guide: https://www.youtube.com/watch?v=Qn2ysnVMvEE

Upvotes: 0

Akash Dubey
Akash Dubey

Reputation: 21

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

Upvotes: 2

3kdeveloper
3kdeveloper

Reputation: 822

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!

Upvotes: 2

jakechakola
jakechakola

Reputation: 1

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

Upvotes: 0

Dilsoz
Dilsoz

Reputation: 101

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

Upvotes: 10

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

Upvotes: 2

Dishant Arora
Dishant Arora

Reputation: 17

Check your minSDK, it works fine for 23

Upvotes: -1

Futurealex
Futurealex

Reputation: 19

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

Upvotes: 0

Louisinator
Louisinator

Reputation: 67

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'

Upvotes: 1

keymistress
keymistress

Reputation: 148

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.

Upvotes: 1

Sangam
Sangam

Reputation: 399

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.

Upvotes: 13

Harshvardhan Joshi
Harshvardhan Joshi

Reputation: 3193

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

Upvotes: 4

Muhammad Sarib
Muhammad Sarib

Reputation: 459

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.

Upvotes: 27

Tasnuva Tavasum oshin
Tasnuva Tavasum oshin

Reputation: 4750

$ flutter pub get

Just Do it in your Terminal it will work

Upvotes: 4

Related Questions