繁体   English   中英

找不到方法颤振()

[英]Could not find method flutter()

我正在尝试在 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

一

打开时没有配置

二

当我尝试添加配置时,没有模块到 select

三

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

笔记:

  1. 使用Sync Project with Gradle Files返回与上述相同的错误
  2. 使用Invalidate Caches也无济于事。
  3. 注释在settings.gradleinclude ':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"
}

您需要更新 build.gradle

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

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

将解决您的 r 问题。

解决了

我已经删除Flutter SDKDart SDK然后从错误中消失。

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

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

android/app/build.gradle

throw new GradleException(“未找到颤振 SDK。在 local.properties 文件中使用 flutter.sdk 定义位置。”)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM