错误:在将Firebase Storage依赖项添加到Android Studio Project中?

时间:2018-06-29 11:35:05

标签: android firebase firebase-realtime-database google-cloud-firestore

我已经在Android Studio中创建了一个Firestore项目。我在其中实施了Firebase授权,并且工作正常。我可以将文档推送到Firestore数据库。

但是现在,我试图添加一些功能,通过这些功能可以将媒体/图像存储到Firebase Storage,但是当我将此依赖项添加到应用程序的build.gradle文件中时,却出现此错误:

添加了依赖性:

implementation 'com.google.firebase:firebase-storage:16.0.1'

这是我得到的错误:

Could not find firebase-common.jar (com.google.firebase:firebase-common:16.0.0).
Searched in the following locations:https://jcenter.bintray.com/com/google/firebase/firebase-common/16.0.0/firebase-common-16.0.0.jar

仅供参考,在我的项目中,我已经有这种配置:

classpath 'com.android.tools.build:gradle:3.1.3'

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

当我仅将firebase-storage依赖项添加到我的Android项目中时,我找不到问题所在。

这是我的应用程序级别的build.gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.firebase.example"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
}

dependencies {
    implementation 'com.google.firebase:firebase-firestore:16.0.0'
    implementation 'com.google.firebase:firebase-auth:15.1.0'
    implementation 'com.google.firebase:firebase-storage:16.0.1'

    implementation 'com.google.android.gms:play-services-auth:15.0.1'

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:appcompat-v7:23.2.1'
    implementation 'com.android.support:design:23.2.1'
    implementation 'com.android.support:recyclerview-v7:23.2.1'
}
apply plugin: 'com.google.gms.google-services'

这是我的模块级别的build.gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:4.0.1' // google-services plugin
        classpath 'com.google.android.gms:play-services-base:15.0.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

5 个答案:

答案 0 :(得分:0)

您是否已将它们添加到根级别gradle文件中?

buildscript {

    dependencies {

        classpath 'com.google.gms:google-services:4.0.1' 
    }
}

allprojects {

    repositories {

        google() 
    }
}

答案 1 :(得分:0)

您必须在根级别的build.gradle文件中添加dependencies {classpath 'com.google.gms:google-services:4.0.1'}repositories { google()}。你加了吗?此外,请提供整个build.gradle文件,以了解您的问题。

答案 2 :(得分:0)

升级以下内容:

 implementation 'com.google.firebase:firebase-firestore:16.0.0'
 implementation 'com.google.firebase:firebase-auth:15.1.0'

对此:

 implementation 'com.google.firebase:firebase-firestore:17.0.2'
 implementation 'com.google.firebase:firebase-auth:16.0.2'

在此处查看更多信息:

https://firebase.google.com/support/release-notes/android

答案 3 :(得分:0)

您还可以使用Firebase助手设置

enter image description here

答案 4 :(得分:0)

我能够使它工作。您可以简单地比较我的新gradle文件。问题是Google服务库和Gradle版本冲突。因此,我创建了一个新项目,并再次像这样添加了依赖项,它就起作用了。

因此,我从app / build.gradle中删除了它:

implementation 'com.google.android.gms:play-services-auth:15.0.1'

然后,将其从module / build.gradle中删除:

classpath 'com.google.android.gms:play-services-base:15.0.1'

,并在module / build.gradle中更新了gradle版本:

classpath 'com.google.gms:google-services:4.0.1'

新的build.gradle文件如下所示。

module / build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:4.0.1' // google-services plugin

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app / build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "master.firebasesetup"
        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:support-v4:27.1.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.firebase:firebase-firestore:17.0.2'
    implementation 'com.google.firebase:firebase-auth:16.0.2'
    implementation 'com.google.firebase:firebase-storage:16.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.1'
}
apply plugin: 'com.google.gms.google-services'