`Unresolved reference: android` on new Flutter pro

2020-07-06 07:07发布

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条回答
Luminary・发光体
2楼-- · 2020-07-06 07:29

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:)

查看更多
We Are One
3楼-- · 2020-07-06 07:37

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)

查看更多
叼着烟拽天下
4楼-- · 2020-07-06 07:39

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.

查看更多
老娘就宠你
5楼-- · 2020-07-06 07:43

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

查看更多
smile是对你的礼貌
6楼-- · 2020-07-06 07:45

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

查看更多
趁早两清
7楼-- · 2020-07-06 07:56

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'
}
查看更多
登录 后发表回答