如何修复 android 工作室同步 Gradle 时出现的 'Cannot invoke method buildTypes()' 错误?

How to fix 'Cannot invoke method buildTypes()' error in the android studio while it is syncing the Gradle?

我记得我没有在我的 Gradle 中编辑任何东西,突然我意识到我无法再同步项目 Gradle, 向我显示此错误:
ERROR: Cannot invoke method buildTypes() on null object

我在 Whosebug 中搜索了我的问题并找到了一些类似的问题,但 none 对我有用

这是我的 Gradle:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        //noinspection GradleDynamicVersion
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'


repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 27
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId "com.myapp.test"
        minSdkVersion 18
        targetSdkVersion 27

        //todo: change the versionCode and the versionName before upload in store
        versionCode 22
        versionName "2.4.0"
        aaptOptions {
            additionalParameters "--no-version-vectors"
        }

    } buildTypes {
        release {

            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    //noinspection GradleCompatible
    implementation 'com.google.firebase:firebase-core:17.0.1'

    implementation fileTree(include: ['*.jar'], dir: 'libs')


    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:support-vector-drawable:27.1.1'
    implementation 'com.google.firebase:firebase-crash:16.2.1'
    testImplementation 'junit:junit:4.12'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
    implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
    implementation 'agency.tango.android:material-intro-screen:0.0.5'
    implementation ('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
        transitive = true
    }
    implementation ('com.crashlytics.sdk.android:crashlytics:2.9.2@aar') {
        transitive = true
    }
    implementation ('com.crashlytics.sdk.android:crashlytics-ndk:2.0.4@aar') {
        transitive = true
    }

}
crashlytics {
    enableNdk true
    androidNdkOut 'src/main/obj'
    androidNdkLibsOut 'src/main/libs'
}

我不知道如何修复它,所以我需要你的帮助。

buildTypes 语句移至下一行。

使用

} 
buildTypes {

而不是

} buildTypes {