[Android Pro] Goodbye compile run----Android Studio 2.0 Preview Release instant run feature

Source: Internet
Author: User

Reference to:http://www.cnblogs.com/soaringeveryday/p/4991563.html

Previous Android development has a headache and slow speed problem, that is, every time you change a line of code to see the results must be compiled to run to the phone or emulator, and need to start from the beginning (perhaps the login screen) to click on the interface you modified. Developing a complete Android app you may have to go through countless repetitive compilation runs, seriously slowing down the development process.

Recently react Native for Android was able to solve this problem, the modified code can be directly on the simulation to refresh the current modified interface (after all, with Web technology). So Google can look down to let FB occupy its own development area? No way!

Instant running: Faster build and deploy

Finally now Android Studio 2 Preview has been launched, one of the revolutionary features is instant run (Instant running)! The new instant-on functionality allows developers to write Android native code like HTML Web pages, allowing them to modify the code and see the result of modifying the code while on the emulator or on the actual device.

Here are a few platforms, after downloading the direct decompression into the Bin folder can be run (it is recommended to keep the previous version of Android Studio1.4 or 1.5 do not delete), and it will automatically import the old version of the project and settings information.

    • Windows:https://dl.google.com/dl/android/studio/ide-zips/2.0.0.0/android-studio-ide-143.2443734-windows.zip ( (MB)

    • Mac:https://dl.google.com/dl/android/studio/ide-zips/2.0.0.0/android-studio-ide-143.2443734-mac.zip (319 MB)

    • Linux:https://dl.google.com/dl/android/studio/ide-zips/2.0.0.0/android-studio-ide-143.2443734-linux.zip (318 MB)

Actual project evaluation

Here I will actually demonstrate a project with the Android Studio 2.0 with the Genymotion simulator

Enter Android Studio2.0 open the project and then go to setting->build,execution,deployment->instant run to view the instant-running settings item, you may find that the tick item is gray,

This is because your project Gradle is old, click on Update Project to wait a few moments.

Update the dependencies I found for project Gragle:

dependencies {        classpath ' com.android.tools.build:gradle:1.2.3 '    }

has been updated to:

dependencies {        classpath ' com.android.tools.build:gradle:2.0.0-alpha1 '    }

This time again the settings of instant run will be found to be checked, please keep the tick:

At this point we look at the left side of the Run button with a sign similar to "Lightning":

We have one of these pages in our project:

Be prepared to replace the temporary visit with another string such as "Hello" and change the icon on the left. It is a custom control with custom properties, and the layout code fragment is

 <   android:id  = "@+id/ll_sudden_visit"   Android: Layout_width  = "Match_parent"   Android: Layout_height  = "Wrap_content"   app:        Clirbriconid  = "@drawable/icon_temp"   = "@string/sudden_visit"   App:clirbractioniconid         = "@drawable/btn_go_nor"  />  

First we need to run this project first, and then click on the interface until the above interface to stop moving, this time we modify the above code (this step is necessary, otherwise the instant run function will cause problems, causing re-run)

This time we let the simulator remain on this page, while modifying the layout code to:

< com.qianmi.shine.widget.CommonLeftIconRightButtonRelativeLayout         Android:id = "@+id/ll_sudden_visit"         android:layout_width= "Match_parent"        android:layout_height= "Wrap_ Content "        app:clirbriconid=" @drawable/icon_resent "//Modify 1        app: Clirbrtitlename= "Hello"//Modify 2        app:clirbractioniconid= "@drawable/btn_go_nor"         />

Then click on the Run with Lightning:

You can see a quick refresh of the interface:

Final description

It is to be explained that, in the course of my use, I have found that changing the instant run only applies to layout modifications. That is, we can make a change and then run to see the effect as a "period", in this cycle you just modify the XML layout file, or the logic code is not related to the file, then you click on the run will trigger instant run, otherwise, Android Studio still compiles and runs again.

In fact, it is reasonable to think, for example, if you modify the code, and the code is exactly the current interface "logic premise", then how can you just brush the current interface to get the correct results?

There is an official article for reference to what forms of code modification is currently supported by instant run

Https://sites.google.com/a/android.com/tools/tech-docs/instant-run

Not all code changes is supported by Instant Run currently. Here are the current list of supported code change scenarios.



Code Change

Instant Run Support

Change instance method implementation

Change static method implementation

Add or remove a class

Supported

ADD, remove, or change a string resource

Supported but requires an Activity restart.

Here is some code changes this Instant Run does not currently support:

    • Add/remove/change annotations

    • Add/remove/change an instance field

    • Add/remove/change a static field

    • Add/remove a static method signature

    • Change a static method signature

    • Add/remove an instance method

    • Change an instance method signature

    • changing which parent class The current class inherits from

    • Change the list of implemented interfaces

    • Changing static initializer of a class

Over the coming months, we plan to expand the Instant Run enable more change types, and continue to make your edit, build, Run cycle faster.

[Android Pro] Say goodbye to compile run----Android Studio 2.0 Preview Release instant run feature

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.