I am trying firebase for my app but when I put the necessary scripts/plugins and sync it. It gives me an error for my project gradle file:
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
my project build.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
}
}
my build.gradle app:
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'
}
but when I put the plugin in the middle it gives me an other error:
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
script:
// 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
}
}
does anyone have an idea, it would be very much appreciated! Thanks in Advance!
CodePudding user response:
Remove all the buildscript
block in the top level file and add in the plugins
the google-services plugin:
plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
id 'com.google.gms.google-services' version '4.3.13' apply false
}