Android Studio 1.0 (Stable version) full introduction _android_ mobile development-itnose
Android Studio Installation and use
?
Android 1.0 Release Description :
December 8, 2014, Google officially released an integrated development environment for Android developers Android Studio 1.0 (Stable version).
From May 2013 to December 2014, nearly a year and 7 months, I finally hope that the release of the 1.0 stable version.
Presumably the vast number of Android developers and small make up the same kind of wistfully, keep the cloud open to see the feeling of the moon Ming.
?
Small series after a period of use, has been deeply in love with this outstanding IDE. As a long-term use of eclipse+genymotion (had to use the Genymotion simulator, because the eclipse comes with the simulator is too slow, generally wait for it to start, you can drink a cup of coffee, and then slow some may go to eat a roast chicken ^@^?; but to download, install, Configure the Genymotion emulator to use with eclipse, I want to ask, are you tired?) Android developers, small to you strongly recommend this Android Studio, easy to burst into tears. As Google's pro-son, in the time to fight dad is so confident. And the eclipse-developed Android project can easily be imported into Android Studio.
?
Introduction: Android Studio is a Google-developed IDE for Android developers, supporting the Windows, Mac, Linux and other operating systems, based on the popular Java language integrated development environment IntelliJ built. The IDE first appeared at the May 2013 Google I/O developer conference, followed by a number of beta versions, until December 8, 2014, when Google officially launched an integrated development environment for Android developers Android Studio 1.0 (Stable version).
?
Note : Google says it will stop updating the ADT (android Developer Tools) Later, so it looks like Android is going to be developed or Android studio.
?
?
Android Studio Installation :
?
Premise: Because Android needs to use the Java language 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 the Internet how to download, install and configure environment variables, in this article do not do too much to explain, there are many graphic tutorials on the web. For Java's JDK (Java Development Kit) version, I installed the latest JDK 1.8 (Java 8) and should be available for Android STUDIO,JDK 1.7 and 1.6.
?
Give the URLs of several Java development environment installation configurations:
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 the installation configuration completes the Java development environment, go to the following URL:
http://developer.android.com/sdk/index.html (click "Read Original" in the lower left corner to enter the URL)
You will see a version of Android studio for your current operating system, I am demo on Apple's MacBook, so it is "Download Android studio for Mac", click this green button to download it.
?
?
Double-click the downloaded file (the DMG file for the Apple Computer) and go to the Installation Wizard:
?
?
"Standard" installation is for the SDK (software Development Kit) that does not already have Android, if you have installed the SDK, you can choose "Custom", we here choose the default standard, Click the Next button (next),
?
?
Is that we need to select the "accept" Android SDK and Emulator Runtime Environment, only select the Accept after the Finish button to be able to be clicked. After pressing the Finish button, wait for Android studio to install, depending on the speed.
?
Once the installation is complete, we double-click the Android studio icon,
?
?
You can officially start our Android Studio Tour!
?
But if you're on an Apple computer, you'll probably encounter a problem that hasn't been solved so far, that Android studio can't find the Java environment that we installed, and it will show the following box:
?
?
So you need to do some more changes, you need to modify the Android studio Info.plist file, open a terminal (go to the utility, and terminal), enter:
?
Vi/applications/android\ studio.app/contents/info.plist? (Here is the VI editor, you can also use your favorite editor, such as Emacs and so on.) You can also find info.plist this file according to the path, and then change it with your favorite editor)
?
will be inside the
?
?
<key>JVMVersion</key>
<string>1.6*</string>
?
Switch
?
<key>JVMVersion</key>
<string>1.8*</string>? (because my JDK version is 1.8, if it is 1.7, it needs to be 1.7*; if it's a 1.6 version of the JDK, there should be no boot issue)
?
?
After the change, you can start.
?
?
(Note: My version of Android Studio here has been updated to 1.0.1, after the update, the previous version of the JDK version of 1.0 is not correct, can only be changed again Info.plist file)
?
The window shown above shows that the user of IntelliJ idea must not be unfamiliar.
?
There are a variety of actions to choose from, create a new project (Start-a new Android studio project), open an existing project (Open?an existing Android Studio project), etc. To create our first project, click on "Start a new Android Studio project",
?
?
You'll see the window jump to like this.
?
In the "Application Name" field to fill in the project name, I filled in here is "world-famous" HelloWorld.
Fill in the company's web address in the "Company Domain" field, I fill in the enmingxie.com (this random). This actually determines the package name of your project.
In the "Project location" column I did not change, let the project in the default location, of course, you can also change the location you want.
?
?
Click Next to enter the next step,
?
?
Here are a few options that your app wants to publish. The default choice is "Phone and tablet" (phones and tablets), you can also choose "TV" (Google TV), Wear (Google wearable devices, such as smart watches) and glass (Google glasses, where I do not install Google Glass the SDK, so the not installed is displayed).
?
Each platform requires us to select the minimum version of the SDK (Minimum SDK), and for "Phone and Tablet" By default the API 15 (corresponding to the Android 4.0.3 version, Icecreamsandwich), You can also click the drop-down menu to select the Minimum SDK version you want.
?
?
?
After selecting, click Next to go to the next step,
?
?
See the above window and believe that eclipse's old users must smile, because very similar. Here is the interface that lets us choose the runtime (which is easier said), which is the activity of Android (an activity is an interface that an application provides to communicate with the user). We choose the default blank activity (blank interface), you can also choose according to your needs such as Google Maps activity (Google Maps), and so on.
?
Click Next to enter the next step,
?
?
Here is some information about the activity we created, similar to ADT:
?
Activity name is the names of the activity
Layout name is the names of the layouts
Title is the caption displayed on activity
Menu Resource name is the resource filename used by the MenuBar
?
I use the default, of course, you can also rewrite.
?
Click Finish to finish configuring the project, and Android Studio will open the new project we just created for us:
?
?
Finally appeared the Project window, is not a little excited about it. We can put the hint of the small window show tips on startup (Display prompt at startup) This tick off, so that the prompt box will not be annoying us at each start.
?
Android Studio Basic usage :
?
?
We can see that in the above window, we have roughly four areas from left to right (because the user interface profile is activity_main.xml when selected by default), which is similar to eclipse. From left to right, the first area is the Project list area (the code and resources for each project are listed here, I've expanded all the projects here), the second one is all the available components of the layout, and the third is the visual layout area (see a cell phone), The fourth one is the tree list of components in the layout and the property settings.
?
If you select the main project source code Mainactivity.java, we see this is the case:
?
?
In the first area: The project list area, we can see that the structure of the whole project is similar to eclipse, but there are some changes:
-
Androidmanifest.xml This Android project base profile is placed in a single folder "manifest"
-
The original src (source code) folder name changed to Java, but the package name is still the same as the original company domain name upside down.
-
Use the Gradle (Gradle scripts), an automated build tool for the INTELLIJ Integrated development Environment (http://baike.baidu.com/view/9916271.htm)
-
The configuration of the Android SDK version moved from Androidmanifest.xml to the Build.gradle (module:app) file under Gradle scripts, such as:
?
?
Let's take a look at the user interface profile in the project: Activity_main.xml, fully visual editing, what components you want (the bar in palette) just drag and drop with the mouse, just like eclipse. The layout of the palette inside is the choice of layouts. I dragged a few components here (button, Radiobutton,checkbox,switch switch)
?
?
Other structures, such as the Res folder, are basically the same as eclipse.
?
As for the management of the Android SDK version, clicking on the small icon in the red box will bring up the SDK Download Management window similar to eclipse:
?
?
?
?
Create an Android emulator and run the app:
?
Next we'll create our own Android Simulator (and of course you can also connect to the real machine to test your app, but Android studio simulator is really powerful, a lot of styles, choice, and fast). First click on the small icon in the red box:
?
?
?
?
As we can see, Android Studio defaults to the creation of a simulator (avd:android Virtual device), which is the Nexus 5 API 21 Resolution 1080 * 1920. We remove it (not so much) and create a new simulator for ourselves. Click the X button on the far right and select the Delete option to confirm the deletion. The window will then display:
?
?
Click the button in the middle of Create a virtual device (creating a VM):
?
A new window will appear:
?
?
There are a number of different device templates to choose from, and the list on the left has four categories: Phone (mobile), tablet (tablet), Wear (wearable devices such as smart watch) and TV (TV), each with a different template. We first select the Nexus S 4.0 Resolution 480 * 800 this device, click on the Next button to the next,
?
?
?
Here let us choose the system image, we can choose the different API version of the image, the small series selected is the latest Lollipop API 21 system image, ARM's architecture, you can also choose the x86 or x86_64 architecture. Click Next,
?
?
In this step, we can set the name of the simulator, adjust the resolution, select adaptive scaling, and change the system image. Here we are all using the default configuration, click Finish to complete. Android Studio will create a simulator that we have just configured for us, as we can see that we have created our own simulator. Of course you can also create multiple emulators.
?
?
Then we click on the red box labeled green triangle button to launch our simulator:
?
?
To run our App in the simulator, there are generally two ways: 1 is to run the emulator first, then click the Green Triangle button in the red box, run (launch) the app, select the emulator that has started (Emulator Nexus 5 API 2 Android 5.0) 2 is to click on the Green Triangle button in the red box, then select Launch a created simulator (Launch emulator), then launch the simulator and run your app.
?
?
Once the app is up and in the simulator, we can see the few components we just added:
?
?
?
Android Studio Features
Next, let's look at the smart code editing technology of Android Studio. Android Studio introduces idea's smart code editing technology, which enables automatic code completion, refactoring, code analysis, and more. What we are most concerned about is its shortcut keys. Of course, the shortcuts for Android studio are the default with idea, and many friends are accustomed to eclipse, so we can also tweak it to be a shortcut key setting similar to eclipse. How to set it up?
?
We click on the Android Studio button in the top left corner and select Preferences (properties) from the drop-down menu.
?
?
When clicked, the Property Settings window will pop up, such as:
?
?
You can see all the property options in the list on the left, we enter the word "key" in the search box in the upper-left corner (meaning of the key), the Keymap attribute is selected, and the drop-down menu on the right selects Eclipse (Mac OS X), It is convenient to adjust the shortcut configuration to eclipse format, but you can also choose other configurations in the list.
?
?
What do you do if you want to modify the settings of a shortcut key individually? You can enter the name of the shortcut you want to set in the search box in the upper-right area, for example, I enter complete, the "Code AutoComplete" shortcut key setting is selected, the default deletion (remove shortcut), and then add (add shortcut), We can add a combination of "shift+/" to this side. To make it effective, click the Apply button below. Then OK button, close.
?
?
?
?
With Android Studio, you'll find it easier than eclipse, and the code style and interface layout are better.
?
If you don't like the white-bottom development environment, we can change the black-grey system to look like it doesn't hurt your eyes (white is the most hurt). As you just changed the shortcut settings, click on the Android Studio button in the top left corner, select Preferences (properties) from the dropdown menu, and the Property Settings window will pop up. This time enter in the search box on the left: font (meaning of the font), select the font shown in the list, change the default in the drop-down menu to Darcula, click Apply, OK, and then it will ask you if you want to restart Android studio for it to take effect, select " Restart ".
?
?
After rebooting, I found that the overall color of Android studio was changed to gray-black, so handsome. Just like this feeling, no longer worry about eye damage.
?
?
Android Studio Code to fill the plenary with the semicolon at the end of the sentence to write to you, too convenient.
?
Android Studio also has a handy hint feature, when we hold the CMD key (Mac, Windows user should be the CTRL key), then move the cursor to a function or variable, it will show the type, and in which class is defined, the access modifier (private, Protected,public) and so on.
?
But the advantages of Android studio are much more than that, so let's look at a very useful feature: multi-layout support. We open the Activity_main.xml file and drag it to the left to reveal as much space as possible. Click on the button in the Red box, select Preview all screensizes in the dropdown menu, we will see a lot of size display. Multi-layout support makes it less cumbersome for developers to adapt to Android devices.
?
?
Android Studio also provides a tool for performance analysis, click the Memory Monitor button in the red box, and you will see a motion diagram that shows the current emulator's consumption It's helpful for us to understand our app performance and improve app performance.
?
?
?
Android Studio Benefits
?
-
Android Studio is Google's launch, which is the biggest advantage. Google is tailor-made for Android development and will continue to support it. The previous mention of Google will stop updating ADT.
-
Fast speed. Start Android Studio very quickly (Eclipse boot is slow), open a project very quickly, launch Android Simulator is very fast and run smoothly. Android developers who suffer from the Eclipse native simulator can get away with the hard times. Finally, the Android IDE also has a model that can be compared with iOS ide:xcode.
-
Save the code automatically, without worrying about forgetting to save the file by pressing Ctrl+s or cmd+s, causing the edits to disappear unexpectedly.
-
Integrated with Gradle, this powerful automated build tool. Configuration, compilation, and packaging are great.
-
Powerful UI editing tools.
-
Code debugging is very smart.
-
The terminal command operates directly. This is really cool, because many programmers like to use the terminal, especially UNIX and Linux users. Click on the red box shown in the Terminal button, it brings up the terminal, in the inside can directly operate our project, great!
?
?
There are many advantages to Android studio, and there is a limited number of gadgets to show. You need to be in the process of the use of slowly to explore.
?
?
Postscript
Of course, at the end of the article, I would like to thank the open source eclipse for the convenience of Android development for so many years. Despite the "relentless attack" on eclipse in the article, it was "ungrateful". But in fact, with a grateful heart. But Android studio has really made a lot of progress, and there's no reason to use it.