【问题标题】:Firebase Admin NoClassDefFoundError: FirebaseOptions$BuilderFirebase 管理员 NoClassDefFoundError:FirebaseOptions$Builder
【发布时间】:2017-07-03 01:55:04
【问题描述】:

我正在使用这个:

FileInputStream serviceAccount;
    try {
        serviceAccount = new FileInputStream("firebase_key.json");
    } catch (FileNotFoundException e) {
        System.out.println(e.getMessage());
        return;
    }
    System.out.println("Reached here!");

    FirebaseOptions options = new FirebaseOptions.Builder()
            .setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
            .setDatabaseUrl("https://*.firebaseio.com/")
            .build();

    FirebaseApp.initializeApp(options);

但是,应用程序崩溃并显示 java.lang.NoClassDefFoundError for FirebaseOptions$Builder

我的build.gradle

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile 'com.google.firebase:firebase-admin:4.1.1'
}

我正在使用 IntelliJ。

Logcat:

    Exception in thread "main" java.lang.NoClassDefFoundError: com/google/firebase/FirebaseOptions$Builder
10:57:43 AM web.1 |     at com.x.*.TokenGenerator.main(TokenGenerator.java:26)
10:57:43 AM web.1 |  Caused by: java.lang.ClassNotFoundException: com.google.firebase.FirebaseOptions$Builder
10:57:43 AM web.1 |     at java.net.URLClassLoader.findClass(Unknown Source)
10:57:43 AM web.1 |     at java.lang.ClassLoader.loadClass(Unknown Source)
10:57:43 AM web.1 |     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
10:57:43 AM web.1 |     at java.lang.ClassLoader.loadClass(Unknown Source)

我的 firebase_key.json 在应用程序的根目录中。

这是什么原因造成的?

【问题讨论】:

  • 添加你的日志猫
  • 认为不需要。已添加

标签: android firebase firebase-authentication firebase-admin


【解决方案1】:

问题原来是我用这个命令来构建的:

gradlew clean install

但是,由此生成的 Jar 不包含 依赖项。 Firebase Admin SDK 是一个依赖项。

所以我所做的是我使用了shadowJar,它会生成一个包含依赖项的 Jar。不像gradlew clean install

然后,在 Procfile 中,我将其设置为 shadowJar 生成的 Jar。我看到的唯一问题是,现在我必须去 IntelliJ 并从那里运行 shadowJar,因为似乎没有任何命令可以从命令行运行它。

希望对你有帮助

【讨论】:

  • 我知道这有点老了,但这是否意味着我们需要使用第三方库才能在 java 中使用 Firebase Admin SDK?有没有其他办法?
【解决方案2】:

你没有在 gradle 上为 firebase 选项设置正确的导入,不需要管理包,你需要核心:

而不是compile 'com.google.firebase:firebase-admin:4.1.1'

使用compile "com.google.firebase:firebase-core:10.0.1"

【讨论】:

    猜你喜欢
    • 2019-01-19
    • 2017-09-23
    • 2019-03-14
    • 1970-01-01
    • 2018-06-15
    • 2019-12-28
    • 2019-02-22
    • 1970-01-01
    • 2018-12-05
    相关资源
    最近更新 更多