无法获取 org.gradle.api.Project 类型的项目“:app”的未知属性“flutterRoot”

ham*_*ace 5 android dart android-studio flutter

我一直在寻找此错误的解决方案,但没有找到任何解决方案。我有一个 flutter 项目,在尝试构建要发布的 apk 时,我不断在 app/build.gradle 文件中收到此错误。

Could not get unknown property 'flutterRoot' for project ':app' of type org.gradle.api.Project.
Run Code Online (Sandbox Code Playgroud)

下面是我的构建 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 FileNotFoundException ("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
println keystorePropertiesFile
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 30

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.develpment.sported_app"
        minSdkVersion 23
        targetSdkVersion 30
        multiDexEnabled true
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }

    buildTypes {
        release {
            release {
                signingConfig signingConfigs.debug
            }
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "com.android.support:multidex:1.0.3"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
Run Code Online (Sandbox Code Playgroud)

我的密钥库属性似乎有问题。我想知道哪里出了问题。我尝试过使缓存无效并重新启动,但似乎没有任何效果。

bel*_*tas 0

在命令行中运行env并检查是否有FLUTTER_ROOT变量。如果没有自己设置。