问题
I just enabled instant run for my project. Building and uploading is faster but my app startup time has increased from a few hundreds of milliseconds to a few seconds.
I'm generally happy with that compromise. I just wanted to know if I was the only one noticing this and if there can be any chance to optimize that too ?
回答1:
This is a known bug in Android Studio I've been facing this problem for a long time and I came across a Reddit thread that explains the actual cause of the problem...
Here's the link to the Thread:
https://m.reddit.com/r/androiddev/comments/4m2v25/instant_run_causing_incredibly_long_app_start/
Until the problem has been resolved perform any of the following : 1. Turn off Instant Run 2. Revert back to version 2.8 of Gradle
Things you should do: 1. Wait until the problem is fixed
Sorry, this is a known issue right now. We are working on improving it in 2.3. The reason this happens is that: Initially, we split all your code into multiple dex files, and put them all inside a instant-run.zip file After the first install, we unzip that file and add all those classes to the classpath. This is the step that takes time, you see a white screen. In the worst case, you may even get an ANR. We split it up so that on subsequent updates, we only send out the dex files that have changed. In Android N, we have some more platform support via split APKs, which we leverage and should be faster.
回答2:
some good news for this thread. We have just release Android Studio 2.3 Canary 1, and it should completely fix the startup performance issue for Instant Run.
Please try it out and let us know what you think! Download link: http://tools.android.com/download/studio/builds/android-studio-2-3-canary-1
来源:https://stackoverflow.com/questions/36633938/starting-an-app-with-android-studio-instant-run-is-very-slow