找到firebase的getInstance()方法时出错

时间:2017-05-21 21:06:12

标签: android firebase firebase-realtime-database

我尝试将Firebase数据库连接到我的Android项目并包含以下行:

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");

我尝试进出onCreate()但是我收到以下错误:

05-21 21:32:55.780 10813-10813/com1032.cw2.nv00075.nv00075_assignment2 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com1032.cw2.nv00075.nv00075_assignment2, PID: 10813
    java.lang.NoSuchMethodError: No virtual method zzTt()Z in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/com1032.cw2.nv00075.nv00075_assignment2-1/split_lib_dependencies_apk.apk:classes2.dex)
     at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
     at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
     at com1032.cw2.nv00075.nv00075_assignment2.MainActivity.initialise(MainActivity.java:38)
     at com1032.cw2.nv00075.nv00075_assignment2.MainActivity.onCreate(MainActivity.java:50)
     at android.app.Activity.performCreate(Activity.java:6308)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2543)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2678)
     at android.app.ActivityThread.-wrap11(ActivityThread.java)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1494)
     at android.os.Handler.dispatchMessage(Handler.java:111)
     at android.os.Looper.loop(Looper.java:207)
     at android.app.ActivityThread.main(ActivityThread.java:5822)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
05-21 21:32:58.844 10813-10813/com1032.cw2.nv00075.nv00075_assignment2 I/Process: Sending signal. PID: 10813 SIG: 9

这些是我的Gradle配置文件:

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.0.0'
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com1032.cw2.nv00075.nv00075_assignment2"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.android.gms:play-services-maps:10.2.6'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.google.firebase:firebase-auth:10.0.1'
    compile 'com.google.firebase:firebase-storage:10.0.1'
    testCompile 'junit:junit:4.12'
}


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

1 个答案:

答案 0 :(得分:0)

我也遇到了这个问题。我解决了。我将firebase版本更新为11.0.4并更新了google-service.json文件     编译com.google.firebase:firebase-auth:11.0.4'     编译com.google.firebase:firebase-database:11.0.4' 我希望这能帮到你。