I'm creating a backend for my Android application using Google App Engine. I'm doing something very simple, which is just initialising my Firebase Admin SDK following instructions here - https://firebase.google.com/docs/admin/setup.
When I do this and run, I get the following error:
java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory is a restricted class. Please see the Google App Engine developer's guide for more details. at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:52) at com.google.firebase.internal.FirebaseThreadManagers.(FirebaseThreadManagers.java:37) at com.google.firebase.FirebaseOptions$Builder.(FirebaseOptions.java:147) at com.example.app.myapplication.backend.MyServlet.doGet(MyServlet.java:34)
Here's my Servlet, which works fine without the Firebase additions. Error occurs at 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);
}
}
Here's my build.gradle for the backend:
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
}
}