我正在使用 scala 版本 2.11.7 和 sbt 0.13 的 play 框架 2.5.4,添加 "com.google.firebase"% "firebase-admin"% "6.12.2"< 后一切停止工作
到 build.sbt
文件
根据请求收到以下错误
[error] p.c.s.n.PlayRequestHandler - Exception caught in Netty
java.lang.AbstractMethodError: null
at io.netty.util.ReferenceCountUtil.touch(ReferenceCountUtil.java:77)
at io.netty.channel.DefaultChannelPipeline.touch(DefaultChannelPipeline.java:116)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:337)
at com.typesafe.netty.http.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:129)
at com.typesafe.netty.http.HttpStreamsServerHandler.channelRead(HttpStreamsServerHandler.java:96)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:337)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
最佳答案
如果有人面临同样的问题,以下内容对我有用,
将 firebase-admin-6.12.2.jar 添加到外部库并将以下依赖项添加到您的 build.sbt
"com.google.guava" % "guava" % "28.2-jre",
"com.google.api" % "api-common" % "1.8.1",
"com.google.api-client" % "google-api-client" % "1.30.1",
"com.google.auth" % "google-auth-library-oauth2-http" % "0.20.0"
并使用以下代码使用 firebase admin 发送通知
String fcmToken = "";
Message message = Message.builder()
.setNotification(new Notification(
title,
context))
.setToken(fcmToken)
.build();
String response = null;
try {
response = FirebaseMessaging.getInstance(FirebaseApp.initializeApp(getOptions()))
.send(message);
} catch (FirebaseMessagingException e) {
e.printStackTrace();
}
System.out.println("Successfully sent message: " + response);
FirebaseOptions getOptions() {
FileInputStream serviceAccount = null;
FirebaseOptions options =null;
try {
serviceAccount = new FileInputStream("conf/projectPrivateKey.json");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://DATABASE_NAME.firebaseio.com")
.build();
} catch (IOException e) {
e.printStackTrace();
}
return options;
}
关于java - 添加 Firebase Admin 6.12.2 后 Netty 无法处理请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60428155/