将Firebase应用于Android Studio项目版本Bumblebee

3phpmpom  于 2022-12-31  发布在  Android
关注(0)|答案(2)|浏览(103)

我正在尝试添加Firebase SDK,请按照Firebase的步骤指南操作:
enter image description here
但新版Android Studio有一个不同的build.gradle文件,只是:

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

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

我不知道在我的文件中添加代码有多正确。我试过这样做:

buildscript {
    repositories {
        // Check that you have the following line (if not, add it):
        google()  // Google's Maven repository
    }
    dependencies {
        // Add this line
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}
allprojects {
    repositories {
        // Check that you have the following line (if not, add it):
        google()  // Google's Maven repository
    }
}

但这里的日志是:*org.gradle.API. Gradle脚本异常:评估根项目“Uber clone”时出现问题,原因是:用户代码无效异常:构建版本已配置为首选设置存储库而非项目存储库,但存储库“Google”是通过构建文件“build.gradle at build_8l5l0a77l47futp20icywdlc2 $_run_closure2 $_closure3.doCall(D:\Android\Android项目\Uberclone\构建版本.gradle:25)在build_8l5l0a77l47futp20icywdlc2 $_run_closure2. doCall(D:\Android\Android项目\Uberclone\构建版本.gradle:23)在build_8l5l0a77l47futp20icywdlc2. run(D:\Android\Android\Android项目\Uberclone\构建版本.gradle:22)中添加的 *

rsaldnfx

rsaldnfx1#

无需将repositoriesallprojects添加到Gradle文件中,因为这两个文件已经存在于setting.gradle文件中。要解决此问题,只需将其删除,如下所示:

buildscript {
    dependencies {
        // Add this line
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

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

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

tzxcd3kk2#

我通过注解掉settings. gradle中的“dependencyResolutionManagement”部分解决了此问题。
转至Gradle脚本-〉设置。gradle -〉注解掉“依赖关系解决方案管理”

//dependencyResolutionManagement {
//    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
//    repositories {
//        google()
//        mavenCentral()
//    }
//}

然后将所有项目存储库粘贴到Gradle脚本-〉build.gradle -〉将其粘贴到“plugins”部分下方
像这样-

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

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

相关问题