赞
踩
这几天在对程序进行混淆处理测试时,在程序中使用了友盟组件的地方会报错,比如自动更新,报错异常如:
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.umeng.update.UpdateDialogActivity}: java.lang.IllegalArgumentException: ResClass is not initialized. Please make sure you have added neccessary resources. Also make sure you have com.example.R$* configured in obfuscation. field=umeng_update_dialog
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
- at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
- at android.app.ActivityThread.access$600(ActivityThread.java:130)
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
- at android.os.Handler.dispatchMessage(Handler.java:99)
- at android.os.Looper.loop(Looper.java:137)
- at android.app.ActivityThread.main(ActivityThread.java:4745)
- at java.lang.reflect.Method.invokeNative(Native Method)
- at java.lang.reflect.Method.invoke(Method.java:511)
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
- at dalvik.system.NativeStart.main(Native Method)
- Caused by: java.lang.IllegalArgumentException: ResClass is not initialized. Please make sure you have added neccessary resources. Also make sure you have com.example.R$* configured in obfuscation. field=umeng_update_dialog
- at com.umeng.common.Res.a(Unknown Source)
- at com.umeng.common.Res.d(Unknown Source)
- at com.umeng.update.UpdateDialogActivity.onCreate(Unknown Source)
- at android.app.Activity.performCreate(Activity.java:5008)
- at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
解决思路:
使用了混淆, 请添加
- -keepclassmembers class * {
- public <init>(org.json.JSONObject);
- }
这是由于SDK中的部分代码使用反射来调用构造函数, 如果被混淆掉, 在运行时会提示"NoSuchMethod"错误。 另外,由于SDK需要引用导入工程的资源文件,通过了反射机制得到资源引用文件R.java,但是在开发者通过proguard等混淆/优化工具处理apk时,proguard可能会将R.java删除,如果遇到这个问题,请在proguard配置文件中添加keep命令如:
- -keep public class [您的应用包名].R$*{
- public static final int *;
- }
把[您的应用包名] 替换成您自己的包名,如com.yourcompany.example。 如果您使用了双向反馈功能,还需要添加下面代码,以免我们自定义的UI被混淆:
- -keep public class com.umeng.fb.ui.ThreadView {
- }
在proguadr-android.txt文件中,添加如下代码:
- -keepclassmembers class * {
- public <init>(org.json.JSONObject);
- }
- -keep public class com.example.R$*{
- public static final int *;
- }
至此,问题解决
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。