Getting Started with Android studio (Installation--development debugging)

Source: Internet
Author: User
Tags version control system

Written in the previous words: This article source : http://blog.csdn.net/yanbober/article/details/45306483

Target: Android studio novice –> Download installation configuration –> 0 Basics –> Basic use –> Debugging Skills –> Build Project Foundation –> use as to address general application development

Download installation

To download as before the first, as the installation package is included in the SDK version and does not include the SDK version of the download, if you have the SDK, you can download the SDK version is not included, but download the SDK version is also OK, the installation of the custom SDK can also be installed after the installation of the SDK path can also be specified, Anyway, look at your hobbies. First spit trough The mighty of the celestial, have to admire celestial wall. If you have a ladder please go to Android developer to download the latest version of the as installation package, if you do not have a ladder, there is a way to go to the Android Studio Chinese Community official website Download your platform needs to install the package.

Download down the installation of the process can be ignored, can be installed is the program Ape Bar, so install this does not say, note that the installation is correctly configured JDK.

Installed after the first run as may have been parked in the fetching Android SDK component information. The following interface:

This is because the wall of celestial is really too high and too thick to put the first run Update SDK to the wall. The workaround is to close the Setup wizard, and if you cannot close the process can be manually shut down in Task Manager (Ctrl+alt+del start Task Manager), Then open the Idea.properties file in the bin directory under the As installation directory and add a configuration item that disables the start of running the wizard:

disable.android.first.run=true

And then start the program will open the Project Wizard interface, this time if you click on Start a new Android Studio project is unresponsive, and the SDK manager under Configure is gray, this is because Android is not installed SDK's sake. This is usually done in two ways:

    1. I do not have the SDK, need to download from the network; Open the configure-settings of the wizard, enter proxy in the lookup box, locate the following HTTP proxy, set the proxy server, and force https://... sources to be fetched using HTTP//selected, and then quit commenting out the configuration item added above in the Idea.properties configuration file, reopen Android studio, and just start the wizard to download and install the Android SDK.

    2. You have the SDK, re-specify the SDK path, open the wizard's Configure->project Defaults->project Structure, here to fill in your existing SDK path.

Restart as now to create a new Android project in the wizard. This completes the installation process.

Introduction to basic use

First create a new project, enter the project name and the main package name and storage path; Click Next to step:

In the first place, you can choose whether the device you want to fit is wear or mobile or TV. When you create a new app to choose the minimum adaptation version, powerful as will give you some useful statistical hints, describes the current version of the user situation, click on the Help me choose after the following more image of the distribution chart description:

The highlight is that this step by step is more powerful than eclipse, which is just a little bit less worth mentioning, powerful features are still behind. Continue to click Next to select the friendly GUI template, click Finish to enter the project initialization process.

The first installation project was initialized due to the need for networking download Gradle will be slow, but sometimes not the first is also slow, engineering dependent version of Gradle will automatically re-download; My initialization is fast, The reason is that my local gradle-2.2-all.zip has been downloaded OK before. As for when Gradle will be explained. This is just to tell you that if you see the card in a moment, it's normal.

Next go to the engineering interface:

This creation process can be much longer than eclipse. Mainly because it is downloaded from Gradle. Gradle can also be downloaded manually offline and placed in the corresponding directory. The structure of the project differs from Eclipse, and SRC is divided into Java and res. As is based on idea, and there are great differences between idea and eclipse, there are good and bad places, and for some time, it is thought to be the most powerful IDE tool for developing Java, so as new is developed with new application and new module. Idea doesn't have a working space. This is where the eclipse user switches to the first one that doesn't fit in.

Specifically, that is:

    1. Android Studio is a single-project development model
    2. Application in Android Studio is equivalent to the workspace concept in eclipse
    3. Module in Android Studio is equivalent to project concept in eclipse

With the above three concepts of self-created by hand, believe that smart you naturally understand what happened.

Next look at some of the basic high frequency practical settings for 工欲善其事 its prerequisite:

  1. Chinese garbled-in the window, locate the IDE settings->appearance, tick "Override default fonts by" on the right, then select the font "SimSun" in the first drop-down box, then apply, restart the IDE, Just fine.

  2. Set shortcut keys-in the Settings window, locate the IDE Settings->keymap, and the shortcut key is open on the right. Right-click the shortcut you want to modify, a menu will pop up, and the shortcut can be modified by selecting "ADD keyboard shortcut". If you delete, select Remove XXX from the menu that pops up. In particular, you can set the use of Eclipse shortcuts or other IDE shortcuts directly in the shortcut key settings of AS. If you're passionate about eclipse, you can also set up Eclipse shortcut keys.

  3. Modify the theme-in the IDE settings->appearance, on the right side of the theme choose your favorite theme. Individuals prefer the Darcula theme, which is like the above style.

  4. How to import an Eclipse project into as use-select File->import Project, select the project you want to import in the popup menu, select OK, then direct next, and in the second window choose the default first option. It is important to note that in as, there are two kinds of projects, one project and one module, which has been described above.

  5. Import jar Package--Select File->projcet Structure, find the libraries on the left side of the popup window and select it, then click "+" and select Java to import the jar package. or copy the jar file directly into the project's Libs folder, and then run: Sync project with Gradle Files. Then clean project recompile.

  6. Delete Project-–as a protection mechanism for project deletion, by default you find no delete option in Project right-click. You will find a small mobile phone on your module, which is a protection mechanism. Removal of the first step is to remove the protection mechanism, that is, to let the phone is not visible, the specific method is to put the mouse on the project right-->open module setting, or F4 into the interface, select the module you want to delete, and then click the minus sign, so that the protection mechanism is removed, Then go back to Project engineering right-click to find the delete option. Note: Deleting will delete the source files.

    1. Modify a Project Catalog-when you create a project, after you select the project directory in project location, you enter a folder name to save the project, and then you can use your own project catalog.
Introductory summary

So far, as the basics, I'm sure you've got a rough idea. Specific advantages over eclipse are reflected in the following points:

    1. As is Google's purpose-built tool for Android based on IntelliJ idea. Biological is always the best, but it is still growing up.

    2. As in any aspect of speed is faster than eclipse.

    3. The Darcula theme UI is simply geek, and it's awesome.

    4. The powerful smart Tip completion feature is simply more efficient than eclipse when writing code.

    5. Smart save, do not need CTRL + S. Efficiency will be greatly improved.

    6. Integrating the Gradle build tool, Gradle combines the benefits of Ant and Maven, whether it's configuration, compilation, or packaging.

    7. The UI editor is simply more efficient than eclipse, and comes with a real-time preview of multiple devices, which is an artifact. Multi-language adaptation Click on the earth Direct input, no longer compare that string without translation.

    8. The built-in terminal directly replaces the cmd command line, and an IDE is all done.

    9. Perfect plug-in system, such as Git, Markdown, gradle, etc., direct search for download.

    10. Version control system, when installed with GitHub, Git, SVN and other popular version control system, you can directly check out your project, side write code right-side can directly have Bcompare function and other versions to compare and modify.

In a word, believe me, if you and I are the same eclipse users switch over, then you will never switch back, you'll love as.

Android Studio Directory Structure

After the new project, the product directory structure for as is as follows:

After the new project, the module directory structure of As is as follows: 

Android Studio Development Debug Use

Android Studio debugging is also very convenient, general problems directly through as the DDMS Logcat can be done. As supports all features of DDMS like Eclipse. Here to say is the debugging of difficult problems, that is, breakpoint debugging.

First compile the program you want to debug.

Click Set breakpoint at line number as shown in 2. Then click to open the debugging session as shown in 1.

As shown, the Debug view appears below the IDE, and 1 points to the line of code where the debugger is currently stuck, and the 2 area is the program's method call stack area. In this area shows the method used by the program to execute to the breakpoint, the more the following method is called earlier. In this order presumably some Android in-depth understanding of a little Android system startup process know how these methods, how to the activity of the oncreate. Haha, speaking of the system. It's not a rip. 3 is a number of debugging buttons, shortcut keys placed directly on the above will be displayed. 4 and 5 are some variable observation areas.

In

Click the 1 point button, the program executes a line down, if the current line has a method call, this method will be executed to return, and then to the next line.

Click the 2 point button and the program executes one line down. If the row has a custom method, it runs into a custom method (a method that does not enter the official class library).

Click on the 3 button to enter any method when debugging.

Click 4 the role is if you enter a method (such as Debugfunc) when debugging, and feel that the method is not a problem, you can use 4 to jump out of the method, return to the method is used to the next line of the statement. It is worth noting that the method has been executed.

When you click the 5-point button, you will return to the current method's call to execute again, and the value of all context variables will return to that time. You can jump to any of these methods as long as there is a parent method in the call chain.

If you set multiple breakpoints, turn on debugging. To move across a breakpoint to the next breakpoint, click a 1 arrow, and the program will run a breakpoint between the next breakpoint and the code that needs to be executed. If the following code does not have a breakpoint, tapping the button again will run the program. Click on the arrow 2 to point to the button, you can see the breakpoint you have set and can set some properties of the breakpoint, as shown in. After debugging begins, in the variables area you can assign a value to the specified variable (the left mouse button selects the variable, the right-click popup menu selects the SetValue ... )。 This feature allows you to detect your conditional statements and loop statements more quickly. You can view the value of the trace variable by tapping the arrow 3 plus or by right-clicking on the debug code variable to add watcher.

Arrow 1 points to the breakpoint you have set, and arrow 2 can set a conditional breakpoint (when a condition is met, pause the execution of the program, such as Index==5). After you finish debugging, you should delete the breakpoint you set at arrow 1 (after selecting the breakpoint you want to delete, click the red minus sign above).

These are some of the debugging techniques used by AS.

Android Studio Building System Fundamentals Basics

When the project is successfully created, it will download gradle automatically, which is very slow and FQ recommended. The downloaded gradle on the Windows platform will default to the C:\Documents and settings\< user name >.gradle\wrapper\dists directory, which has a Gradle-x.xx-all folder under this directory. You can also manually download the corresponding version to the Gradle website, and then copy the downloaded. zip file (or unzip it) to the Gradle-x.xx-all folder above.

Each module needs to have a Gradle configuration file, the syntax is the same, the only difference is that the beginning of the declaration is the Apply plugin. Be careful to distinguish between build.gradle files in different locations.

Build.gradle file under Engineering root of as:

Settings.gradle file under Engineering root of as:

The Build.gradle file for module in the engineering root directory of AS (here is an example of a simple Lib module Gradle):

Gradle Packaging App Signature

By default, debug is configured to use one of the debug keystory. The debug keystory uses the default password and default key and the default key password. The Debug build type is automatically configured with the debug signature. In your module's Build.gradle file, add:

Although the relative path of the project root is often used as the path to the KeyStore, an absolute path can also be used, although this is not recommended (except for the automatically created debug KeyStore). Run the Gradle clean Gradle build to generate a signature confusion-aligned app.

Gradle build Android apps Multi-Channel pack (bulk package)

The release of Android apps needs to face a variety of markets, which we call channels. Usually as a developer we need to know which channel the app was downloaded from. This statistical information is commonly used in Baidu statistics or friends League statistics. Here, for example, use the Friends League statistics as an example to illustrate the problem. The principle is Gradle manifest merger.

Configure the so-called placeholder in Androidmanifest.xml.

Batch build multi-Channel package: Enter the project directory to run Gradlew assemblerelease. You can see that the compilation produced a total of 4 apk, respectively, corresponding to the 4 channels defined in the Productflavors segment. Anti-compilation opens androidmanifest.xml you will find that the channel configuration has been modified.

Generate a single channel package: Open as the Gradle Tasks panel module has many tasks, directly double-click the corresponding delay channel task to generate the corresponding apk. It would be nice to use Gradlew assemblexiaomirelease to generate Xiaomi channels separately using the command line.

Well, gradle the basic situation of this, specifically can read the official website or access to other materials, the use of gradle need experience accumulation.

Android Studio plug-in installation and use of Genymotion simulator

Android Studio comes with an emulator faster than the Eclipse plugin, but it's not violent enough, it's not cool enough. Now, the most violent genymotion simulator can be used in conjunction with AS. First on the Genymotion official website to download the installation of genymotion, and you need to register an account on the Genymotion official website, so that you can use the Genymotion normal.

To the left of the settings interface of as, locate plugins and click on the arrow button (i.e., install online):

By the way, the interface is the same as the general method of installing plug-ins, you can see the current installed plug-ins, choose to install online or from the hard disk installation, that is, for you have already downloaded the plug-in, you can use this option to your next good plug-in, to install.

As shown in the 1 zone input plug-in name, 2-Zone selection, 3-zone download installation, and then return to the as toolbar can see the Genymotion small icon, that is, the arrow 4 refers to the thing, indicating the installation OK.

Next is to set the next genymotion, create a new virtual machine device, this is genymotion things, as to how to get step by step on the line, no difficulty. Click on the As on the emulator icon can be started using, run as program selection Simulator can see their program in the simulator, is the genymotion start up interface.

This fast simulator genymotion has been taken care of to improve your speed. Other plug-in installation will be comprehend by analogy.

Android Studio Summary

This is where you can use Android Studio for application development. Other questions believe that smart you use Google can handle, good luck! In short, as the strong need you to explore slowly, you will find that you will fall in love with him.

Getting Started with Android studio (Installation--development debugging)

Related Article

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.