Netty library not work in android release apk?

Viewed 686

I made proxy server with netty on android by using the codes available on netty GitHub example, actually, I just copy them and use them in android. here is the netty proxy server example : https://github.com/netty/netty/tree/4.0/example/src/main/java/io/netty/example/proxy Now I faced two problems, the first netty does not work properly in the first run but after closing the app and open it again it works well I don't know why in the first run it doesn't work. 2. netty does not work in the release mode and when I check the logs I see this error

Rejecting re-init on previously-failed class java.lang.Class<g.b.b.k>: java.lang.ExceptionInInitializerError: 
        at void g.b.b.m.<clinit>() (ByteBufUtil.java:82)
        at void g.b.b.k.<clinit>() (ByteBufAllocator.java:24)
        at void g.b.c.f0.<init>(g.b.c.e, g.b.c.y0) (DefaultChannelConfig.java:59)
        at void g.b.c.f0.<init>(g.b.c.e) (DefaultChannelConfig.java:72)
        at void g.b.c.i1.e.<init>(g.b.c.i1.g, java.net.ServerSocket) (DefaultServerSocketChannelConfig.java:50)
        at void g.b.c.i1.k.b$b.<init>(g.b.c.i1.k.b, g.b.c.i1.k.b, java.net.ServerSocket) (NioServerSocketChannel.java:201)
        at void g.b.c.i1.k.b$b.<init>(g.b.c.i1.k.b, g.b.c.i1.k.b, java.net.ServerSocket, g.b.c.i1.k.b$a) (NioServerSocketChannel.java:199)
        at void g.b.c.i1.k.b.<init>(java.nio.channels.ServerSocketChannel) (NioServerSocketChannel.java:90)
        at void g.b.c.i1.k.b.<init>() (NioServerSocketChannel.java:75)
        at java.lang.Object java.lang.reflect.Constructor.newInstance0(java.lang.Object[]) (Constructor.java:-2)
        at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:343)
        at g.b.c.e g.b.c.z0.a() (ReflectiveChannelFactory.java:44)
        at g.b.c.j g.b.a.a.v() (AbstractBootstrap.java:310)
        at g.b.c.j g.b.a.a.o(java.net.SocketAddress) (AbstractBootstrap.java:272)
        at g.b.c.j g.b.a.a.g(java.net.SocketAddress) (AbstractBootstrap.java:268)
        at g.b.c.j g.b.a.a.e(int) (AbstractBootstrap.java:246)
        at void d.a.a.f.d.run() (MainProxyServer.java:55)
        at void d.a.a.j.j$c$a.a(m.a.a.a) (Main.kt:115)
        at java.lang.Object d.a.a.j.j$c$a.invoke(java.lang.Object) (Main.kt:94)
        at void m.a.a.b$a.a() (Async.kt:138)
        at java.lang.Object m.a.a.b$a.invoke() (Async.kt:-1)
        at java.lang.Object m.a.a.c.call() (Async.kt:-1)
        at void java.util.concurrent.FutureTask.run() (FutureTask.java:266)
        at void java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run() (ScheduledThreadPoolExecutor.java:301)
        at void java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) (ThreadPoolExecutor.java:1167)
        at void java.util.concurrent.ThreadPoolExecutor$Worker.run() (ThreadPoolExecutor.java:641)
        at void java.lang.Thread.run() (Thread.java:919)

but it works in debug mode well.

2 Answers

about the first problem maybe you need to add ProviderInstaller into your app because some android versions like android 5 seems can not handle SSL but by adding this I think the problem will be fixed.

About the second problem, there are 2 options to resolve it:

  1. just add -keep class io.netty.**{*;} to the file named proguard-rules.pro under this module.

  2. disable code confuse, modify file named build.gradle under this module like this:

.....
buildTypes {
....
      release {
          minifyEnabled false
          .....
      }
....
}
....

Pick one in your condition.

Related