0

我正在使用 Google App Engine 为我的 Android 应用程序创建一个后端。我正在做一些非常简单的事情,它只是按照此处的说明初始化我的 Firebase Admin SDK - https://firebase.google.com/docs/admin/setup

当我这样做并运行时,我收到以下错误:

java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory 是一个受限类。有关详细信息,请参阅 Google App Engine 开发人员指南。在 com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:52) 在 com.google.firebase.internal.FirebaseThreadManagers.(FirebaseThreadManagers.java:37) 在 com.google.firebase。 FirebaseOptions$Builder.(FirebaseOptions.java:147) 在 com.example.app.myapplication.backend.MyServlet.doGet(MyServlet.java:34)

这是我的 Servlet,无需添加 Firebase 即可正常工作。FirebaseOptions 发生错误:

    public class MyServlet extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        resp.setContentType("text/plain");
        resp.getWriter().println("Please use the form to POST to this url");


        FileInputStream serviceAccount =
                new FileInputStream("WEB-INF/MyAppServiceKey.json");

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

        FirebaseApp.initializeApp(options);
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        String name = req.getParameter("name");
        resp.setContentType("text/plain");
        if (name == null) {
            resp.getWriter().println("Please enter a name");
        }
        resp.getWriter().println("Hello " + name);
    }
}

这是我用于后端的 build.gradle:

    buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.google.appengine:gradle-appengine-plugin:1.9.42'
    }
}

repositories {
    jcenter();
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.42'
    compile 'javax.servlet:servlet-api:2.5'
    compile 'com.google.firebase:firebase-admin:5.5.0'

}

appengine {
    downloadSdk = true
    appcfg {
        oauth2 = true
    }
}
4

0 回答 0