将裁剪的照片保存到FirebaseStorage时,应用程序崩溃

时间:2019-05-20 21:00:59

标签: java android firebase firebase-storage

我想保存在Firebase存储器中,这张照片是使用github中的CropImage libraray裁剪的。一切正常,直到我按下裁剪按钮。 这就是我从“作物图像活动”中获取和存储图像的方式;

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == GALLERY_PICK && resultCode == RESULT_OK) {

        Uri imageUri = data.getData();

        CropImage.activity(imageUri)
                .setAspectRatio(1, 1)
                .start(this);

    }

    if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {

        CropImage.ActivityResult result = CropImage.getActivityResult(data);

        if (resultCode == RESULT_OK) {

            Uri resultUri = result.getUri();

            StorageReference filepath = mImageStorage.child("profile_images").child("profile_image.jpg");

            filepath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {

                    if(task.isSuccessful()) {

                        Toast.makeText(SettingsActivity.this, "Working", Toast.LENGTH_SHORT).show();

                    } else {

                        Toast.makeText(SettingsActivity.this, "Error in uploading", Toast.LENGTH_SHORT).show();

                    }

                }
            });

        } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {

            Exception error = result.getError();

        }
    }

当我按下“裁剪”按钮时,应用程序崩溃,并且在LogCat中看到此错误:

    2019-05-20 23:51:53.228 13563-13616/com.example.lapitchat E/StorageException: StorageException has occurred.
    An unknown error occurred, please check the HTTP result code and inner exception for server response.
     Code: -13000 HttpResult: 0
2019-05-20 23:51:53.230 13563-13616/com.example.lapitchat E/AndroidRuntime: FATAL EXCEPTION: FirebaseStorage-Upload-1
    Process: com.example.lapitchat, PID: 13563
    java.lang.NoSuchMethodError: No virtual method getToken(Z)Lcom/google/android/gms/tasks/Task; in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/com.example.lapitchat-0t0XSYn85YiAd1vWQMGk4g==/split_lib_dependencies_apk.apk)
        at com.google.firebase.storage.internal.Util.getCurrentAuthToken(com.google.firebase:firebase-storage@@16.0.4:148)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@16.0.4:65)
        at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@16.0.4:57)
        at com.google.firebase.storage.UploadTask.sendWithRetry(com.google.firebase:firebase-storage@@16.0.4:457)
        at com.google.firebase.storage.UploadTask.beginResumableUpload(com.google.firebase:firebase-storage@@16.0.4:257)
        at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@16.0.4:198)
        at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@16.0.4:1106)
        at com.google.firebase.storage.StorageTask$$Lambda$12.run(Unknown Source:2)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
2019-05-20 23:51:53.228 13563-13616/com.example.lapitchat E/StorageException: StorageException has occurred.
    An unknown error occurred, please check the HTTP result code and inner exception for server response.
     Code: -13000 HttpResult: 0

这是我的build.gradle文件:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'de.hdodenhof:circleimageview:3.0.0'
implementation 'com.google.firebase:firebase-database:17.0.0'
implementation 'com.google.firebase:firebase-storage:16.0.4'
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'
api 'com.theartofdev.edmodo:android-image-cropper:2.4.+'

我使用的是image-cropper:2.4。+,因为使用最新版本的Github页面中的示例不起作用。 我能做什么?是版本问题吗?

2 个答案:

答案 0 :(得分:1)

这可能是由于您的firebase-storage依赖版本与firebase-auth和firebase-database依赖版本不同所致。

您可以尝试将Firebase-storage上的版本更新为17.0.0,看看是否可以解决您的问题吗?

答案 1 :(得分:0)

依赖项版本应该相同。这会起作用

implementation 'com.google.firebase:firebase-storage:17.0.0'
implementation 'com.google.firebase:firebase-database:17.0.0'
implementation 'com.google.firebase:firebase-auth:17.0.0'