4

Since updating Gradle Plugin for Android to 2.0.0, there are many error messages in all projects in Android Studio 2.0.

I would like to know the reason for this and possibly how to avoid it.

This seems not related to the code of my projects, as the errors also show up in an empty or blank project. There are in fact hundreds of lines of warnings and errors, even before first call of onCreate() in a blank project.

This is a small excerpt of the logged errors:

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

With Gradle Plugin 1.5.0 everything went fine. With Gradle Plugin 2.0.0 these errors come up.

I updated to 2.0.0, because Android Studio 2.0 recommends the update:

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.

As there are hundreds of lines of errors at the start of any app and many more later, this makes using logcat for debugging extremely difficult.

I have tried to downgrade to 1.5.0 as described in this answer. This does actually prevent the errors to come up. Anyhow, I do not regard this as a solution, but rather a work-around, as I cannot use the new features of plugin 2.0.0.

Community
  • 1
  • 1
bluebeat
  • 71
  • 6
  • Did you try `Clean -> Build` after updating? – Prerak Sola Apr 22 '16 at 11:42
  • 1
    These are perfectly normal. You have had them before, though perhaps not in this volume. They are cases where code (including libraries) refer to classes, methods, or other symbols that do not exist on your particular device, as those symbols are from newer versions of Android. For example, `PersistableBundle` was introduced on API Level 21 (Android 5.0). They do not indicate any particular problems in your code. – CommonsWare Apr 22 '16 at 11:43
  • this might help http://stackoverflow.com/questions/17727645/how-to-update-gradle-in-android-studio – Bharatesh Apr 22 '16 at 12:05
  • @PrerakSola: I tried, but Android Studio does clean the project anyhow after updating the plugin. – bluebeat Apr 28 '16 at 17:51
  • @CommonsWare Of course it is not related to my code, that is what I have written. Nevertheless, the number of errors lets logcat overflow, so that important debug messages cannot be seen anymore. In addition, with plugin 1.5.0 the errors do not come up, although the project is compiled to API Level 23. – bluebeat Apr 28 '16 at 17:54
  • @skadoosh: this is deprecated, as Android Studio lets you update Gradle plugin with one click – bluebeat Apr 28 '16 at 17:56

1 Answers1

2

Yes, unfortunately, the Android team decided to use the INFO rather than VERBOSE tag on these messages: https://code.google.com/p/android/issues/detail?id=198567

The solution is to create a custom filter. Give it a [Filter Name]. Click [Edit Filter Configuration] on the right of the Android Monitor window toolbar. In the [Log Tag], enter "^(?!(dalvikvm))", minus the quotes, and make sure [Regex] is Checked next to it. In the [Package Name] field, enter your top-level package name (e.g. com.example.me). Select Debug for [Log Level] and click [OK]. Finally make sure to select your new filter back in the toolbar.

Wing Poon
  • 1,051
  • 8
  • 10