14

Recently i have upgraded Android Studio from 1.5 to 2.0.

With that i am using gradle 2.0.0

classpath 'com.android.tools.build:gradle:2.0.0'

But there seems some issue with it, whenever i am running my app for first time, it is showing while/black screen for 10-15 seconds.

There is nothing i am doing on applicationClass or launcher activity, but then also it is taking this much time.

I don't know whether it is issue with AS 2.0 or Gradle 2.0.0. Strange thing is that it is working properly on emulator, it is just taking time on device. So there might be possibility of device RAM or processing issues, but i have checked it in 10-12 devices and all devices have same issue.

Problem arise when i am running my application for first time, then after it is working as usual and loads launcher activity within fraction of seconds.

Can anyone please help me in this?

Ravi
  • 34,851
  • 21
  • 122
  • 183
  • So, you are referring to the fact that the Instant Run feature on an emulator is practically instant and you somehow expect a physical device to act the same? – OneCricketeer Apr 21 '16 at 05:04
  • but when i am clearing data from app on device, and then running it, first time it showing same white/black screen for10-15 seconds, at that time device is not connected so it means there is no connection of instant run. – Ravi Apr 21 '16 at 05:07
  • I'm not sure what screen you are meaning. When the app itself runs? Or as it is installed? – OneCricketeer Apr 21 '16 at 05:09
  • 4
    http://stackoverflow.com/questions/36623917/first-launch-take-long-time-in-android – Amir Apr 21 '16 at 05:09
  • @cricket_007 when you are running app for first time, whether its first time after installation or first time after clearing cache data. – Ravi Apr 21 '16 at 05:10
  • Turn off your instant run and your problem will be fixed. – Amir Apr 21 '16 at 05:10
  • @Amir that doesn't seems solution, you mean to say that is bug in instant-run?? – Ravi Apr 21 '16 at 05:11
  • I think so. Also your min API should be above 15 to instant run work properly. – Amir Apr 21 '16 at 05:12
  • Also it's not affect your release APK. because of some initialization in debug mode this happen in first launch. – Amir Apr 21 '16 at 05:14
  • If that is problem with instant-run, it should work properly when i disconnect device. But it is not. – Ravi Apr 21 '16 at 05:18
  • When you upgraded to AS 2.0 did you got warning about JDK version.If yes please update your JDK.Your should be 1.8@ Ravi Rupareliya – Lips_coder Apr 21 '16 at 07:24
  • I think its bug in instant run...same thing is happening with my app too...device holds on for white screen for 10-15 seconds on its first launch and even after disconnecting it from AS same thing happend [Another Question](http://stackoverflow.com/questions/36575229/android-studio-2-0-pause-white-screen-on-app-first-run) – Burhanuddin Rashid Apr 27 '16 at 12:57
  • I have also experienced this issue and in my case the first run time improves significaltly setting the `minSdkVersion` to `21` as stated here: http://developer.android.com/intl/es/tools/building/building-studio.html#instant-run – antonio Apr 28 '16 at 09:25
  • if you feel 2.0 version is issue then you can try updating studio to 2.1 – Vivek Mishra May 03 '16 at 08:46
  • 1
    i have the same problem and version 2.1 didn't help – Mounir Elfassi May 03 '16 at 23:53
  • what i'm doing now is using gradle version 1.5.1 or 1.5.0 not sure, and its running better in my devise – Mounir Elfassi May 03 '16 at 23:54
  • I am facing this issue in 2.1.3 – Aditya Vyas-Lakhan Sep 07 '16 at 06:55

4 Answers4

1

there seems some issue with it, whenever i am running my app for first time, it is showing while/black screen for 10-15 seconds.

I guess you have issue of Cold Start in your application.

Cold Start :

When a user launches an application, Android creates a new process that, during it charge, shows a black/white screen which is built with the application theme, or the theme of the activity that is the entry point.

This load can be increased if our application is complex and overwrites the application object, which is normally used to initialize the analytics, error reporters, etc.

Solution :

  1. Specify android:windowBackground in your application theme.
  2. Add Splash screen to your app.

For detailed information please check, http://saulmm.github.io/avoding-android-cold-starts

Thanks.

AndiGeeky
  • 11,266
  • 6
  • 50
  • 66
0

As documentation describe :

Instant Run pushes updated code and resources to your connected device or emulator by performing a hot swap, warm swap, or cold swap. It automatically determines the type of swap to perform based on the type of change you made.

Also document mentioned it's not Bug with instant run :

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"
  }
}
Amir
  • 16,067
  • 10
  • 80
  • 119
0

In android studio, open preferences. In the search bar(preferences dialog) type instant run or Navigate to Build, Execution, Deployment > Instant Run and uncheck all the options. But of course, you will lose the power of instant run.

Vaibhav Sharma
  • 2,293
  • 1
  • 17
  • 24
0

Change your classpath

classpath 'com.android.tools.build:gradle:2.0.0'

to your previous build version (for e.g)

classpath 'com.android.tools.build:gradle:1.5.0'
Viral Patel
  • 32,418
  • 18
  • 82
  • 110