0

При попытке подключить Firebase к Android проекту вылетает ошибка: "Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'". Путем проверок, я понял, что ошибка выходит из build.gradle в строках

allprojects {
repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
}
}

В строке

google() // Google's Maven repository

При удалении данной строки ошибка не вылетает. Помогите, пожалуйста)

Код build.gradle project

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.3"
        classpath 'com.google.gms:google-services:4.3.10'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    // ...

    repositories {
        // Check that you have the following line (if not, add it):
        google()  // Google's Maven repository
        // ...
    }

}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Код build.gradle app:

    id 'com.android.application'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.photo42"
        minSdk 24
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.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 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

P.S. Изначально в build.gradle не было allprojects{...}. Добавил сам.

1
  • А зачем вам его к Android Studio подключать? Подключите к проекту приложения. Проблема похоже в Gradle, вот тут ищите ответ: stackoverflow.com/a/69794803/5479247 3 ноя 2021 в 22:54

1 ответ 1

0

В новой версии ошибка может заключаться в строках

allprojects {
    // ...

    repositories {
        // Check that you have the following line (if not, add it):
        google()  // Google's Maven repository
        // ...
    }

}

Удалите их из gradle это должно помочь!

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.