`Unresolved reference: android` on new Flutter project

Viewed 21412

My first Flutter app seems to be debugging okay so far on my phone, but all of a sudden I'm seeing this error in my android/app/src/main/kotlin/my.appname.whatever/MainActivity file (screenshot below).

And when I rollover the onCreate, it shows this: Cannot access class 'android.Os.Bundle'. Check your module classpath for missing or conflicting dependencies.

I'm using AndroidStudio 3.2.1

While trying to get Firebase going, I changed the version of this (it was 1.2.17 I think, but had a warning about it being different than the IDE, so I changed it to what it suggested and the warning went away). Even after trying to change it back, I'm still getting the warning below.

buildscript { ext.kotlin_version = '1.3.11'

I assume this is something simple, but for someone very new to Android/Flutter...etc, I just don't have a clue where to look for the Unresolved reference: android, nor have any idea what I did to make it show up.

error

6 Answers

In my case, File -> Invalidate Caches / Restart worked. When Android Studio started back up, the issue was gone. Doesn't really answer the "why", but... it worked.

Configure to the project SDK to the appropriate API level as per your project will solve your issue(shown in the dialog after clicking Setup SDK at right corner).

enter image description here

For the "Unresolved reference: android” Issue.

It occurs because the project is not able to configure the Android SDK.

Go to File-> Project Structure -> Project SDK [Set the correct SDK as per your project]

And then,

ReSync the project. (Invalidate caches and restart, if required)

There are a few things you can try:

open Android directory of your flutter project in android studio(new window). Then

  1. go to Build and select clean project. Then after this select Rebuild project.
  2. If above step doesn't solves your problem then go to file -> open -> select build.gradle to reopen and get the dependencies of project.
  3. go to project root directory and try flutter clean command this would clean the build/ and then try running your project by flutter run command.

Hope it helps:)

I managed to solve the problem by updating my Gradle version to the latest one (via Andorid studio), changing the ext.kotlin_version to 1.3.11 at build.grade(Project: android), and updating the SDK at Tools/SDK Manager/Edit

If you are still facing Issues like

Unresolved reference: NonNull or Unresolved reference: annotation then you should add a dependency to have access to the classes inside android.support.annotation Inside your dependencies in your build.gradle, you should add com.android.support:support-annotations:28.0.0, something like this:

dependencies {
    implementation 'com.android.support:support-annotations:28.0.0'
}
Related