android - 找不到参数的方法 android()...flutter.gradle 问题
问题描述
我尝试实施 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'
解决方案
推荐阅读
- android - Android - 媒体扫描仪不适用于 api 28-29
- linux - 无法删除文件 - 终端将文件名拆分为两个
- bash - 如果命令开头包含某个单词,如何给命令起别名
- amazon-web-services - 如何在定制的 TCP 应用程序中编写 AWS ELB 运行状况检查代码?
- node.js - 无法连接到 Azure Cosmosdb 中的 Mongdb
- c# - Selenium Webdriver 3.141.0 driver.Manage().Logs.AvailableLogTypes 抛出 System.NullReference 异常
- zap - 如何在 OWASP ZAP 中进行自动扫描时传递用户名和密码
- react-native - 使用状态值更新操作表标题
- java - 如何使用 Java 和 PostgreSQL 执行 \d tablename
- properties - Ansible-从属性文件中删除多行属性