gpt4 book ai didi

java - 尝试将图像保存到 firebase 存储时,android studio 出现错误

转载 作者:太空狗 更新时间:2023-10-29 13:46:49 24 4
gpt4 key购买 nike

我正在制作一个 Android 应用程序,这个应用程序的一部分是为用户保存显示图像。下面的代码块是将图像保存在 firebase 存储中的方法。我已经在 firebase 中配置了规则,并在 list 文件中设置了访问图像的权限。该方法在用户选择图库中的图像后被调用。选择图像有效,但保存部分无效。我已经做了很多方法来解决这个问题,但似乎没有任何效果。 IDE 无法检测到的代码中似乎存在错误。错误在运行时。用户在图库中选择图片后应用关闭。

mStorage 已经在onCreate 方法中初始化。所选图像保存在 uriProfileImage 中。 uploadProgress 只是一个进度条。

private void uploadImageToFirebaseStorage() {
mStorage = FirebaseStorage.getInstance().getReference();
StorageReference profileImageRef = mStorage.child("displayImages/" + System.currentTimeMillis() + uriProfileImage.getPath().substring(uriProfileImage.getPath().lastIndexOf(".")));
uploadProgress.setVisibility(View.VISIBLE);
if (uriProfileImage != null) {
profileImageRef.putFile(uriProfileImage).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
uploadProgress.setVisibility(View.GONE);
profileImageUrl = taskSnapshot.getDownloadUrl().toString();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
uploadProgress.setVisibility(View.GONE);
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}

我得到了这个错误

E/AndroidRuntime: FATAL EXCEPTION: main
Process: eabalderama.gmail.com.albaytravelguideadministrator, PID: 10812
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbq;
at com.google.firebase.storage.FirebaseStorage.getInstance(Unknown Source:11)
at eabalderama.gmail.com.albaytravelguideadministrator.EditProfileFragment.uploadImageToFirebaseStorage(EditProfileFragment.java:133)
at eabalderama.gmail.com.albaytravelguideadministrator.EditProfileFragment.onActivityResult(EditProfileFragment.java:123)
at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:156)
at android.app.Activity.dispatchActivityResult(Activity.java:7690)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4928)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4975)
at android.app.ActivityThread.-wrap20(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1950)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzbq" on path: DexPathList[[zip file "/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/base.apk", zip file "/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/split_lib_dependencies_apk.apk", zip file "/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/split_lib_resources_apk.apk", zip file "/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/split_lib_slice_0_apk.apk", zip file "/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/split_lib_slice_1_apk.apk", zip file "/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/split_lib_slice_2_apk.apk", zip file "/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/split_lib_slice_3_apk.apk", zip file "/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/split_lib_slice_4_apk.apk", zip file "/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/split_lib_slice_5_apk.apk", zip file "/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/split_lib_slice_6_apk.apk", zip file "/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/split_lib_slice_7_apk.apk", zip file "/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/split_lib_slice_8_apk.apk", zip file "/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/lib/arm64, /system/lib64, /vendor/lib64, /product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.google.firebase.storage.FirebaseStorage.getInstance(Unknown Source:11) 
at eabalderama.gmail.com.albaytravelguideadministrator.EditProfileFragment.uploadImageToFirebaseStorage(EditProfileFragment.java:133) 
at eabalderama.gmail.com.albaytravelguideadministrator.EditProfileFragment.onActivityResult(EditProfileFragment.java:123) 
at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:156) 
at android.app.Activity.dispatchActivityResult(Activity.java:7690) 
at android.app.ActivityThread.deliverResults(ActivityThread.java:4928) 
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4975) 
at android.app.ActivityThread.-wrap20(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1950) 
at android.os.Handler.dispatchMessage(Handler.java:108) 
at android.os.Looper.loop(Looper.java:166) 
at android.app.ActivityThread.main(ActivityThread.java:7425) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) 
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/eabalderama.gmail.com.albaytravelguideadministrator-S-sF91cNJsjG7a5MWP_EqQ==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:353)
at dalvik.system.DexFile.<init>(DexFile.java:100)
at dalvik.system.DexFile.<init>(DexFile.java:74)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)

这是我在应用程序中的 build.gradle

    apply plugin: 'com.android.application'

android {
compileSdkVersion 27
defaultConfig {
applicationId "eabalderama.gmail.com.albaytravelguideadministrator"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-storage:11.8.0'
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'
}

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

请帮帮我。我已经尝试了很多方法来解决它,但我根本没有取得任何进展。

最佳答案

伙计们,我找到了解决方案。我发布这个是为了帮助其他有同样问题的人。

问题是我提供的 StorageReference 是错误的。

我把它改成

mStorage = FirebaseStorage.getInstance().getReference();
StorageReference profileImageRef = mStorage.child("displayImages/" + System.currentTimeMillis() + uriProfileImage.getPath().substring(uriProfileImage.getPath().lastIndexOf(".")));

StorageReference profileImageRef = FirebaseStorage.getInstance().getReference("displayImages/"+System.currentTimeMillis()+".jpg");

似乎之前的 StorageReference 返回了一个无效的存储引用。我还更新了我的 firebase 存储和数据库依赖项。

另一件事是,上面用于获取上传图片的 downloadUrl 的代码不起作用。

所以我把它改成了

profileImageUrl = taskSnapshot.getDownloadUrl().toString();

profileImageUrl = taskSnapshot.getMetadata().getReference().getDownloadUrl().toString();

希望对您有所帮助。

关于java - 尝试将图像保存到 firebase 存储时,android studio 出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52168860/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com