简体   繁体   中英

Android Errors in released app with ProGuard

I have done a app in which I am Using EPSON Printer SDK So there I Have some Library files for EPSON thermal printer I am using them In my app

So here App is running Successfully and I am printing the data

Now I made a Release Version of my apk and Signed it

My app is in different package(com.mytest.mapp) and printer is in other package (com.epson.epos2_printer) and I am using library libepos2.so

So its crashing when I try to print the application

I followed many proguard forms and I have added this in proguard-rules

-keep class  com.epson.epos2** {
    *;
}

But am still facing same issue when minifyEnabled true

If its false its working fine for Release version can any 1 suggest me what I am missing for EPSON SDK library

This is my error Log

   No pending exception expected: java.lang.ClassNotFoundException: Didn't find class "com.epson.epsonio.bluetooth.NetBt" on path: DexPathList[[zip file "/data/app/com.mytest.mapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mytest.mapp-1/lib/arm, /vendor/lib, /system/lib]]
   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:511)
   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:469)
   at java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader, java.lang.String) (Runtime.java:-2)
   at java.lang.String java.lang.Runtime.doLoad(java.lang.String, java.lang.ClassLoader) (Runtime.java:428)
   at void java.lang.Runtime.loadLibrary(java.lang.String, java.lang.ClassLoader) (Runtime.java:369)
   at void java.lang.System.loadLibrary(java.lang.String) (System.java:989)
   at void com.epson.epos2.discovery.Discovery.<clinit>() ((null):-1)
   at void com.mytest.mapp.pdata.PrintMActivity.onCreate(android.os.Bundle) ((null):-1)
   at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6289)
   at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1119)
   at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2655)
   at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2767)
   at void android.app.ActivityThread.access$900(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:177)
   at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1449)
   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
   at void android.os.Looper.loop() (Looper.java:145)
   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:5951)
   at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[], boolean) (Method.java:-2)
   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:372)
   at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:1400)
   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:1195)

I also Got Same error With Bluetooth printer and Epson Printer.. Better to use

-ignorewarnings / -dontwarn class/package name
-keep class * {
    public private *;
}

Dot forget to Keep our class/package name

Hope this works

I know this is an old threat but I hope this will help people who come across this topic in the future.

Adding broad -keep options such as the ones shown below is a bad practice, this will prevent ProGuard from shrinking, optimizing and obfuscating the entire project (except parts of code marked as protected ).

-keep class * {
    public private *
}

Instead when encountering a ClassNotFoundException , you should just add a -keep option for the missing class. In OP's case that would be -keep class com.epson.epsonio.bluetooth.NetBt

You can check out the difference on the ProGuard Playground , it visualises nicely which classes are affected by your -keep options without the need to compile over and over again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM