在android studio中使用库

时间:2017-09-07 08:25:05

标签: java android firebase

com.google.firebase:firebase-core:11.2.2
com.google.firebase:firebase-database:11.2.2
com.google.firebase:firebase-storage:11.2.2

这些库似乎无法正常工作,我无法使用google,Facebook,twitter等提供商登录我的android项目。我试图更新android工作室,现在我正在使用android studio 2.3.3,我正在使用:

    app:




compileSdkVersion 26
    buildToolsVersion "26.0.1"

 minSdkVersion 16
        targetSdkVersion 26
        versionCode 1




 project:

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.3'

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
            classpath 'com.google.gms:google-services:3.1.0'
        }
    }

    allprojects {
        repositories {
            jcenter()
        }
    }

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

1 个答案:

答案 0 :(得分:0)

根据官方Firebase Documentation,您需要将Google的Maven存储库添加到项目级build.gradle:

buildscript {
    // ...
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:3.1.0' // google-services plugin
    }
}

allprojects {
    // ...
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
    }
}

然后,在您的模块Gradle文件(通常是app / build.gradle)中,在文件底部添加apply plugin行以启用Gradle插件:

apply plugin: 'com.android.application'

android {
  // ...
}

dependencies {
  // ...
  compile 'com.google.firebase:firebase-core:11.2.2'
  compile 'com.google.firebase:firebase-messaging:11.2.2'
  // Getting a "Could not find" error? Make sure you have
  // the latest Google Repository in the Android SDK manager
}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'