在Android 2.3.3中导入com.firebase.client.Firebase

时间:2017-07-04 09:32:28

标签: android firebase firebase-authentication

我正在创建一个应用程序类,以便在我的完整应用程序中使用Firebase。但是,在导入行中出现错误,突出显示' firebase'红色的。 我到处都看,但无法解决问题。

代码:

package com.mobility.mobilityindia;
import android.app.Application;
import com.firebase.client.Firebase;  <--- firebase is red here

public class MobilityIndia2 extends Application{
   @Override
    public void onCreate() {
       super.onCreate();

       Firebase.setAndroidContext(this);  <----  Firebase is red here
   }

app level gradle.build

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0"
    defaultConfig
            {
                applicationId "com.mobility.mobilityindia"
                minSdkVersion 21
                targetSdkVersion 26
                versionCode 1
                versionName "1.0"
                testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    String googleSupportVersion = '26.+'
    String googlePlayServicesVersion = '11.0.2'
    compile "com.google.firebase:firebase-core:$googlePlayServicesVersion"
    compile "com.google.firebase:firebase-auth:$googlePlayServicesVersion"
    compile "com.android.support:appcompat-v7:$googleSupportVersion"
    compile "com.android.support:support-v4:$googleSupportVersion"
    compile "com.google.android.gms:play-services:$googlePlayServicesVersion"
    compile "com.android.support:design:$googleSupportVersion"
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
apply plugin: 'com.google.gms.google-services'

顶级gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:3.1.0'

    }
}

1 个答案:

答案 0 :(得分:0)

您拥有的代码适用于旧版本的Firebase SDK(1.x或2.x),而您正在导入最新版本。

如果您关注latest documentation或最新Android codelab,则不再需要Firebase.setAndroidContext(),并且会获得以com.google.firebase开头的导入。