Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

all buildscript {} blocks must appear before any plugins {} blocks in the script :8 ~ Android Studio

Ask Question

I am creating an application using Java and connecting the database to Firebase. I am getting this error in the build file. Please help me to solve this error. I can't understand the error message please explain me to solve it. Error 👇👇👇

Build file 'D:\MyWeb\build.gradle' line: 7
Could not compile build file 'D:\MyWeb\build.gradle'.
> startup failed:
  build file 'D:\MyWeb\build.gradle': 7: all buildscript {} blocks must appear before any plugins {} blocks in the script
build.grable(My Web)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '8.0.2' apply false
    id 'com.android.library' version '8.0.2' apply false
buildscript {
    repositories {
        google()  // Google's Maven repository
        mavenCentral()  // Maven Central repository
    dependencies {// Add the dependency for the Google services Gradle plugin
        classpath 'com.google.gms:google-services:4.3.15'
allprojects {
    repositories {// Make sure that you have the following two repositories
        google()  // Google's Maven repository
        mavenCentral()  // Maven Central repository

build.gradle (:app)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '8.0.2' apply false
    id 'com.android.library' version '8.0.2' apply false
buildscript {
    repositories {
        google()  // Google's Maven repository
        mavenCentral()  // Maven Central repository
    dependencies {// Add the dependency for the Google services Gradle plugin
        classpath 'com.google.gms:google-services:4.3.15'
allprojects {
    repositories {// Make sure that you have the following two repositories
        google()  // Google's Maven repository
        mavenCentral()  // Maven Central repository

I'm trying to connect my Android Studio project to Firebase, but I get an error with the build.gradle. Not sure how to fix it.

Simply remove the buildscript{} block and add it on top of plugins{} block, Like this:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()  // Google's Maven repository
        mavenCentral()  // Maven Central repository
    dependencies {// Add the dependency for the Google services Gradle plugin
        classpath 'com.google.gms:google-services:4.3.15'
plugins {
    id 'com.android.application' version '8.0.2' apply false
    id 'com.android.library' version '8.0.2' apply false
allprojects {
    repositories {// Make sure that you have the following two repositories
        google()  // Google's Maven repository
        mavenCentral()  // Maven Central repository

Always remember that buildscript{} block should be on top of plugins{} block.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.