android - 在 Android Studio 上设置 Firebase
问题描述
我正在尝试在我的 android studio 上设置 firebase。我使用的是 2.2.3 版本。所以这是我在 app.gradle 文件中的代码:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.parth.carpool"
minSdkVersion 22
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-a`enter code here`nnotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.google.firebase:firebase-core:16.0.1'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
这是我收到的错误。
Error:(27, 13) Failed to resolve: com.google.firebase:firebase-core:16.0.1
这是我的 project.gradle 文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
为了纠正这个错误,我在看到 stackoverflow 上的一些帖子后安装了谷歌播放服务、谷歌存储库、SDK 平台、SDK 平台工具等。有人有解决方案吗?
解决方案
首先你需要将android studio升级到最新版本:
如果您没有使用 Android Studio 3.1 来开发您的应用程序,则需要升级才能在 IDE 中获得正确的版本检查行为。
https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html
然后您需要使用以下顶级 gradle 文件:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
推荐阅读
- python - 如何比较两个列表中的单词并使用python将匹配的单词提取为单独的列表
- android - 工作完成后进度条变为可见
- google-apps-script - 我们可以在不使用谷歌脚本中的 onEdit() 触发器的情况下获取单元格的旧值吗?
- php - php添加多个上传表单
- flutter - Flutter/dart:如何处理自定义 url 方案回调
- java - 我怎么知道使用构造函数解决
- scala - 未找到 Scala 导入
- odk - 随机化 XLSForm 中问题的文本
- ios - 无法创建显式 AppID,该 AppID 用作带有通配符标识符的应用程序 bundleId 为 iOS 应用程序提供配置文件
- django - 在 Django 中重置密码电子邮件