Java 无法解析:com.google.firebase:firebase-core:16.0.1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50586177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to resolve: com.google.firebase:firebase-core:16.0.1
提问by Louise L.
I'm trying to add firebase cloud storage to my app. Below is the app build.gradle. But it says: Failed to resolve: com.google.firebase:firebase-core:16.0.1. Why? There is no firebase-core in the dependencies at all.
我正在尝试将 firebase 云存储添加到我的应用程序中。下面是应用程序 build.gradle。但它说:无法解析:com.google.firebase:firebase-core:16.0.1。为什么?依赖项中根本没有 firebase-core。
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.louise.udacity.mydict"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.cloud:google-cloud-storage:1.31.0'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
}
apply plugin: 'com.google.gms.google-services'
采纳答案by Peter Haddad
From the docs:-
从文档: -
Your app gradle file now has to explicitly list
com.google.firebase:firebase-core
as a dependency for Firebase services to work as expected.
您的应用程序 gradle 文件现在必须明确
com.google.firebase:firebase-core
列为 Firebase 服务的依赖项才能按预期工作。
Add:
添加:
implementation 'com.google.firebase:firebase-core:16.0.1'
and in top level gradle file use the latest version of google play services:
并在顶级 gradle 文件中使用最新版本的 google play 服务:
classpath 'com.google.gms:google-services:4.0.2'
https://firebase.google.com/support/release-notes/android
https://firebase.google.com/support/release-notes/android
https://bintray.com/android/android-tools/com.google.gms.google-services
https://bintray.com/android/android-tools/com.google.gms.google-services
Note:
笔记:
You need to add the google()
repo in the top level gradle file, as specified in the firebase docs and also it should be before jcenter()
:
您需要google()
在顶级 gradle 文件中添加repo,如 firebase 文档中所述,并且它应该在之前jcenter()
:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
回答by bra_racing
Since May 23, 2018 update, when you're using a firebase dependency, you must include the firebase-core
dependency, too.
自2018年5 月 23 日更新以来,当您使用 firebase 依赖项时,您也必须包含该firebase-core
依赖项。
If adding it, you still having the error, trying to update the gradle plugin in your gradle-wrapper.properties
to 4.5 version:
如果添加它,您仍然遇到错误,尝试将您的 gradle 插件更新gradle-wrapper.properties
到 4.5 版本:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
and resync the project.
并重新同步项目。
回答by Salim Lachdhaf
I get the same issue and i solved it by replacing :
我遇到了同样的问题,我通过替换解决了它:
implementation 'com.google.firebase:firebase-core:16.0.1'
to
到
implementation 'com.google.firebase:firebase-core:15.0.2'
and everything solved and worked well.
一切都解决了并且运行良好。
回答by HaRsh Rathi
I was able to solve the issue by following these steps-
我能够按照以下步骤解决问题-
1.) This error occurs when you didn't connect your project to firebase. Do that from Tools->Firebaseif you are using Android studio version 2.2 or above.
1.) 当您没有将项目连接到 firebase 时会发生此错误。如果您使用的是 Android Studio 2.2 或更高版本,请从Tools->Firebase执行此操作。
2.) Make sure you have replaced the compile
with implementation
in dependencies in app/build.gradle
2.) 确保你已经compile
用implementation
in替换了dependencies in app/build.gradle
3.) Include your firebase dependency from the firebase docs. Everything should work fine now
3.) 从 firebase 文档中包含您的 firebase 依赖项。现在一切正常
回答by Andy
Add maven { url "https://maven.google.com" } to your root level build.gradle file
将 maven { url " https://maven.google.com" } 添加到您的根级 build.gradle 文件中
repositories {
maven { url "https://maven.google.com" }
flatDir {
dirs 'libs'
}
}
回答by E-max
This is rare, but there is a chance your project's gradle offline mode is enable, disable offline mode with the following steps;
这种情况很少见,但有可能您的项目的 gradle 离线模式已启用,请按照以下步骤禁用离线模式;
- In android studio, locate the file tab of the header and click
- In the drop own menu, select settings
- In the dialog produced, select "Build, Execution, Deploy" and then select "Gradle"
- Finally uncheck the "offline work" check box and apply changes
- 在android studio中,找到header的file选项卡,点击
- 在下拉菜单中,选择设置
- 在生成的对话框中,选择“构建、执行、部署”,然后选择“Gradle”
- 最后取消选中“离线工作”复选框并应用更改
If this doesn't work leave a comment describing your Logcat response and i'll try to help more.
如果这不起作用,请发表评论描述您的 Logcat 响应,我会尽力提供更多帮助。
回答by DeadStar
In my case it was resolved by changing the compileSdkVersion and targetSdkVersion from 26 to 27
就我而言,它是通过将 compileSdkVersion 和 targetSdkVersion 从 26 更改为 27 来解决的
回答by DIEGO FEDER
What actually was missing for me and what made it work then was downloading'Google Play services' and 'Google Repository'
我真正缺少的是下载“Google Play services”和“Google Repository”
Go to: Settings -> Android SDK -> SDK Tools -> check/install Google Play services + repository
转到:设置 -> Android SDK -> SDK 工具 -> 检查/安装 Google Play 服务 + 存储库
Hope it helps.
希望能帮助到你。
回答by Louis CAD
If you use Firebase in a library module, you need to apply the google play services gradle plugin to it in addition to the app(s) module(s), but also, you need to beware of version 4.2.0 (and 4.1.0) which are broken, and use version 4.0.2 instead.
如果您在库模块中使用 Firebase,除了应用模块之外,您还需要将 google play services gradle 插件应用到它,而且,您还需要提防 4.2.0(和 4.1.1.2)版本。 0) 已损坏,请改用 4.0.2 版。
Here's the issue: https://github.com/google/play-services-plugins/issues/22
这是问题所在:https: //github.com/google/play-services-plugins/issues/22
回答by kaushal
As @Peter Haddad mentioned above,
正如@Peter Haddad 上面提到的,
To fix this issue I followed Google firebase integration guidelines and did the following changes in my app/build.gradle and project/build.gradle
为了解决这个问题,我遵循了 Google firebase 集成指南,并在我的 app/build.gradle 和 project/build.gradle 中做了以下更改
Follow below mentioned link if you have any doubts
如果您有任何疑问,请按照下面提到的链接
https://firebase.google.com/docs/android/setup
https://firebase.google.com/docs/android/setup
changes in app/build.gradle
app/build.gradle 中的变化
implementation 'com.google.android.gms:play-services-base:15.0.2'
implementation "com.google.firebase:firebase-core:16.0.1"
implementation "com.google.firebase:firebase-messaging:17.4.0"
Changes in Project/build.gradle
Project/build.gradle 中的变化
repositories {
google()
jcenter()
mavenCentral()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:4.2.0'// // google-services plugin it should be latest if you are using firebase version 16.0 +
}
allprojects {
repositories {
google()// add it to top instead of bottom or somewhere in middle
mavenLocal()
mavenCentral()
maven {
url 'https://maven.google.com'
}
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}