Flutter returns `lifecycle-common-java8.jar (androidx.lifecycle:lifecycle-common-java8:2.0.0)` 错误

Flutter returns `lifecycle-common-java8.jar (androidx.lifecycle:lifecycle-common-java8:2.0.0)` error

Flutter 项目不会 运行 在 Android Studio 中具有 AndroidX 兼容性和 returns 以下 Run/Console window 中的错误:

FAILURE: Build failed with an exception.

FAILURE: Build failed with an exception.

  • What went wrong: A problem occurred configuring root project 'path_provider'. SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

如果您遇到这些错误,请执行以下步骤:

  1. 在 Android Studio 中打开 Android 项目(你可以在 android 路径中打开一个文件或 Class 然后 select Open for Editing interface Android Studio 比如下一张图片)

  1. Build window select错误行然后在右边select Affected Modules:

  1. 对于打开的文件 (build.gradle) 中的每个模块,在 dependencies{} 部分添加 lifecycle-common-java8 api,然后构建项目:

    dependencies {
    ...
    
     api "androidx.lifecycle:lifecycle-common-java8:2.2.0"
    
    }
    

  1. 最后关闭Android项目和运行Flutter项目。