6

My Android studio flutter project started giving cannot find symbol errors.

C:\Users\abc\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\firebase_messaging-2.2.0\android\src\main\java\io\flutter\plugins\firebasemessaging\FirebaseMe**ssagingPlugin.java:13: error: cannot find symbol
import androidx.annotation.NonNull;**
                          ^
  symbol:   class NonNull
  location: package androidx.annotation
C:\Users\abc\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\firebase_messaging-2.2.0\android\src\main\java\io\flutter\plugins\firebasemessaging\FirebaseMessagingPlugin.java:14: error: package androidx.localbroadcastmanager.content does not exist
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
                                             ^
C:\Users\abc\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\firebase_messaging-2.2.0\android\src\main\java\io\flutter\plugins\firebasemessaging\FlutterFir**ebaseInstanceIDService.java:9: error: package androidx.localbroadcastmanager.content does not exist
import androidx.localbroadcastmanager.content.LocalBroadcastManager;**

Anyone has an idea what is wrong ?

As suggested by other users I tried to refactor to AndroidX but still getting error even though it is compileSdkVersion 28. I also tried to invalidate cache and restart the android studio.

enter image description here

Gradle.properties gradle.properties

6 Answers 6

19

If you are using cloud_firestore: ^0.9.0 Change the following

pubspec.yaml

Add firebase_core: '^0.3.0' to dependencies

android/build.gradle

Add mavenLocal() to buildscripts.repositories and allprojects.repositories

Add classpath 'com.google.gms:google-services:4.2.0' to buildscript.dependencies

android/grandle.properties

Add android.useAndroidX=true and android.enableJetifier=true

android/app/build.gradle

change compileSdkVersion to 28

change dependencies to

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

Add apply plugin: 'com.google.gms.google-services' at the bottom

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you Eric kim. It resolved my issue. My app is running fine after doing all the steps you told. I also need to update few dependencies like firebase_auth, firebase_messaging etc. Everything is working fine now. However my eclipse is still showing me alert message to change my compileSdk to 28 (Even though it is) in order to refactor to AndroidX....
@Sam I'm not really sure how to solve your issue. You might want to clear Android Studio cache or download a new version. Right now I am using VSCode with flutter plugin.
@Sam Can you please tell which dependencies version especially for firebase_auth you used I am having the same issue. I have tried all this but still getting the same error.
@EricKim Thanks for detailed description. Running flutter clean after making these changed made it work.
1

I had the same error, had to go into my app level android build.gradle file and change the compilesdkversion to 28, then in my gradle.properties file I added android.useAndroidX=true android.enableJetifier=true, I also went through my pubspec file and checked for any updates that had the breaking change to AndroidX and made sure to update those just for safety. Read more about AndroidX

1 Comment

Hi, I tried it but my Android studio still showing me error saying your compileSdkVersion should be at least 28 even though it is 28
1

You need to migrate your project to AndroidX. Please refer change logs for firebase_messaging here. To migrate your project refer this link.

Comments

1

Android made new licenses on 16.01.2019

Go to your terminal: flutter doctor --android-licenses

In Android Studio: Refactor -> Migrate to AndroidX

1 Comment

Hi, i changed the compileSdkVersion 28 and changed the gradle.properties. But when I try to Refactor -> Migrate to AndroidX it shows me error saying change compileSdkVersion to 28 even though it is at 28...
1

In addition to @Eric Kim's answer, make sure you are using minimum supported android build tool version,

classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.51'

Ideally you should use latest version, but the above version is minimum required as of now.

Comments

0

In android/app/build.gradle you should change your compileSdkVersion to:

compileSdkVersion 28

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.