代码编译 Firebase Admin 时出错。

huangapple go评论81阅读模式
英文:

Error while compiling code for firebase admin

问题

以下是您提供的内容的翻译部分:

错误:

代码编译 Firebase Admin 时出错。

根据 http://www.slf4j.org/codes.html#StaticLoggerBinder 提供的信息,我尝试了逐个添加所有依赖项

添加

testCompile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.13.3'

或者

testCompile group: 'org.slf4j', name: 'slf4j-nop', version: '1.8.0-beta4'

或者

testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.8.0-beta4'

或者

testCompile group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.8.0-beta4'

或者

testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'

都无法解决错误。
请问我错在了哪里?

我的 Gradle 文件:

plugins {
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    implementation 'com.google.firebase:firebase-admin:6.13.0'
// 这些依然无法解决错误
//    testCompile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.13.3'
//    testCompile group: 'org.slf4j', name: 'slf4j-nop', version: '1.8.0-beta4'
//    testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.8.0-beta4'
//    testCompile group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.8.0-beta4'
//    testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'

我的主类

import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.database.*;

import java.io.IOException;

public class MainClass {
    public static void main(String[] args) throws IOException {
        FirebaseOptions options = new FirebaseOptions.Builder()
                .setCredentials(GoogleCredentials.getApplicationDefault())
                .setDatabaseUrl("https://{我的数据库名称}.firebaseio.com/")
                .build();

        FirebaseApp.initializeApp(options);
        DatabaseReference ref = FirebaseDatabase.getInstance()
                .getReference("restricted_access/secret_document");
        ref.setValue("hiIII", new DatabaseReference.CompletionListener() {
            @Override
            public void onComplete(DatabaseError error, DatabaseReference ref) {
                System.out.println("完成");
            }
        });
    }
}

请问我错在了哪里?我该如何纠正呢?

英文:

I got an error while compiling code for Firebase admin.

Error:

代码编译 Firebase Admin 时出错。

Following the info from <http://www.slf4j.org/codes.html#StaticLoggerBinder> I've tried adding all the dependencies one by one

adding

testCompile group: &#39;org.apache.logging.log4j&#39;, name: &#39;log4j-slf4j-impl&#39;, version: &#39;2.13.3&#39;

or

testCompile group: &#39;org.slf4j&#39;, name: &#39;slf4j-nop&#39;, version: &#39;1.8.0-beta4&#39;

or

testCompile group: &#39;org.slf4j&#39;, name: &#39;slf4j-simple&#39;, version: &#39;1.8.0-beta4&#39;

or

testCompile group: &#39;org.slf4j&#39;, name: &#39;slf4j-jdk14&#39;, version: &#39;1.8.0-beta4&#39;

or

testCompile group: &#39;ch.qos.logback&#39;, name: &#39;logback-classic&#39;, version: &#39;1.2.3&#39;

doesn't remove the error.
May I know what I'm going wrong with?

My Gradle file:

plugins {
    id &#39;java&#39;
}

group &#39;org.example&#39;
version &#39;1.0-SNAPSHOT&#39;

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: &#39;junit&#39;, name: &#39;junit&#39;, version: &#39;4.12&#39;
    implementation &#39;com.google.firebase:firebase-admin:6.13.0&#39;
//None of these seem to remove the error
//    testCompile group: &#39;org.apache.logging.log4j&#39;, name: &#39;log4j-slf4j-impl&#39;, version: &#39;2.13.3&#39;
//    testCompile group: &#39;org.slf4j&#39;, name: &#39;slf4j-nop&#39;, version: &#39;1.8.0-beta4&#39;
//    testCompile group: &#39;org.slf4j&#39;, name: &#39;slf4j-simple&#39;, version: &#39;1.8.0-beta4&#39;
//    testCompile group: &#39;org.slf4j&#39;, name: &#39;slf4j-jdk14&#39;, version: &#39;1.8.0-beta4&#39;
//    testCompile group: &#39;ch.qos.logback&#39;, name: &#39;logback-classic&#39;, version: &#39;1.2.3&#39;

My main Class

import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.database.*;

import java.io.IOException;

public class MainClass {
    public static void main(String[] args) throws IOException {
        FirebaseOptions options = new FirebaseOptions.Builder()
                .setCredentials(GoogleCredentials.getApplicationDefault())
                .setDatabaseUrl(&quot;https://{my database name}.firebaseio.com/&quot;)
                .build();

        FirebaseApp.initializeApp(options);
        DatabaseReference ref = FirebaseDatabase.getInstance()
                .getReference(&quot;restricted_access/secret_document&quot;);
        ref.setValue(&quot;hiIII&quot;, new DatabaseReference.CompletionListener() {
            @Override
            public void onComplete(DatabaseError error, DatabaseReference ref) {
                System.out.println(&quot;Completed&quot;);
            }
        });
    }
}

May I know What I'm going wrong with? and How can I Correct it?

答案1

得分: 1

这个警告消息是在无法将 org.slf4j.impl.StaticLoggerBinder 类加载到内存时报告的。当类路径上找不到适当的 SLF4J 绑定时会发生这种情况。在类路径上放置 slf4j-nop.jar、slf4j-simple.jar、slf4j-log4j12.jar、slf4j-jdk14.jar 或 logback-classic.jar 中的一个(仅限一个),应该可以解决这个问题。

如果这个问题没有解决,请尝试清除缓存并重新启动。

英文:

This warning message is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.

If this problem doesnot solve try clear caches and restart.

huangapple
  • 本文由 发表于 2020年5月29日 20:22:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/62085890.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定