簡體   English   中英

將裁剪后的照片保存到 FirebaseStorage 時應用崩潰

[英]App crashes when saving a cropped photo to FirebaseStorage

我想保存在 firebase 存儲中,這是一張使用來自 github 的 CropImage 庫裁剪的照片。 一切正常,直到我按下裁剪按鈕。 這就是我從 Crop Image Activity 獲取和存儲圖像的方式;

@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 頁面中的示例不起作用。 我能做什么? 是版本問題嗎?

這可能是由於您的 firebase-storage 依賴項版本與您的 firebase-auth 和 firebase-database 依賴項不同。

您可以嘗試將 firebase-storage 上的版本更新到 17.0.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'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM