Моя сборка настроена на настройку репозиториев над репозиториями проекта, репозиторий «Google» был добавлен файлом сборки build.gradle

Я устал использовать ответ (ы) на другой вопрос, подобный моему здесь, но я не понимаю и не думаю, что это отвечает на мой вопрос Сборка была настроена так, чтобы предпочесть репозитории настроек репозиториям проекта, но репозиторий «Google» был добавлен файлом сборки «build.gradle». Я использую последнюю версию Android Studio.

Вот мой проект build.gradle

 // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        // Make sure that you have the following two 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.13'

    }
}

allprojects {
    repositories {
        // Make sure that you have the following two repositories
        google()  // Google's Maven repository

        mavenCentral()  // Maven Central repository

    }
}
plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
}

и вот мой модуль build.gradle

    plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
}

android {
    namespace 'com.example.destination'
    compileSdk 32

    defaultConfig {
        applicationId "com.example.destination"
        minSdk 17
        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.5.1'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation platform('com.google.firebase:firebase-bom:31.1.1')
    implementation 'com.google.firebase:firebase-analytics'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    classpath 'com.android.tools.build:gradle:7.3.1'
}

и, наконец, вот мой код settings.gradle (настройки проекта)

    pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    //repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "Destination"
include ':app'

Если есть решение, не могли бы вы дать мне пошаговое описание, как это сделать, пожалуйста, поскольку я никогда не делал этого раньше. Я пытаюсь добавить Firebase в свое приложение

Скорее всего этот ответ поможет.

Alex Mamo 11.01.2023 14:10
1
1
151
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Вы настроили его на сбой при добавлении репо в проекты build.gradle:

    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

а затем вы добавляете google() в свой корневой (проект) файл build.gradle здесь:

allprojects {
    repositories {
        google() 
        mavenCentral() 

    }
}

^ удалить это

потому что в вашем settings.gradle вы все равно объявляете их здесь:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 
    repositories {
        google()    // no need to declare this in `allProjects` if its declared here 
        mavenCentral()
    }
}

Другие вопросы по теме