【问题标题】:Could not find method flutter()找不到方法颤振()
【发布时间】:2022-09-25 00:39:03
【问题描述】:

我正在尝试在 macOS 上的 android 模拟器中打开我的应用程序,但出现以下错误

* Where:
Build file \'/Users/home/app_sources/my_app/android/app/build.gradle\' line: 63

* What went wrong:
A problem occurred evaluating project \':app\'.
> Could not find method flutter() for arguments [build_enl1wb3rxbgojqnsmrkb1pqib$_run_closure3@4a124cf3] on project \':app\' of type org.gradle.api.Project.

另外,如果我尝试Open Android module in Android Studio

打开时没有配置

当我尝试添加配置时,没有可供选择的模块

我过去 3 天一直面临这个问题,相信我,我已经尝试了这个网站上的每个主题,关于这个问题的每一篇文章都没有任何效果,所以请不要建议谷歌搜索,因为我已经这样做了很多!

笔记:

  1. 使用Sync Project with Gradle Files 返回与上述相同的错误
  2. 使用Invalidate Caches 也无济于事。
  3. settings.gradle 中评论include \':app\' 并同步,再次取消评论和同步也无济于事。

    任何想法?

    更新

    settings.gradle

    include \':app\'
    
    def localPropertiesFile = new File(rootProject.projectDir, \"local.properties\")
    def properties = new Properties()
    
    assert localPropertiesFile.exists()
    localPropertiesFile.withReader(\"UTF-8\") { reader -> properties.load(reader) }
    
    def flutterSdkPath = properties.getProperty(\"flutter.sdk\")
    assert flutterSdkPath != null, \"flutter.sdk not set in local.properties\"
    apply from: \"$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle\"
    

    android/build.gradle

    buildscript {
        ext.kotlin_version = \'1.6.10\'
        repositories {
            google()
            mavenCentral()
        }
    
        dependencies {
            classpath \'com.android.tools.build:gradle:4.1.3\'
            classpath \"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version\"
        }
    }
    
    allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }
    
    rootProject.buildDir = \'../build\'
    subprojects {
        project.buildDir = \"${rootProject.buildDir}/${project.name}\"
    }
    subprojects {
        project.evaluationDependsOn(\':app\')
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    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.\")
    }
    
    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: \'kotlin-android\'
    apply from: \"$flutterRoot/packages/flutter_tools/gradle/flutter.gradle\"
    
    android {
        compileSdkVersion flutter.compileSdkVersion
    
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    
        kotlinOptions {
            jvmTarget = \'1.8\'
        }
    
        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 \"xxx.xxx.xxx.xxx\"
            minSdkVersion 19
            targetSdkVersion 32
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
        }
    
        buildTypes {
            release {
                // TODO: Add your own signing config for the release build.
                // Signing with the debug keys for now, so `flutter run --release` works.
                signingConfig signingConfigs.debug
            }
        }
    }
    
    flutter {
        source \'../..\'
    }
    
    dependencies {
        implementation \"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version\"
    }
    
  • 嘿,你能分享你的setting.gradlebuild.gradle 应用程序级别和项目级别的文件吗?
  • @Ashutoshsingh 已更新
  • 在这个项目中添加了火力基地?
  • @Ashutoshsingh 没有

标签: android flutter macos dart


【解决方案1】:

您需要更新 build.gradle 从

def localPropertiesFile = rootProject.file('local.properties')

def localPropertiesFile = new rootProject.file('local.properties')

会解决你的问题。

【讨论】:

  • 谢谢,会试试,让你知道
  • 还尝试用setting.gradle 文件中的new 关键字替换这一行,例如def flutterSdkPath = new properties.getProperty("flutter.sdk")
  • 它说startup failed: build file '/Users/home/app_sources/my_app/android/app/build.gradle': 2: unable to resolve class rootProject.filebuild file '/Users/home/app_sources/my_app/android/app/build.gradle': 9: unable to resolve class localProperties.getProperty
【解决方案2】:

解决了

我已经从我的系统中删除了Flutter SDKDart SDK,并且 重新安装它们然后错误就消失了。

PS:我不知道为什么会发生这种情况,或者为什么全新安装解决了这个问题(特别是我安装的版本与这个全新安装的版本相同),但它成功了,这就是我所知道的。

【讨论】:

    【解决方案3】:

    我删除了新的,一切都很好

    android/app/build.gradle

    新的GradleException("未找到 Flutter SDK。在 local.properties 文件中使用 flutter.sdk 定义位置。")

    【讨论】:

      猜你喜欢
      • 2021-06-24
      • 2021-07-04
      • 2020-10-21
      • 2019-05-30
      • 2020-03-11
      • 2020-11-28
      • 2019-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多