gpt4 book ai didi

java - 如何将 FirebaseApp.initializeApp 用于 FirebaseRemoteConfig

转载 作者:太空狗 更新时间:2023-10-29 13:50:57 28 4
gpt4 key购买 nike

我正在尝试使用 FirebaseApp.initializeApp,但它不起作用。我有正确的库,但我无法使用 JSON 文件来初始化应用程序

这是我的代码:

导入

import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;

变量

private FirebaseRemoteConfig mFirebaseRemoteConfig;

private String projectID;
private String apiKey;
private String appID;

我如何初始化应用程序

public void Initialize() {
FirebaseOptions mFirebaseOptions = new FirebaseOptions.Builder()
.setApplicationId(this.appID)
.setApiKey(this.apiKey)
.build();
FirebaseApp.initializeApp(this.context, mFirebaseOptions, this.projectID);
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
}

应用程序在启动时崩溃,这是 logcat 错误:

12-04 22:11:42.217 12566 12566 E AndroidRuntime: FATAL EXCEPTION: main
12-04 22:11:42.217 12566 12566 E AndroidRuntime: Process: com.makeroid.sanderjochems.FirebaseRemoteConfig, PID: 12566
12-04 22:11:42.217 12566 12566 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzby;
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at com.google.firebase.FirebaseOptions.fromResource(Unknown Source)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at com.google.appinventor.components.runtime.FirebaseRemoteConfiguration.<init>(FirebaseRemoteConfiguration.java:67)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at java.lang.reflect.Constructor.newInstance0(Native Method)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at gnu.expr.PrimProcedure.apply(PrimProcedure.java:272)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at gnu.mapping.CallContext.runUntilDone(CallContext.java:234)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at gnu.mapping.CallContext.runUntilValue(CallContext.java:298)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at gnu.kawa.reflect.Invoke.applyN(Invoke.java:209)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at gnu.mapping.ProcedureN.apply2(ProcedureN.java:39)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at com.makeroid.sanderjochems.FirebaseRemoteConfig.Screen1.$define(Screen1.yail:10182)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at com.google.appinventor.components.runtime.Form.onCreateFinish(Form.java:389)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at com.google.appinventor.components.runtime.Form.onCreate(Form.java:336)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6942)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at android.app.ActivityThread.-wrap14(ActivityThread.java)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at android.os.Looper.loop(Looper.java:154)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6682)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzby" on path: DexPathList[[zip file "/data/app/com.makeroid.sanderjochems.FirebaseRemoteConfig-1/base.apk"],nativeLibraryDirectories=[/data/app/com.makeroid.sanderjochems.FirebaseRemoteConfig-1/lib/arm64, /system/lib64, /vendor/lib64]]
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
12-04 22:11:42.217 12566 12566 E AndroidRuntime: ... 25 more

最佳答案

可能存在多个问题。我会指出似乎是一个。

RemoteConfig.getInstance() 的文档注意到它希望初始化 default FirebaseApp:

FirebaseRemoteConfig uses the default FirebaseApp...

与其他一些 Firebase API 不同,无法使用不同的 FirebaseApp 初始化 RemoteConfig

这意味着当您初始化 FirebaseApp 时,projectID 必须是“[DEFAULT]”,它可以作为常数 FirebaseApp.DEFAULT_APP_NAME 使用。 .

FirebaseApp.initializeApp(this.context, mFirebaseOptions, this.projectID);

尝试将 projectID 设置为“[DEFAULT]”(或可用常量)以查看故障是否改变或已解决。

关于java - 如何将 FirebaseApp.initializeApp 用于 FirebaseRemoteConfig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47642053/

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