Flutter Android 无法解析类 GradleException @ 第 11 行,第 15 列

Jul*_*Pak 3 android gradle firebase gradlew flutter

由于某种原因,我的项目中出现了 gradle 错误。在应用程序级别 build.gradle 中,我收到此错误Unable to resolve class GradleException @ line 11, column 15.,其中“GradleException”下面有红色波浪线:

if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
Run Code Online (Sandbox Code Playgroud)

vad*_*che 16

有同样的问题。转到 android/app/build.gradle。在此文件的最顶部,您应该看到以下代码。

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
Run Code Online (Sandbox Code Playgroud)

仅从属性和异常行中删除“new”关键字。

def localProperties = Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
Run Code Online (Sandbox Code Playgroud)