-3

I am getting the below error everytime I am building my APK; Gradle build shows it has been done successfully but while installing the APK at my phone, it crashes everytime

10-04 22:52:53.848 9297-9297/com.usfca.studentrecordsverify E/Trace: error opening trace file: No such file or directory (2)
10-04 22:52:53.908 9297-9297/com.usfca.studentrecordsverify E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.monkeyPatchExistingResources
10-04 22:52:53.908 9297-9297/com.usfca.studentrecordsverify W/dalvikvm: VFY: unable to resolve check-cast 1786 (Landroid/util/ArrayMap;) in Lcom/android/tools/fd/runtime/MonkeyPatcher;
10-04 22:52:53.908 9297-9297/com.usfca.studentrecordsverify E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.pruneResourceCache
10-04 22:52:53.908 9297-9297/com.usfca.studentrecordsverify W/dalvikvm: VFY: unable to resolve const-class 1786 (Landroid/util/ArrayMap;) in Lcom/android/tools/fd/runtime/MonkeyPatcher;
10-04 22:52:53.928 9297-9297/com.usfca.studentrecordsverify W/dalvikvm: VFY: unable to resolve virtual method 437: Landroid/content/Context;.getSystemService (Ljava/lang/Class;)Ljava/lang/Object;
10-04 22:52:53.928 9297-9297/com.usfca.studentrecordsverify W/dalvikvm: VFY: unable to resolve virtual method 231: Landroid/app/Activity;.stopLockTask ()V
10-04 22:52:53.928 9297-9297/com.usfca.studentrecordsverify E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.usfca.studentrecordsverify.MainActivity.access$super
10-04 22:52:53.928 9297-9297/com.usfca.studentrecordsverify W/dalvikvm: VFY: unable to resolve check-cast 226 (Landroid/os/PersistableBundle;) in Lcom/usfca/studentrecordsverify/MainActivity;
10-04 22:52:53.928 9297-9297/com.usfca.studentrecordsverify W/dalvikvm: VFY: unable to resolve virtual method 419: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
10-04 22:52:53.928 9297-9297/com.usfca.studentrecordsverify W/dalvikvm: VFY: unable to resolve virtual method 154: Landroid/app/Activity;.onVisibleBehindCanceled ()V
10-04 22:52:53.928 9297-9297/com.usfca.studentrecordsverify W/dalvikvm: VFY: unable to resolve virtual method 158: Landroid/app/Activity;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
10-04 22:52:53.928 9297-9297/com.usfca.studentrecordsverify E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.usfca.studentrecordsverify.MainActivity.access$super

Here is the build.gradle

Christopher
  • 9,682
  • 7
  • 47
  • 76

2 Answers2

0

android.util.ArrayMap was introduced with API-Level 19 (ArrayMap). If you run the code on a Android 4.2.2 device, it it will not find this class on your device and your app will crash.

You can use a java.util.Map instead. It is not as performant as the ArrayMap, but it is available on every Android platform.

Christopher
  • 9,682
  • 7
  • 47
  • 76
  • I tried running it in Android 5.0, 6.0 even it fails there; Also getting the same in Emulators with API level 21 – Mayank Thirani Oct 05 '16 at 06:19
  • Have you tried to disable Instant Run. Furthermore, your support libraries are a bit outdated. 24.2.1 is available. Maybe this helps. Additionally, I would really check, if do not use API that is not available on your hardware. – Christopher Oct 05 '16 at 06:25
0

change your minSdkVersion to 19

defaultConfig {
   applicationId "com.usfca.studentrecordsverification"
   minSdkVersion 19
   targetSdkVersion 23
   versionCode 1
   versionName "1.0"
}

Because ArrayMap was introduced with API-Level 19!