Error: In adding Firebase Storage dependency to Android Studio Project?

China☆狼群 提交于 2019-12-13 08:05:47

问题


I have created a Firestore Project in Android Studio. In which I have Firebase Authorization implemented and that is working absolutely fine. I am able to push documents to Firestore Database.

But now, I am trying to add functionality using which I can store media/images to Firebase Storage but when I am adding this dependency to app's build.gradle file, I am getting this error:

Dependency added:

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

This is the error that I am getting:

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

FYI, In my project I already have this kind of configuration:

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

And

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

I can not find what is going wrong when I just add firebase-storage dependency to my Android project.

Here is my app level build.gradle file:

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'

Here is my module level build.gradle file:

// 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
}

回答1:


Have you added these to your root level gradle file?

buildscript {

    dependencies {

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

allprojects {

    repositories {

        google() 
    }
}



回答2:


You have to add dependencies {classpath 'com.google.gms:google-services:4.0.1'} and repositories { google()} on your root level build.gradle file. Have you added that? And further more please provide your whole build.gradle file in order to understand your problem .




回答3:


Upgrade the following:

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

into this:

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

Check here for more info:

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




回答4:


Also you can use firebase assitant set up




回答5:


I was able to make it work guys. You can simply compare my new gradle files. The issue was conflicting google services libraries and gradle version. So, I created new project and just added dependencies again like this and it worked.

So, I removed this from app/build.gradle:

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

And, removed this from module/build.gradle:

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

and updated gradle version in module/build.gradle:

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

New build.gradle files look like this.

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'


来源:https://stackoverflow.com/questions/51100839/error-in-adding-firebase-storage-dependency-to-android-studio-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!