1. 程式人生 > >Android5.1-s5p6818平臺程式碼混淆導致jar裡面的類不能讀取---classnotfound exception

Android5.1-s5p6818平臺程式碼混淆導致jar裡面的類不能讀取---classnotfound exception

貼上異常log:
12-30 11:37:02.997 2205-2205/com:push A/art: art/runtime/runtime.cc:289] Pending exception java.lang.ClassNotFoundException thrown by 'unknown throw location'
12-30 11:37:02.997 2205-2205/com.A/art: art/runtime/runtime.cc:289] java.lang.ClassNotFoundException: Didn't find class "com.yuntongxun.ecsdk.core.voip.AudioDeviceAndroid" on path: DexPathList[[zip file "/system/app/aner.apk"],nativeLibraryDirectories=[/system/app/EE/lib/arm, /vendor/lib, /system/lib]]
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:511)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:469)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at int com.yuntongxun.ecsdk.core.jni.IVoIPNative.setAudioContext(java.lang.Object) ((null):-2)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at com.yuntongxun.ecsdk.core.ai com.yuntongxun.ecsdk.core.ai.a(android.content.Context) ((null):-1)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at void com.yuntongxun.ecsdk.core.ah.a(android.content.Context) ((null):-1)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at void com.yuntongxun.ecsdk.ECClientService.onCreate() ((null):-1)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at void android.app.ActivityThread.handleCreateService(android.app.ActivityThread$CreateServiceData) (ActivityThread.java:2761)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at void android.app.ActivityThread.access$1800(android.app.ActivityThread, android.app.ActivityThread$CreateServiceData) (ActivityThread.java:151)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1386)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at void android.os.Looper.loop() (Looper.java:135)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:5254)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[], boolean) (Method.java:-2)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:372)
12-30 11:37:02.997 2205-2205/com.. A/art: art/runtime/runtime.cc:289]   at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:903)
12-30 11:37:02.997 2205-2205/com..A/art: art/runtime/runtime.cc:289]   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:698)


編譯OK,但是啟動榮聯雲的IM功能時候就出現了沒有問題,定位到log發現是一個類沒有找到,也就時classnotfoundexception! 在檢查發現這個類是的存在與榮聯雲的jar裡面的,但是我明明匯入了這個jar,而且在android.mk裡面也做了相應配置,為什麼會出現這種情況?

突然想到添加了混淆的Proguard.flag檔案,有可能把jar也混淆了所以導致功能邏輯裡面沒有可以呼叫的正確類名了!仔細參考了一下Proguard混淆檔案的語法確定了這個問題(http://blog.csdn.net/lovexjyong/article/details/24652085

解決辦法:

在原始碼自建系統應用的目錄下將Proguard.flag檔案裡面新增:

-libraryjars libs/Yuntx_FullLib_v5.3.0r.jar
-keep class com.yuntongxun.ecsdk.**{*;}
保證jar裡面對應的類不會被混淆,再次編譯後刷機啟動IM功能ok!