[英]App crashes when saving a cropped photo to FirebaseStorage
I want to save in the firebase storage, a photo that's cropped using the CropImage libraray from github.我想保存在 firebase 存储中,这是一张使用来自 github 的 CropImage 库裁剪的照片。 Everything works all right, until I hit the crop button.一切正常,直到我按下裁剪按钮。 This is how I get and store the image from the Crop Image Activity;这就是我从 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();
}
}
When I hit the Crop button, the app crashes and I see this error in the LogCat:当我点击裁剪按钮时,应用程序崩溃,我在 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
This is my build.gradle file:这是我的 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.+'
I'm using image-cropper:2.4.+ because the examples in the Github page doesn't work when I'm using the lastest version of it.我正在使用 image-cropper:2.4.+ 因为当我使用它的最新版本时,Github 页面中的示例不起作用。 What can I do?我能做什么? Is it a version problem?是版本问题吗?
It's likely caused by your firebase-storage dependency version being different than your firebase-auth and firebase-database dependencies.这可能是由于您的 firebase-storage 依赖项版本与您的 firebase-auth 和 firebase-database 依赖项不同。
Can you try updating the version on your firebase-storage to 17.0.0 and see if that resolves your problem?您可以尝试将 firebase-storage 上的版本更新到 17.0.0,看看是否能解决您的问题?
The dependency versions should be the same.依赖版本应该相同。 This would work这会工作
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.