[英]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我希望在添加依赖项和应用插件后成功同步,但发生错误
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要完成谷歌播放服务插件的设置,你必须
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.