在 Android 上添加 spdy 编解码器后使用 netty 连接失败

Posted

技术标签:

【中文标题】在 Android 上添加 spdy 编解码器后使用 netty 连接失败【英文标题】:Failed to connect using netty after add spdy codec on Android 【发布时间】:2013-09-27 05:24:49 【问题描述】:

我已经使用 netty 编写了一个服务器和一个本地代理。该项目在我的电脑上运行良好,但是当我稍作更改以使其成为 android 应用程序时,它就无法运行。

我试了很多次,发现插入下面的代码后就出问题了。

pipeline.addLast("spdyEncoder", new SpdyFrameEncoder(3));
pipeline.addLast("spdyDecoder", new SpdyFrameDecoder(3));

我比较了添加或不添加spdy编解码器的日志,区别是

找不到类 'com.jcraft.jzlib.Deflater',引用自方法 io.netty.handler.codec.spdy.SpdyHeaderBlockJZlibEncoder.”,所以我猜问题出在jzlib deflater,但我真的不知道如何修复它。谁能帮帮我,非常感谢。

这里是 LogCat:

09-22 03:35:15.761: D/Multiplex(863): initInstance
09-22 03:35:15.761: D/MultiplexChannelConnMgr(863): constructor
09-22 03:35:15.771: I/dalvikvm(863): Could not find method org.slf4j.LoggerFactory.getILoggerFactory, referenced from method io.netty.util.internal.logging.Slf4JLoggerFactory.<init>
09-22 03:35:15.771: W/dalvikvm(863): VFY: unable to resolve static method 28005: Lorg/slf4j/LoggerFactory;.getILoggerFactory ()Lorg/slf4j/ILoggerFactory;
09-22 03:35:15.771: D/dalvikvm(863): VFY: replacing opcode 0x71 at 0x0026
09-22 03:35:15.781: I/dalvikvm(863): Could not find method org.slf4j.LoggerFactory.getLogger, referenced from method io.netty.util.internal.logging.Slf4JLoggerFactory.newInstance
09-22 03:35:15.781: W/dalvikvm(863): VFY: unable to resolve static method 28006: Lorg/slf4j/LoggerFactory;.getLogger (Ljava/lang/String;)Lorg/slf4j/Logger;
09-22 03:35:15.794: D/dalvikvm(863): VFY: replacing opcode 0x71 at 0x0002
09-22 03:35:15.862: W/System.err(863): log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).
09-22 03:35:15.871: W/System.err(863): log4j:WARN Please initialize the log4j system properly.
09-22 03:35:15.871: W/System.err(863): log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
09-22 03:35:16.110: D/dalvikvm(863): GC_CONCURRENT freed 121K, 9% free 2660K/2904K, paused 70ms+38ms, total 213ms
09-22 03:35:16.180: E/dalvikvm(863): Could not find class 'javassist.ClassPool', referenced from method io.netty.util.internal.JavassistTypeParameterMatcherGenerator.<clinit>
09-22 03:35:16.180: W/dalvikvm(863): VFY: unable to resolve new-instance 2027 (Ljavassist/ClassPool;) in Lio/netty/util/internal/JavassistTypeParameterMatcherGenerator;
09-22 03:35:16.180: D/dalvikvm(863): VFY: replacing opcode 0x22 at 0x0008
09-22 03:35:16.180: I/dalvikvm(863): Could not find method javassist.ClassPool.getAndRename, referenced from method io.netty.util.internal.JavassistTypeParameterMatcherGenerator.generate
09-22 03:35:16.190: W/dalvikvm(863): VFY: unable to resolve virtual method 16552: Ljavassist/ClassPool;.getAndRename (Ljava/lang/String;Ljava/lang/String;)Ljavassist/CtClass;
09-22 03:35:16.190: D/dalvikvm(863): VFY: replacing opcode 0x6e at 0x0032
09-22 03:35:16.190: I/dalvikvm(863): Could not find method javassist.ClassPool.appendClassPath, referenced from method io.netty.util.internal.JavassistTypeParameterMatcherGenerator.appendClassPath
09-22 03:35:16.190: W/dalvikvm(863): VFY: unable to resolve virtual method 16550: Ljavassist/ClassPool;.appendClassPath (Ljava/lang/String;)Ljavassist/ClassPath;
09-22 03:35:16.190: D/dalvikvm(863): VFY: replacing opcode 0x6e at 0x0002
09-22 03:35:16.190: W/dalvikvm(863): VFY: unable to find class referenced in signature (Ljavassist/ClassPath;)
09-22 03:35:16.190: I/dalvikvm(863): Could not find method javassist.ClassPool.appendClassPath, referenced from method io.netty.util.internal.JavassistTypeParameterMatcherGenerator.appendClassPath
09-22 03:35:16.190: W/dalvikvm(863): VFY: unable to resolve virtual method 16551: Ljavassist/ClassPool;.appendClassPath (Ljavassist/ClassPath;)Ljavassist/ClassPath;
09-22 03:35:16.190: D/dalvikvm(863): VFY: replacing opcode 0x6e at 0x0002
09-22 03:35:16.190: D/dalvikvm(863): DexOpt: unable to opt direct call 0x40a5 at 0x0b in Lio/netty/util/internal/JavassistTypeParameterMatcherGenerator;.<clinit>
09-22 03:35:16.200: D/dalvikvm(863): DexOpt: unable to opt direct call 0x40a4 at 0x16 in Lio/netty/util/internal/JavassistTypeParameterMatcherGenerator;.<clinit>
09-22 03:35:16.200: W/dalvikvm(863): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lio/netty/util/internal/JavassistTypeParameterMatcherGenerator;
09-22 03:35:16.260: D/MultiplexChannelConnMgr(863): Before connect to 10.108.112.239:9001
09-22 03:35:16.330: E/dalvikvm(863): Could not find class 'com.jcraft.jzlib.Deflater', referenced from method io.netty.handler.codec.spdy.SpdyHeaderBlockJZlibEncoder.<init>
09-22 03:35:16.330: W/dalvikvm(863): VFY: unable to resolve new-instance 574 (Lcom/jcraft/jzlib/Deflater;) in Lio/netty/handler/codec/spdy/SpdyHeaderBlockJZlibEncoder;
09-22 03:35:16.330: D/dalvikvm(863): VFY: replacing opcode 0x22 at 0x0005
09-22 03:35:16.340: W/dalvikvm(863): VFY: unable to resolve instance field 1051
09-22 03:35:16.340: D/dalvikvm(863): VFY: replacing opcode 0x54 at 0x0003
09-22 03:35:16.340: W/dalvikvm(863): VFY: unable to resolve instance field 1051
09-22 03:35:16.340: D/dalvikvm(863): VFY: replacing opcode 0x5b at 0x0049
09-22 03:35:16.350: W/dalvikvm(863): VFY: unable to resolve instance field 1051
09-22 03:35:16.350: D/dalvikvm(863): VFY: replacing opcode 0x5b at 0x000b
09-22 03:35:16.361: I/dalvikvm(863): Could not find method com.jcraft.jzlib.Deflater.deflateEnd, referenced from method io.netty.handler.codec.spdy.SpdyHeaderBlockJZlibEncoder.end
09-22 03:35:16.361: W/dalvikvm(863): VFY: unable to resolve virtual method 4173: Lcom/jcraft/jzlib/Deflater;.deflateEnd ()I
09-22 03:35:16.361: D/dalvikvm(863): VFY: replacing opcode 0x6e at 0x000b
09-22 03:35:16.361: D/dalvikvm(863): DexOpt: unable to opt direct call 0x104b at 0x07 in Lio/netty/handler/codec/spdy/SpdyHeaderBlockJZlibEncoder;.<init>
09-22 03:35:16.381: D/MultiplexChannelConnMgr(863): Catch error: null
**09-22 03:35:16.381: W/System.err(863): java.nio.channels.ClosedChannelException**

【问题讨论】:

【参考方案1】:

您需要将 com.jcraft.jzlib 添加到您的类路径中。这是通过添加 jzlib jar 来完成的。

http://www.jcraft.com/jzlib/

【讨论】:

非常感谢。我很高兴能解决这个问题。事实上问题同样很明显,但没有你的帮助我仍然无法继续前进。我确实需要学习如何解决问题。再次感谢。

以上是关于在 Android 上添加 spdy 编解码器后使用 netty 连接失败的主要内容,如果未能解决你的问题,请参考以下文章

android 4.1 中的媒体编解码器示例实现

Android 无法实例化编解码器“video/avc”

Android 手机可以解码和播放带有 iLBC 编解码器的 *.caf 文件吗?

Android 音视频 - MediaCodec 编解码音视频

Android 音视频 - MediaCodec 编解码音视频

Android 音视频 - MediaCodec 编解码音视频