自从将Gradle Plugin for
Android更新为2.0.0后,Android Studio 2.0中的所有项目都会出现许多错误消息.
我想知道这个的原因,可能还有如何避免它.
这似乎与我的项目代码无关,因为错误也出现在空白或空白项目中.事实上,即使在空白项目中第一次调用onCreate()之前,仍有数百行警告和错误.
这是记录错误的一小部分:
I/dalvikvm: Could not find method android.content.Context.getSystemService, referenced from method com.example.test.MainActivity.access$super
W/dalvikvm: VFY: unable to resolve virtual method 450: Landroid/content/Context;.getSystemService (Ljava/lang/Class;)Ljava/lang/Object;
D/dalvikvm: VFY: replacing opcode 0x6f at 0x004b
I/dalvikvm: Could not find method android.app.Activity.stopLockTask, referenced from method com.example.test.MainActivity.access$super
W/dalvikvm: VFY: unable to resolve virtual method 246: Landroid/app/Activity;.stopLockTask ()V
D/dalvikvm: VFY: replacing opcode 0x6f at 0x00b9
E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.test.MainActivity.access$super
W/dalvikvm: VFY: unable to resolve check-cast 229 (Landroid/os/PersistableBundle;) in Lcom/example/test/MainActivity;
D/dalvikvm: VFY: replacing opcode 0x1f at 0x00f1
I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method com.example.test.MainActivity.access$super
W/dalvikvm: VFY: unable to resolve virtual method 432: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0101
I/dalvikvm: Could not find method android.app.Activity.onVisibleBehindCanceled, referenced from method com.example.test.MainActivity.access$super
W/dalvikvm: VFY: unable to resolve virtual method 169: Landroid/app/Activity;.onVisibleBehindCanceled ()V
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0111
I/dalvikvm: Could not find method android.app.Activity.onWindowStartingActionMode, referenced from method com.example.test.MainActivity.access$super
W/dalvikvm: VFY: unable to resolve virtual method 173: Landroid/app/Activity;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0137
E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.test.MainActivity.access$super
W/dalvikvm: VFY: unable to resolve check-cast 229 (Landroid/os/PersistableBundle;) in Lcom/example/test/MainActivity;
D/dalvikvm: VFY: replacing opcode 0x1f at 0x019a
E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method com.example.test.MainActivity.access$super
使用Gradle Plugin 1.5.0一切都很顺利.
使用Gradle Plugin 2.0.0会出现这些错误.
我更新到2.0.0,因为Android Studio 2.0推荐更新:
The project is using an old version of the Android Gradle plugin. To
take advantage of all the latest features, such as Instant Run, we
strongly recommend that you update the Android Gradle plugin to
version 2.0.0.
由于在任何应用程序的开头都有数百行错误,以后会有更多错误,这使得使用logcat进行调试非常困难.
我已经尝试按照in this answer所述降级到1.5.0.这确实可以防止错误出现.无论如何,我不认为这是一个解决方案,而是一个解决方案,因为我不能使用插件2.0.0的新功能.
最佳答案 是的,不幸的是,Android团队决定在这些消息上使用INFO而不是VERBOSE标记:
https://code.google.com/p/android/issues/detail?id=198567
解决方案是创建自定义筛选器.给它一个[过滤器名称].单击Android Monitor窗口工具栏右侧的[编辑过滤器配置].在[日志标签]中,输入“^(?!(dalvikvm))”,减去引号,并确保旁边有[正则表达式].在[包名称]字段中,输入您的顶级包名称(例如com.example.me).为[Log Level]选择Debug,然后单击[OK].最后,确保在工具栏中选择新的过滤器.