尝试构建Flutter应用程序时,评估失败

时间:2019-11-22 09:39:30

标签: android gradle flutter

我是如此困住,如果有人可以看一下并尝试帮助我解决问题,我将很乐意。

当我尝试构建或运行Flutter应用程序时,出现此错误

Launching lib\main.dart on SM G973F in debug mode...
Initializing gradle...
Resolving dependencies...
* Error running Gradle:
ProcessException: Process "C:\Users\tbsvst18tedbom\AndroidStudioProjects\tab_truth_true\android\gradlew.bat" exited abnormally:

BUILD FAILED

Total time: 2.766 secs


FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\tbsvst18tedbom\AndroidStudioProjects\tab_truth_true\android\build.gradle' line: 4

* What went wrong:
A problem occurred evaluating root project 'android'.
> Could not find method google() for arguments [] on repository container of type org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  Command: C:\Users\tbsvst18tedbom\AndroidStudioProjects\tab_truth_true\android\gradlew.bat app:properties

Finished with error: Please review your Gradle project setup in the android/ folder.

我已经尽我所能尝试了一切,但是却无所适从。

这是我的应用程序级别的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.0.0'
}

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 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

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

    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"
    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:18.3.0'
}

apply plugin: 'com.google.gms.google-services'  // Google Play services Gradle plugin

这是项目级别的build.gradle文件。

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()

        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.2'
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'
    }


allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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

如您所见,我将google()作为依赖项,但仍然失败。我在这些文件中做错了什么吗? 有人知道该怎么办吗?我真的很乐意提供帮助!

1 个答案:

答案 0 :(得分:0)

  
      
  • 出了什么问题:   评估根项目“ android”时发生问题。
  •   
     

在类型org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler类型的存储库容器中找不到参数[]的google()方法。

从上面的错误日志中可以看到,您在项目级gradle中缺少google依赖项
转到 projectname / android / build.gradle 并添加google依赖项

 repositories {
        google()
        jcenter()

}