在尝试访问Firebase存储时,应用程序崩溃。我正在调用另一个具有FirebaseStorage的所有方法和声明的Java类文件。每当我尝试访问此类文件时,都会在FirebaseStorage.getInstance()方法中收到错误消息。 我想知道是否还有另一种方法可以明确提及该URL,以直接访问存储桶而不是访问应用程序的上下文。
PS:我从一个片段中打开此类,这可能是崩溃的原因。 有什么想法吗 ? 谢谢:)
UploadImage.java
public class UploadImage extends MainActivity{
private String path;
private StorageReference storageReference;
public UploadImage(String path){
this.path = path;
this.storageReference = FirebaseStorage.getInstance("gs://databasereal-bb774.appspot.com").getReference();
}
public void upload(){
Uri file = Uri.fromFile(new File(path));
StorageReference imageRef = storageReference.child("ParamedicImages");
imageRef.putFile(file)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Get a URL to the uploaded content
Log.d("Uupload","Uploaded");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e("failed upload", exception.toString());
}
});
}
}
例外
10-17 10:50:19.623 23807-23807/com.example.emil.integrated E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.emil.integrated, PID: 23807
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbq;
at com.google.firebase.storage.FirebaseStorage.getInstance(Unknown Source:11)
at com.example.emil.integrated.MainActivity.onCreate(MainActivity.java:52)
at android.app.Activity.performCreate(Activity.java:7084)
at android.app.Activity.performCreate(Activity.java:7075)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2765)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2890)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1611)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:171)
at android.app.ActivityThread.main(ActivityThread.java:6633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzbq" on path: DexPathList[[zip file "/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/base.apk", zip file "/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/split_lib_resources_apk.apk", zip file "/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
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 com.example.emil.integrated.MainActivity.onCreate(MainActivity.java:52)
at android.app.Activity.performCreate(Activity.java:7084)
at android.app.Activity.performCreate(Activity.java:7075)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2765)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2890)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1611)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:171)
at android.app.ActivityThread.main(ActivityThread.java:6633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.emil.integrated-uhFwZ_bugwGNWNgjr6d59A==/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)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337)
at dalvik.system.DexPathList.<init>(DexPathList.java:157)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:35)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:695)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:729)
at android.app.LoadedApk.getResources(LoadedApk.java:956)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2282)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5714)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1680)
... 6 more
build.gradle(应用程序模块)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.emil.integrated"
minSdkVersion 16
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.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-firestore:17.1.1'
implementation 'com.google.firebase:firebase-auth:16.0.4'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.mindorks:placeholderview:0.2.7'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:design:27.0.0'
implementation 'id.zelory:compressor:2.1.0'
implementation 'pub.devrel:easypermissions:0.2.1'
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'
build.gradle(项目模块)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.emil.integrated"
minSdkVersion 16
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.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-firestore:17.1.1'
implementation 'com.google.firebase:firebase-auth:16.0.4'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.mindorks:placeholderview:0.2.7'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:design:27.0.0'
implementation 'id.zelory:compressor:2.1.0'
implementation 'pub.devrel:easypermissions:0.2.1'
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'
答案 0 :(得分:0)
FirebaseStorage.getInstance(String url)..这个URL是什么?
您需要以URL
方法传递Firebase
存储桶中的FirebaseStorage.getInstance()
来自文档
FirebaseStorage getInstance (String url)
FirebaseStorage
,并使用默认FirebaseApp
和自定义存储桶进行初始化。参数
url
gs://指向您的Firebase
存储桶的网址。编辑
您需要更新您的firebase-storage
依赖项
implementation 'com.google.firebase:firebase-storage:16.0.3'