在添加Firebase的类路径依赖时发生问题



添加Firebase类路径依赖时出现问题

这是我的Gradle。项目文件

plugins {
id "com.android.application" version "7.3.1" apply false
id "com.android.library" version "7.3.1" apply false
id "com.google.gms.google-services" version "4.3.14" apply false
}
dependencies {
// Add the dependency for the Google services Gradle plugin
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.google.gms:google-services:4.3.14'
}

我的Gradle Module文件

plugins {
id 'com.android.application'
}
apply plugin: 'com.google.gms.google-services'
android {
namespace 'com.example.anonymous'
compileSdk 32
defaultConfig {
applicationId "com.example.anonymous"
minSdk 19
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation platform('com.google.firebase:firebase-bom:31.1.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.airbnb.android:lottie:5.2.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'
}

在同步Gradle时,我得到了这个错误

在org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

无法找到参数[com.android.tools.build:gradle:7.3.1]的方法classpath()

您的构建。Gradle(项目)文件应该像这样:

buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.google.gms:google-services:4.3.14'
}
}
plugins {
id "com.android.application" version "7.3.1" apply false
id "com.android.library" version "7.3.1" apply false
id "com.google.gms.google-services" version "4.3.14" apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}

所有buildscript {}块必须出现在脚本中的plugins {}块之前。

最新更新