提问人:kapil g 提问时间:1/14/2023 更新时间:1/14/2023 访问量:231
如何将 firebase sdk 添加到最新的 android studio 版本 2022?
How to add firebase sdk to latest android studio version 2022?
问:
我想将 firebase sdk 添加到我用 kotlin 编写的 android studio 项目中
根据 Firebase 网站,它要求添加
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
}
}
但是我在 build.gradle 的 android 中看到的
plugins {
id 'com.android.application' version '7.4.0' apply false
id 'com.android.library' version '7.4.0' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}
文档不是最新的怎么办?
我试图将它与整个buildscript块一起添加到setting.gradle中 我对 buil.gradle 做了同样的事情
答:
0赞
Ajowi
1/14/2023
#1
这是一个相当漫长的过程。首先回顾所需的流程,例如:
- 在Firebase注册;
- 设置 Android 环境(您所在的位置)
- 设置服务器环境(很可能您会需要这个)
对于 android 实现,您可以按照以下步骤操作:https://firebase.google.com/docs/cloud-messaging/android/client
对于服务器端,如果在 PHP 上,您可以遵循以下操作: https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html
但是,特别是针对您的问题:
有两个等级;Build.gradle(project) 和 Build.gradle(Module--app-name) 在模块一中,您的 min-sdk 和 target-sdk 设置位于最顶部,而不是在任何当前设置中,添加以下内容:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
apply plugin: 'com.android.application'
您看到的那个在 project-gradle 中。其中可能还需要一些重新排序。只要确保使用指示的确切方法:项目或应用程序(模块)。我花了一段时间才发现这一点 - 尤其是插件条目的位置。
评论