无法在android中声明FirebaseStorage

时间:2017-01-12 08:45:37

标签: android firebase firebase-storage

我尝试使用Firebase存储上传文件,但是当我声明时 FirebaseStorage storage = FirebaseStorage.getInstance(),启动我的应用会自动关闭。这是我的代码:

 private ImageView imageView;
private Button uploadButton;
private static final int SELECT_PICTURE = 100;
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl("gs://mypj-a8807.appspot.com");

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.upload);

    Firebase.setAndroidContext(this);

    imageView = (ImageView) findViewById(R.id.imageview);
    uploadButton = (Button) findViewById(R.id.uploadbutton);
    onImageViewClick(); // for selecting an Image from gallery.
    onUploadButtonClick(); // for uploading the image to Firebase Storage.



}

这是错误日志:

01-12 03:42:41.464 9991-9991/? E/AndroidRuntime: FATAL EXCEPTION: main
                                             Process: com.app.tuan88291.testapp, PID: 9991
                                             java.lang.NoSuchMethodError: No static method zzb(ZLjava/lang/Object;)V in class Lcom/google/android/gms/common/internal/zzab; or its super classes (declaration of 'com.google.android.gms.common.internal.zzab' appears in /data/data/com.app.tuan88291.testapp/files/instant-run/dex/slice-com.google.android.gms-play-services-basement-9.6.1_db2fbc040aebde58c8f066d23f6feacd51d66de2-classes.dex)
                                                 at com.google.firebase.storage.FirebaseStorage.getInstance(Unknown Source)
                                                 at com.app.tuan88291.testapp.upload_firebase.<init>(upload_firebase.java:26_***here is line which is declare FirebaseStorage***)
                                                 at java.lang.reflect.Constructor.newInstance(Native Method)
                                                 at java.lang.Class.newInstance(Class.java:1606)
                                                 at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
                                                 at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                 at android.os.Looper.loop(Looper.java:135)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:372)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

和gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 25
    buildToolsVersion "24.0.3"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.app.tuan88291.testapp"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    apt 'com.jakewharton:butterknife-compiler:8.4.0'
    compile files('libs/urlimageviewhelper-1.0.4.jar')


    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.facebook.android:facebook-android-sdk:4.+'
    compile 'com.jakewharton:butterknife:8.4.0'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    compile 'com.google.firebase:firebase-core:9.6.1'
    compile 'com.google.firebase:firebase-messaging:9.6.1'
    compile 'com.firebase:firebase-client-android:2.3.1'
    compile 'com.google.firebase:firebase-storage:9.2.1'
    compile 'com.google.firebase:firebase-auth:9.2.1'

    compile 'com.google.android.gms:play-services-gcm:9.6.1'

}

apply plugin: 'com.google.gms.google-services'
你可以帮我找错吗?谢谢

1 个答案:

答案 0 :(得分:0)

您似乎正在使用至少三个不同版本的Firebase,包括&#34; old&#34; firebase数据库,以及&#34; new&#34; firebase组件,如Storage,Auth和Messaging。

// Make sure all dependencies have the same version
// This is determined by the version of Google Play Services on your device
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-messaging:9.6.1'
compile 'com.google.firebase:firebase-database:9.6.1'
compile 'com.google.firebase:firebase-storage:9.6.1'
compile 'com.google.firebase:firebase-auth:9.6.1'

// Delete these two, they're the "old" versions of things
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.android.gms:play-services-gcm:9.6.1'

将所有这些产品的依赖关系设置为相同,我希望事情能够更好地发挥作用。