First launch take long time (ClassLoader referenced unknown path)

After updating my Android studio to 2.0 and gradle to 2.0.0 and SDK-Platform to 23.0.3 When I want to launch application it take too much time (about 2-3 second) and following warning appears in Android Monitor :

W/System: ClassLoader referenced unknown path: /data/app/net.hadifar.test-1/lib/arm
W/System: ClassLoader referenced unknown path: /data/app/net.hadifar.test-1/lib/arm
 W/art: Suspending all threads took: 5.439ms
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
W/art: Suspending all threads took: 6.808ms

But second time I launch application it's run as usual. Can any body knows what's the issue ?


Solution 1:

In version 2.0 a new feature was added instant-run.

To enable this feature tool adds a lots of meta information, so the first build and upload takes more time.

Be aware about

  • setting minSdkVersion 15 or higher to get any profit;

  • Instant Run does not currently work with Jack (to support java 8) and will be disabled while using the new toolchain;

  • you may still encounter some glitches and bugs;

Here we can write (or vote) issues (report to make the better tool).

Solution 2:

There is a strange behaviour in newly released A.S 2.0 (or 2.1) and screen turns to black (or Activity pause) for seconds. As doc explained first build may take longer in A.S 2.0 But this issue happen in Runtime.

A quick fix based on @Skadoosh comment's would be disable instant Run:

Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run

More info:

When you deploy a clean build, Android Studio instruments your app to allow Instant Run to push code and resource updates. Although updating the running app happens much more quickly, the first build may take longer to complete. You can improve the build process by configuring a few DexOptions settings:

android {
  ...
  dexOptions {
    maxProcessCount 4 // this is the default value
    javaMaxHeapSize "2g"
  }
}

Also for warning Before Android 4.1. it says :

Instant Run is supported only when you deploy the debug build variant, use Android Plugin for Gradle version 2.0.0 or higher, and set minSdkVersion to 15 or higher in your app's module-level build.gradle file. For the best performance, set minSdkVersion to 21 or higher.

Seeing this video from Googler may help you understand a bit about Instant Run.