Android 5.0,代号 Lollipop,源码终于在2014年12月3日放出,国内一大批厂商跟进。最大的改变是默认使用 ART(Android Runtime) ,替换了之前的 Dalvik 虚拟机,提出了 Material Design 界面风格。之前发布的 app 可能需要作一些改动,暂时收集了一些问题,希望对大家有所帮助。
1. Intent/Service
在低于 Android 5.0 版本,程序运行正常。用户抱怨在新的 Android 5.0 设备上崩溃,我们还没有最新的设备,所以暂时用 Android 模拟器调试。
在输出的 log 中可以看到这样的记录:
E/AndroidRuntime(26479): java.lang.RuntimeException: Unable to start activity ComponentInfo{PACKAGE_NAME/.ACTIVITY_NAME}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.bda.controller.IControllerService }
E/GameActivity(18333): Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.bda.controller.IControllerService }
E/GameActivity(18333): at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1982)
E/GameActivity(18333): at android.app.ContextImpl.startServiceCommon(ContextImpl.java:2020)
E/GameActivity(18333): at android.app.ContextImpl.startService(ContextImpl.java:1995)
E/GameActivity(18333): at android.content.ContextWrapper.startService(ContextWrapper.java:533)
E/GameActivity(18333): at com.bda.controller.a.d(Unknown Source)
通过查看堆栈崩溃信息,我们看到使用了第三方的 controller.jar 包导致错误。Controller 是在设备屏幕上模拟游戏手柄功能的包,下载最新的 Moga developers SDK ,下载了 controller-sdk-std-1.3.1.zip,2013 Feb 01 发布的,有点旧了。里面有 com.bda.controller.jar,没有源码。
尝试 zip 解压 controller.jar 文件,反编译 .class 文件 com/bda/controller/BaseController.class
想查看 bytecode,使用 javap -c BaseController.class
public final boolean init(); Code: 0: aload_0 1: getfield #113 // Field mIsBound:Z 4: ifne 48 7: new #193 // class android/content/Intent 10: dup 11: ldc #165 // class com/bda/controller/IControllerService 13: invokevirtual #195 // Method java/lang/Class.getName:()Ljava/lang/String; 16: invokespecial #201 // Method android/content/Intent."<init>":(Ljava/lang/String;)V 19: astore_1 20: aload_0 21: getfield #142 // Field mContext:Landroid/content/Context; 24: aload_1 25: invokevirtual #204 // Method android/content/Context.startService:(Landroid/content/Intent;)Landroid/content/ComponentName; 28: pop 29: aload_0 30: getfield #142 // Field mContext:Landroid/content/Context; 33: aload_1 34: aload_0 35: getfield #132 // Field mServiceConnection:Lcom/bda/controller/Controller$ServiceConnection; 38: iconst_1 39: invokevirtual #208 // Method android/content/Context.bindService:(Landroid/content/Intent;Landroid/content/ServiceConnection;I)Z 42: pop 43: aload_0 44: iconst_1 45: putfield #113 // Field mIsBound:Z 48: aload_0 49: getfield #113 // Field mIsBound:Z 52: ireturn