【问题标题】:Could not find method flutter() for arguments in Visual Studio Code在 Visual Studio Code 中找不到参数的方法 flutter()
【发布时间】:2020-01-16 18:36:50
【问题描述】:

所以我目前正在尝试为 Google Play 商店构建我的应用程序的 apk。我在使用 android{} 时遇到了类似的错误,我可以通过将apply plugin: 'com.android.application' 向上移动到 android{} 来修复它,并且它已被修复,但后来我收到了这个错误:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/herb/Downloads/morningly/android/app/build.gradle' line: 66

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

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s

我想我必须升级另一个插件apply plugin: 'com.google.gms.google-services'。我尝试移动到第 66 行以上,但仍然遇到同样的错误。现在我在想这可能是 build.gradle 的问题,或者完全不同的东西。请,如果您对如何提供帮助有任何见解,请随时发表评论。我非常想上传我的应用程序。

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'
}

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

   apply plugin: 'com.android.application'
   android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.morningly"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile file(keystoreProperties['storeFile'])
           storePassword keystoreProperties['storePassword']
       }
   }
   buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

android/build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:3.2.1'
    } 
}

allprojects {
    repositories {
        google()
        jcenter()
    }
} 

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}

subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

【问题讨论】:

标签: android gradle flutter dart visual-studio-code


【解决方案1】:

似乎与your question 类似的解决方法,试试这个:

 apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

与以前一样,gradle system 不知道 flutter{} 方法,直到您应用 plugin/filecode

注意

这是一种脚本语言,您可以在其中放置重要内容,逐行解释(无法引用您未告诉系统的内容){Could not find method}。

【讨论】:

    猜你喜欢
    • 2018-11-16
    • 2019-08-02
    • 2020-07-20
    • 2016-07-23
    • 2018-03-26
    • 1970-01-01
    • 2021-06-05
    • 2021-01-08
    相关资源
    最近更新 更多