我正在为我的应用程序尝试firebase,但当我把必要的脚本/插件和同步它。它给了我一个错误,我的项目gradle文件:
Build file 'D:\UCLL\3de jaar\app_Comic\build.gradle' line: 6
Could not compile build file 'D:\UCLL\3de jaar\app_Comic\build.gradle'.
> startup failed:
build file 'D:\UCLL\3de jaar\app_Comic\build.gradle': 6: all buildscript {} blocks must appear before any plugins {} blocks in the script
我项目建筑。Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
}
buildscript {
repositories {
google()
mavenCentral() // Maven Central repository
}
dependencies {
classpath 'com.google.gms:google-services:4.3.13'
}
}
allprojects {
repositories {
google()
mavenCentral() // Maven Central repository
}
}
我builder.gradle应用程序:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
namespace 'com.example.mowmow'
compileSdk 32
defaultConfig {
applicationId "com.example.mowmow"
minSdk 21
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'
}
}
buildFeatures {
viewBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
//picasso
implementation 'com.squareup.picasso:picasso:2.8'
//ToStringBuilder
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
//Firebase/google
implementation 'com.google.firebase:firebase-analytics'
}
但是当我把插件放在中间时,它给了我另一个错误:
Build file 'D:\UCLL\3de jaar\app_Comic\build.gradle' line: 18
A problem occurred evaluating root project 'app_Comic'.
> Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'app_Comic'. <87 internal lines>
at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:116)
at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:42) <82 internal lines>
Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle' <11 internal lines>
at jdk.internal.reflect.GeneratedMethodAccessor153.invoke(Unknown Source) <6 internal lines>
at build_63utr2332008u9gjv762bsg3t$_run_closure1$_closure2.doCall(D:\UCLL\3de jaar\app_Comic\build.gradle:18) <18 internal lines>
at build_63utr2332008u9gjv762bsg3t$_run_closure1.doCall(D:\UCLL\3de jaar\app_Comic\build.gradle:17)<47 internal lines>
at build_63utr2332008u9gjv762bsg3t.run(D:\UCLL\3de jaar\app_Comic\build.gradle:16)<1 internal lines>
... 170 more
脚本:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral() // Maven Central repository
}
dependencies {
classpath 'com.google.gms:google-services:4.3.13'
}
}
plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
}
allprojects {
repositories {
google()
mavenCentral() // Maven Central repository
}
}
有没有人有一个想法,这将是非常感谢!提前感谢!
1条答案
按热度按时间bis0qfac1#
删除顶层文件中的所有
buildscript
块,并在plugins
中添加google-services插件: