Android Studio 1.0 (stable version) full strategy, androidstudio

Source: Internet
Author: User

Android Studio 1.0 (stable version) full strategy, androidstudio




This blog post mainly describes the following points:

1. install and use Android Studio

2. Features of Android Studio

3. Advantages of Android Studio

 


Install and use Android Studio


Android 1.0 Release:

In December 8, 2014, Google officially released the Android Studio 1.0 (stable version) integrated development environment for Android Developers ).

From May 2013 to December 2014, nearly one year and seven months, we finally hoped for the release of the 1.0 stable version.

Presumably, the vast majority of Android Developers have the same vision as xiaobian. Let's watch the cloud and see the Moon and the moon.


After a period of use, xiaobian has fallen in love with this outstanding IDE. As a long-term use of Eclipse + Genymotion (you have to use the Genymotion simulator, because the simulator that comes with Eclipse is too slow, generally wait for it to start, you can have a cup of coffee, if it is slower, you may have a roast chicken ^ @ ^. But you need to download, install, and configure the Genymotion simulator to be used with Eclipse. I would like to ask, are you tired ?) Android Studio is strongly recommended to you by xiaobian, an Android developer. As Google's son, it is so confident in the Age of fight dad. Android projects developed by Eclipse can be easily imported into Android Studio.


Introduction: Android Studio is an IDE developed by Google for Android Developers. It supports Windows, Mac, Linux, and other operating systems and is built based on the popular Java integrated development environment IntelliJ. This IDE showed up for the first time at the Google I/O developer conference in May 2013, and then launched several beta versions until December 8, 2014, google finally officially released the Android Studio 1.0 (stable version) integrated development environment for Android Developers ).


Note:: The ADT (Android Developer Tools), It seems that Android Studio will be used for Android development in the future.



Android Studio Installation:


Prerequisites: Because Android uses Java as the standard development language, you need to install the Java Development Environment in your operating system. If you have not installed the Java development environment, you can search for how to download, install, and configure environment variables online. This article does not describe too much. There are many graphic tutorials on the Internet. For Java JDK (Java Development Kit) Version. I installed the latest JDK 1.8 (for Java 8). For Android Studio, JDK 1.7 and 1.6 are acceptable.


The following describes how to install and configure the Java Development Environment:

Http://blog.sciencenet.cn/blog-830496-778851.html

Http://blog.csdn.net/yusiguyuan/article/details/14123669

Http://blog.sina.com.cn/s/blog_7d1c5c8601015ppr.html


After installing and configuring the Java development environment, go to the following URL:

Http://developer.android.com/sdk/index.html

You will see an Android Studio version for your current operating system. I demonstrated it on Apple's Macbook, so it is "Download Android Studio for Mac ", click this green button to download it.



Double-click the downloaded file (dmg for the Apple Computer) To Go To The Installation Wizard:



"Standard" (Standard) installation is a situation where no Android SDK (Software development kit) is available. If you have already installed the SDK, you can select "Custom" (Custom ), here we select the default Standard and click Next (Next ),



In, We need to select the "Accept" (Accept) Android SDK and simulator runtime environment respectively. Only after the Accept is selected can the "Finish" button be clicked. After you press the Finish button, wait for the installation of Android Studio, depending on the network speed.


After the installation is complete, double-click the Android Studio icon,



Now we can officially start our journey to Android Studio!


However, on the Apple computer, it is estimated that there will be a problem that has not been solved yet, that is, Android Studio cannot find the installed Java environment, and the following prompt box will be displayed:



Therefore, you need to make some changes by yourself. You need to modify the Info. plist file of Android Studio, open a terminal (go to> utility> terminal), and enter:


Vi/Applications/Android \ Studio. app/Contents/Info. plist (the vi editor is used here. You can also use your favorite editor, such as emacs. You can also find the Info. plist File Based on the path and change it with your favorite editor)


Replace


<Key> JVMVersion </key>

<String> 1.6 * </string>


Change


<Key> JVMVersion </key>

<String> 1.8 * </string> (because my JDK version is 1.8; if it is 1.7, it needs to be changed to 1.7 *; if it is JDK 1.6, there should be no startup issues)



After modification, you can start it.




(Note: The Android Studio version has been updated to 1.0.1. After the update, the JDK version changed to version 1.0 is incorrect. You can only change the Info. plist file once again)


The window shown in the figure above, I believe that IntelliJ IDEA users will not be unfamiliar.


You can choose to create a new project (Start a new Android Studio project) and Open an existing project (Open an existing Android Studio project. Let's create our first project and click "Start a new Android Studio project ",



You will see the Window jump like this.


Fill in the project name in the "Application name" field. Here I fill in the "world-famous" HelloWorld.

Fill in the Company website in the "Company Domain" column. Here I fill in enmingxie.com (this is random ). This actually determines the Package name of your project ).

If the "Project location" column is not changed, the Project will be stored in the default location. Of course, you can change it to any location you want.



Click Next to go to the Next step,



Here we can see several options, which are the platform your application wants to publish. The default option is "Phone and Tablet" (mobile Phone and Tablet). You can also choose "TV" (Google TV) and Wear (Google wearable devices, such as smart watches) and Glass (Google Glasses, here I have Not installed Google Glass SDK, so it shows Not installed ).


For each platform, we need to select the Minimum SDK version (Minimum SDK). For "Phone and Tablet", API 15 is selected by default (corresponding to Android 4.0.3, IceCreamSandwich ), you can also click the drop-down menu to select the minimum SDK version you want.




After the selection is complete, click Next to go to the Next step,



Seeing the window above, I believe that Eclipse's old users will smile, because it is very similar. Here, let's select the running interface at startup (to put it simply), that is, the Android Activity (Activity is an application interface that provides communication with users ). We select the default Blank Activity (Blank interface). You can also choose the Activity based on your needs, such as Google Maps Activity.


Click Next to go to the Next step,



Here, Let's enter some information about the Activity we created, which is similar to ADT:


Activity Name is the Activity Name.

Layout Name is the Layout Name.

Title is the Title displayed on the Activity.

Menu Resource Name is the Name of the Resource file in the Menu bar used.


I use the default one, and you can rewrite it as needed.


Click Finish to complete the project configuration. Android Studio will open the new project you just created for us:



The project window finally appeared. Is it a little excited. We can remove the Show Tips on Startup (the prompt is displayed at Startup) in the prompt window, so that the prompt box will not bother us at every Startup.


Basic use of Android Studio:



We can see that in the above window, we have roughly four areas from left to right (because the user interface configuration file activity_main.xml is selected by default), which is similar to Eclipse. From left to right, The first area is the project list area (the code and resources of each project are listed here, and I have expanded all the projects here for a one-to-one Introduction ), the second is all available components of the layout, the third is the visual layout area (see a mobile phone), and the fourth is the tree list and attribute settings of the components in the layout.


If you select the main project source code MainActivity. java, we can see this:



In the first area: Project List area, we can see that the structure of the entire project is similar to that of Eclipse, but there are some changes:

  1. AndroidManifest. xml: the basic configuration file of the Android project is separately stored in the "manifest" folder.

  2. The original src (source code) folder name is changed to java, But the package name is still the same as the original company domain name.

  3. Use the Gradle (middle Gradle Scripts) IntelliJ integrated development environment automation build tool (http://baike.baidu.com/view/9916271.htm)

  4. The Android SDK configuration is moved from AndroidManifest. xml to the build. Gradle (Module: app) file under gradle Scripts, such:



Let's take a look at the user interface configuration file activity_main.xml in the project, which is completely visualized editing. You only need to drag the components (the Widget column in the Palette) with the mouse, just like Eclipse. The Layout column in the Palette selects the Layout. Here I drag a few components (Button, RadioButton, CheckBox, Switch)



The structure of other folders, such as res, is basically the same as that of Eclipse.


For the management of the Android SDK version, click the small icon marked in the red box to bring up the SDK download management window similar to Eclipse:





Create an Android simulator and run the App:


Next we will create our own Android simulator (of course you can connect to the real machine to test your App, but the simulator of Android Studio is really powerful and has many styles, fast ). First, click the small icon marked in the red box:





We can see that Android Studio creates a simulator (AVD: Android Virtual Device) for us by default, which is 1080x1920 resolution for Nexus 5 API 21. We can delete it (this is not needed) and create a new simulator. Click the X button on the rightmost side, select the Delete option, and confirm deletion. The window will be displayed as follows:



Click Create a virtual device in the middle:


A new window will appear:



Here we can see that there are many different device templates for us to choose from. The list on the left has four categories: Phone (mobile Phone), Tablet (Tablet), Wear (wearable device, for example, smart watches and TVs have different templates in each category. First, select the Nexus S 4.0 resolution 480*800 device in the Phone, and click Next to go to the Next step,




Here, let's select a system image. We can select images of different API versions. The editor selects the latest Lollipop API 21 system image and arm architecture, you can also select an x86 or x86_64 architecture. Click Next,



In this step, we can set the simulator name, adjust the resolution, select adaptive scaling, and change the system image. Here we use the default configuration and click Finish. Android Studio will create the simulator We Just configured. For example, we can see that we have created our own simulator. You can also create multiple simulators.



Then we click the green triangle button marked in the red box to start our simulator:



To run our App in the simulator, there are two methods: 1. run the simulator first, click the green triangle button in the red box, and run (start) the App, select the started simulator (Emulator Nexus 5 API 21 2 Android 5.0), and click the green triangle button in the red box, then select start a created simulator (Launch emulator) in the middle to start the simulator and then run your App.



After the App is started, we can see the components We just added in the simulator:




Android Studio Features


Next, let's take a look at the smart code editing technology of Android Studio. Android Studio introduces Idea's intelligent code editing technology to implement automatic Code Completion, refactoring, code analysis, and other functions. What we are most concerned about is what its shortcut keys are. Of course, the shortcut keys of Android Studio follow the default Idea. Many friends are used to Eclipse, so we can adjust it to a shortcut key setting similar to Eclipse. How to Set it?


Click the Android Studio button in the upper left corner and select Preferences from the drop-down menu ),



Click to bring up the Property setting window, for example:



We can see all the attribute options in the list on the left. In the search box in the upper left corner, enter the word "key" (key meaning), and The Keymap attribute is selected, select Eclipse (Mac OS X) from the drop-down menu on the right, and then adjust the shortcut key configuration to the Eclipse format. Is it very convenient, you can also select other configurations in the list.



What should you do if you want to modify the setting of a single shortcut key? You can enter the name of the shortcut key you want to set in the search box in the upper-right corner. For example, if you enter complete, the shortcut key setting "Automatically complete code" will be selected, remove temporary cut and Add another cut. Here we can Add a combination like shift +. To make it take effect, click the Apply button under "Activate. Then click OK to close it.





With Android Studio, you will find that the Code style and interface layout are better than Eclipse.


If you do not like the development environment of white background, we can change the black and gray series to avoid eye injury (White is the most eye-catching ). Just like changing the shortcut key settings, click the Android Studio button in the upper left corner, select Preferences from the drop-down menu, and click. The property setting window is displayed. In the search box on the left, enter "font", select the Font in the list, change "Default" in the drop-down list to "Darcula", and click "Apply". OK, then it will ask you if you want to Restart Android Studio to make it take effect and select "Restart ".



After the restart, we found that the overall color of Android Studio was changed to gray-black, so handsome. I like this feeling and never worry about impaired eyes.



The Code Completion section of Android Studio can be written with a semicolon at the end of the sentence, which is too convenient.


Android Studio also has a very convenient prompt function. When we press the cmd key (Apple Computer, windows users should press ctrl), move the cursor to a function or variable, it displays the type, the class in which it is defined, the access modifier (private, protected, public), and so on.


However, Android Studio has far more advantages than this. Let's look at a very useful feature: Multi-layout support. Open the activity_main.xml file and drag it to the left to reveal as much space as possible. Click the button marked in the red box and select Preview All Screensizes from the drop-down menu. We can see that many sizes are displayed. The support of multiple la s makes it easier for developers to adapt to Android devices.



Android Studio also provides a performance analysis tool. Click the Memory Monitor button in the red box to see an animation, the memory consumption of the current simulator is always displayed. It is helpful for us to understand our App performance and improve App performance.




Advantages of Android Studio


  1. Android Studio was launched by Google, which is the biggest advantage. Google is tailored for Android development and will be continuously supported. As mentioned earlier, Google will stop updating the ADT.

  2. Fast. Start Android Studio very quickly (Eclipse is very slow to start), open a project very quickly, start Android simulator is very fast, run smoothly. Android Developers suffering from the Eclipse native simulator can get rid of the hardships. Finally, Android IDE is comparable to ios ide: XCode.

  3. Automatically save the code. Do not worry that the edited content disappears unexpectedly because you forget to press ctrl + s or cmd + s to save the file.

  4. Integrates Gradle, a powerful automated build tool. Configuration, compilation, and packaging are all great.

  5. Powerful UI editing tool.

  6. Code debugging is very intelligent.

  7. Terminal commands. This is cool, because many programmers like to use terminals, especially Unix and Linux users. Click the Terminal button in the red box shown in to bring up the Terminal. You can directly operate on our project in it. That's great!



There are many other benefits of Android Studio, and the level of small series is limited, and it cannot be fully demonstrated. We need to explore it in the Process of use.



Postscript


Of course, at the end of the article, I would like to thank the open-source Eclipse for providing us with the convenience of Android development over the years. Although the article has carried out "relentless attacks" on Eclipse, it is simply "Ungrateful ". But it is still grateful. However, Android Studio has made too much progress and there is no need to use it.




*For new friends, please follow the mini public accountProgrammer Alliance 」



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.