简体   繁体   English

将 firebase 依赖项添加到 android 应用程序时,应用脚本 build.gradle 错误

[英]Apply script build.gradle error when adding firebase dependencies to an android app

I am adding firebase to my android application.我将 firebase 添加到我的 android 应用程序中。 After adding dependecies classpath 'com.google.gms:google-services:4.3.0' and implementation 'com.google.firebase:firebase-database:18.0.1' and plugins that is apply plugin: 'com.google.gms.google-services' and trying to sync it brings an "Apply script build.gradle" error添加依赖classpath 'com.google.gms:google-services:4.3.0'和实现'com.google.firebase:firebase-database:18.0.1'和应用plugin: 'com.google.gms.google-services'并尝试同步它会带来“应用脚本 build.gradle”错误

I have updated my google repositories and have a good internet connection我已经更新了我的谷歌存储库并且有良好的互联网连接

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

dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
        classpath 'com.google.gms:google-services:4.3.0'}`
dependencies{implementation 'com.google.firebase:firebase-database:18.0.1'}

I expected a successful sync after adding the dependencies and applying plugins but an error occured我希望在添加依赖项和应用插件后成功同步,但发生错误

Check the doc:检查文档:

To setup firebase you have to configure the top-level build.gradle file with:要设置 firebase,您必须使用以下命令配置顶级build.gradle文件:

buildscript {

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

  dependencies {
    // ...

    // Add the following line:
    classpath 'com.google.gms:google-services:4.3.0'  // Google Services plugin
  }
}

allprojects {
  // ...

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

Then in your app/build.gradle :然后在你的app/build.gradle

apply plugin: 'com.android.application'

android {
  // ...
}

dependencies {
  // ...
  implementation 'com.google.firebase:firebase-database:18.0.1'

}

// Add the following line to the bottom of the file:
apply plugin: 'com.google.gms.google-services'  // Google Play services Gradle plugin

To complete the setup of the google play services plugin you have to要完成谷歌播放服务插件设置,你必须

  • add the google-services.json file.添加google-services.json文件。

For Latest android studio, you can add library like below对于最新的 android 工作室,您可以添加如下库

plugins {
    id 'com.android.application' version '7.2.0' apply false
    id 'com.android.library' version '7.2.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
    id 'com.google.dagger.hilt.android' version '2.43.2' apply false
    id 'androidx.navigation.safeargs.kotlin' version '2.4.1' apply false

    
    id 'com.google.gms.google-services' version '4.3.10' apply false 
    id 'com.google.firebase.crashlytics' version '2.8.1' apply false
}

settings.gradle设置.gradle

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}
rootProject.name = "GameShow"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 build.gradle 中没有 firebase 的方法 - No methods for firebase in build.gradle 在 Android Studio 中为 firebase Flutter 生成 SHA1 密钥时出现 Build.gradle 错误 - Build.gradle error while Generating SHA1 key for firebase Flutter in Android Studio build.gradle需要加Firebase分析吗? - Is it required to add Firebase Analytics to build.gradle? 在 Android 中添加 Firebase Crashlytics 时生成同步错误 - Build sync error while adding Firebase Crashlytics in Android Android Studio 构建错误:Gradle - 找不到平台('com.google.firebase:firebase-bom:30.3.1') - Android Studio build error: Gradle - Could not find platform('com.google.firebase:firebase-bom:30.3.1') 我的 flutter 应用程序 android build.gradle 文件没有默认配置和应用程序 ID - My flutter application android build.gradle file does not have Default config and application ID 错误:无法解析 Android 应用程序模块的 Gradle 配置。 解析或重新同步(构建 gradle 应用程序中没有存储库) - Error: Could not parse the Android application Module's Gradle Config. Resolve or resync (no repositories in build gradle app) “找不到 ID 为‘io.fabric’的插件”错误。 从 build.gradle 中取出织物后 - "Plugin with id 'io.fabric' not found" error. after removing fabric from build.gradle 我的构建配置为在项目存储库上设置存储库,build.gradle 构建文件添加了存储库“Google” - My build is configured to settings repositories over project repositories, repository ‘Google’ was added by build.gradle build file 到达“安装依赖项”时 EAS 构建错误 - EAS build error when reaching "install dependencies"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM