Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Android studio build failing

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

like image 527
Sam Avatar asked Jan 26 '19 02:01

Sam


2 Answers

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

like image 195
Eric Kim Avatar answered Oct 10 '22 13:10

Eric Kim


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

like image 24
AustinNaz Avatar answered Oct 10 '22 13:10

AustinNaz