【问题标题】:Apply Firebase to Android Studio Project version Bumblebee将 Firebase 应用于 Android Studio 项目版本 Bumblebee
【发布时间】:2022-12-31 03:44:24
【问题描述】:

我正在尝试添加 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.GradleScriptException:评估根项目“Uber clone”时出现问题 由以下原因引起:org.gradle.api.InvalidUserCodeException:构建被配置为更喜欢设置存储库而不是项目存储库,但是构建文件“build.gradle”添加了存储库“Google” 在 build_8l5l0a77l47futp20icywdlc2$_run_closure2$_closure3.doCall(D:\Android\AndroidProjects\Uberclone\build.gradle:25) 在 build_8l5l0a77l47futp20icywdlc2$_run_closure2.doCall(D:\Android\AndroidProjects\Uberclone\build.gradle:23) 在 build_8l5l0a77l47futp20icywdlc2.run(D:\Android\AndroidProjects\Uberclone\build.gradle:22)

【问题讨论】:

    标签: android firebase gradle build.gradle


    【解决方案1】:

    无需在 Gradle 文件中添加 repositoriesallprojects。这是因为两者都已存在于 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
    }
    

    【讨论】:

    • 哦。多谢。你真好我已经修好了
    【解决方案2】:

    我通过注释掉 settings.gradle 中存在的“dependencyResolutionManagement”部分解决了这个问题。

    转到 Gradle Scripts -> settings.gradle -> 注释掉 'dependencyResolutionManagement'

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

    然后将所有项目存储库粘贴到 Gradle Scripts -> build.gradle -> 将其粘贴到“插件”部分下方

    像这样-

    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
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-13
      • 1970-01-01
      • 2022-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多