android - 找不到参数的方法 android() ... flutter.gradle 问题

标签 android gradle flutter

我尝试实现 Google 针对“将 Firebase 添加到您的应用程序”的建议更改,其中指出:

The Google services plugin for Gradle loads the google-services.json file you just downloaded. Modify your build.gradle files to use the plugin.
Project-level build.gradle (<project>/build.gradle):

buildscript {
  dependencies {
    // Add this line
    classpath 'com.google.gms:google-services:4.0.1'
  }
}

App-level build.gradle (<project>/<app-module>/build.gradle):

dependencies {
  // Add this line
  implementation 'com.google.firebase:firebase-core:16.0.1'
}
...
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

但是在进行这些更改后(尽管针对当前版本进行了更新,即:服务现在是 4.2.0,核心现在是 16.0.9)我在尝试运行应用程序时遇到以下错误:

* Error running Gradle:
ProcessException: Process "X:\Projects\Apps\Flutter\ultimate_mtg\android\gradlew.bat" exited abnormally:

FAILURE: Build failed with an exception.

* Where:
Script 'X:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 29

* What went wrong:
A problem occurred evaluating script.
> Could not find method android() for arguments [flutter_btx813u5j2ly3w9khjl576b0k$_run_closure1@6f90a486] on project ':app' of type org.gradle.api.Project.

它在这个阶段出现在 flutter SDK 中。这是我的 flutter.gradle 文件(提取):

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'
    }
}

android {
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
}

第29行是这一行:

android {

有人对此有任何想法吗?我已经阅读了许多关于此的类似主题,但没有任何建议对我有用。

有关附加信息,我的\build.gradle 文件:

buildscript {
    repositories {
        google()
        jcenter()
    }

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

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
}

还有我的\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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

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

    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 'com.google.firebase:firebase-core:16.0.9'
    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'
    implementation 'com.google.firebase:firebase-ads:17.2.0'
}


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

最佳答案

尝试将 'com.android.application' 移动到插件配置中顺序的顶部。这似乎需要首先进行,类似于此 answer 中提到的内容.

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

尽管如今,您可以使用 flutterfire_cli将您的应用配置为使用 Firebase。

关于android - 找不到参数的方法 android() ... flutter.gradle 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56125140/

相关文章:

Android获取设备方向

android - ndk-build 不编译 lib.so 文件

dart - Flutter Row 主轴对齐不起作用

flutter - 方法 'MultiTrackTween' 没有为类型 'FadeAnimation' 定义

安卓: "Class loader may fail for processes that host multiple applications"

java - 防止 Android One 设备中的屏幕捕获

JavaFX Gradle 构建错误,java.util.zip.ZipException : duplicate entry: META-INF/LICENSE

c++ - C++构建顺序?

jenkins - 我在 Jenkins 上运行时显示gradle错误

flutter - 如何在 flutter 桌面中自定义 AppMenu(MenuBar)?