我正在用Android创建一个图书馆项目。
我想启用专业防护,但出现以下崩溃:
Process: com.mysdk.myapplication, PID: 15629
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/volley/VolleyLog;
at com.mysdk.sdk.api.b.a(Unknown Source)
at com.mysdk.sdk.api.mysdk.startmysdk(Unknown Source)
at com.mysdk.myapplication.App.onCreate(Unknown Source)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1026)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5099)
at android.app.ActivityThread.access$1600(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1464)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5885)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:819)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:709)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.volley.VolleyLog" on path: DexPathList[[zip file "/data/app/com.mysdk.myapplication-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mysdk.myapplication-1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.mysdk.sdk.api.b.a(Unknown Source)
at com.mysdk.sdk.api.mysdk.startmysdk(Unknown Source)
at com.mysdk.myapplication.App.onCreate(Unknown Source)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1026)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5099)
at android.app.ActivityThread.access$1600(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1464)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5885)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:819)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:709)
Suppressed: java.lang.ClassNotFoundException: com.android.volley.VolleyLog
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 14 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
在我的图书馆项目中,我有一个配置为以下内容的proguard-rules.pro文件:
-keep class com.android.volley.** { *; }
-keep interface com.android.volley.** { *; }
-keepclassmembers class com.android.volley.VolleyLog { *; }
-keep class org.apache.commons.logging.** { *; }
我在网络上找到了一些解决方案(例如将apache行添加到我的pro-guard文件中),但是它没有用。
有什么建议么?我想念什么?
谢谢。
最佳答案
指令
-keepclassmembers class com.android.volley.VolleyLog { *; }
告诉ProGuard保留类成员(方法,字段等),但仍让其混淆实际类的名称,这意味着可以在APK中将其重命名为“ a.a.b.a”之类的名称。
使用ClassyShark之类的工具来检查APK中是否包含
com.android.volley.VolleyLog
,如果没有,则将规则更改为:-keep class com.android.volley.VolleyLog { *; }
使ProGuard保留该类的名称。