Android Studio beginners to proficient, android beginners to proficient

Source: Internet
Author: User
Tags jcenter

Android Studio beginners to proficient, android beginners to proficient

Finally, CSDN was chosen to sort out the knowledge points published over the past few years. This article was migrated to CSDN in parallel. Because CSDN also supports the MarkDown syntax, it's awesome!

Objectives: To learn more about Android Studio, download and install the configuration, go to the "Basic Info" page, and click "basic usage"> "Debug skills"> build a Project Foundation, and use "AS" to cope with regular application development.

AS Introduction

After two years of R & D, Google finally officially released the Android Studio 1.2 (stable version) integrated development environment for Android Developers ). 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. The IDE showed up for the first time at the Google I/O developer conference in May 2013. The beta version was a variety of inexplicable bugs, but the version released in December 8 was a stable version. After the launch of Android Studio 1.0, Google will gradually give up its support for the original major Eclipse ADT and provide Eclipse users with a solution for engineering migration. However, I believe that after you get started with AS 1.0 AS a Developer, you will no longer be willing to use the original hard-pressed Eclipse + ADT, and you will be attracted by the various strengths of.

Download and install

Before downloading the AS package, you can download the AS installation package with or without the SDK version. If you have an SDK, you can download it without the SDK version, you can also select a custom SDK during installation. You can also re-specify the SDK path after installation. Let's talk about the power of tianchao, and we have to pay tribute to the tianchao wall. If you have a ladder, go to Android Developer to download the latest version of the AS installation package. If you do not have a ladder, you can download the installation package required by your platform from the official website of the Chinese community of Android Studio.

After downloading the SDK, you can skip the installation process. You can install the SDK by using a program. Therefore, you can skip this step. Note that JDK has been correctly installed and configured.

After installation, the first time you run the AS program, you may be stuck in Fetching Android SDK component information. The following page is displayed:

This is because tianchao's wall is really too high and too thick. It gave the wall the first time the SDK was updated. The solution is to close the Installation Wizard. If the Installation Wizard cannot be closed, you can manually close the process in the Task Manager (Ctrl + Alt + Del to start the task manager ), then open the idea in the bin directory under the AS installation directory. properties file to add a configuration item to disable the start running Wizard:

disable.android.first.run=true

Then Start the program and the project Wizard interface will be opened. If you click Start a new Android Studio project, there is no response, and the SDK Manager under Configure is gray, this is because the Android SDK is not installed. At this time, there are two methods:

Restart AS to create an Android project in the Wizard. So far, the entire installation process is complete.

Basic usage

First, create a project, enter the project name and main package name and storage path, and click next To step:

First, you can select whether your App is applicable to Wear, Mobile, or TV. When you select a minimum version for a new App, the powerful AS will give you some useful statistical tips to describe the users of the current version, click Help me choose to display the following more vivid distribution chart description:

The highlight of this is that this step is more powerful than Eclipse, which is just a little bit less worth mentioning. The powerful functions are still coming soon. Click Next to select an image-friendly GUI template, and click Finish to enter the project initialization process.

You have downloaded the OK command before the dig command. When gradle is used, it will be explained later. This is just to tell you that if you see the card for a while, it will be normal.

Next, go to the project interface:

This creation process is much longer than that of Eclipse. It is mainly because it is downloaded from gradle. Gradle can also be manually downloaded offline and stored in the corresponding directory. The project structure is different from that in Eclipse. src is divided into java and res. AS is based on idea, while idea is quite different from eclipse, and there are advantages and disadvantages. For a while, idea is considered to be the best ide tool for java development, therefore, the new application and new module are developed when the AS is created. Idea has no workspace. This is the first unsuitable place for Eclipse users to switch over.

Specifically:

With the above three concepts, You can manually create and find out, and believe that you will naturally understand what is going on.

Next, let's take a look at some of the basic high-frequency practical settings that must first be used to do the job well:

Summary

So far, I believe you have a general understanding of the basic situation of. The advantages over Eclipse are as follows:

In a word, believe me. If you switch over from an Eclipse user like me, you will never switch back, and you will fall in love with.

Android Studio directory structure

After a project is created, the AS Product directory structure is AS follows:

. Idea: // project configuration file generated by AS, similar to Eclipse project. properties. App: // AS creates a Module in the project. Gradle: // jar and wrapper of the build tool system. jar tells AS how to establish a connection with gradle installed in the system. External Libraries: // not a folder, but dependent on lib files, such as sdks.

After the project is created, the AS Module Directory structure is AS follows:

Build: // build Directory, which is equivalent to the bin directory of the default Java project in Eclipse. Right Click Show in Exploer to open the folder. The compiled apk is also in the outs subdirectory of this directory, however, in the AS project, the out directory is not displayed by default, and the compilation result is not displayed. You can right-click and open the directory to view it directly. Libs: // dependent package, including jar package and jni. Src: // source code, equivalent to the eclipse project. Main: // main folder java: // Java code, including the project and the Test project source code generated by default when the project is created. Res: // resource file, similar to Eclipse. Layout: // App layout and interface element configuration, similar to Eclipse. Menu: // App menu configuration, similar to Eclipse. Values: // similar to Eclipse. Dimens. xml: // defines the css configuration file. Strings. xml: // the configuration file that defines the string. Styles. xml: // the configuration file that defines the style. ...: // Arrays and other files. ......: // Directory such as assets AndroidManifest. xml: // App basic information (Android management File) ic_launcher-web.png: // App icon build. gradle: // Module's Gradle build script
Android Studio development and debugging

Android Studio debugging is actually very convenient. Generally, you can solve the problem by using the as ddms Logcat. AS supports all features similar to Eclipse's DDMS. Here we will talk about debugging methods for difficult problems, that is, breakpoint debugging.

First, compile the program to be debugged.

As shown in figure 2, click Set breakpoint at the row number. Click Enable debugging session, as shown in figure 1.

As shown in, the Debug view appears below the IDE. 1 points to the code lines currently stuck in the debugging program, and 2 points to the method call stack area of the program. This area shows the methods used by the program to run on the breakpoint. The earlier the method is called. In this order, we must have some in-depth knowledge about the Startup Process of the Android system. We will know how these methods are going and how to get to onCreate of the Activity. Haha, speaking of the system. No. 3. There are some debugging buttons. The shortcut keys are displayed directly on them. 4 and 5 are some variable observation areas.

Medium:

Click the button pointing to 1, and the program executes a row down. If the current row has a method call, the method will be returned after execution, and then to the next row.

Click the button pointing to 2 and the program executes a line down. If this row has a custom method, run it to enter the custom method (instead of the official class library method ).

Click the 3 button to go to any method during debugging.

Click 4. If you enter a method (such as debugFunc) during debugging and feel that the method is correct, you can use 4 to jump out of the method, returns the next line of statements called by the method. It is worth noting that this method has been executed.

After clicking the 5-point button, you will return to the call of the current method for re-execution, and the value of all context variables will return to that time. As long as there is a higher-level method in the call chain, you can jump to any of the methods.

For example, you can set multiple breakpoints to enable debugging. To move a breakpoint to the next breakpoint, click the 1 arrow to run the code to be executed between the breakpoint and the next breakpoint. If there is no breakpoint in the subsequent code, click this button again to execute the program. Click the button pointed to by Arrow 2 to view the breakpoint you have set and set the attributes of the breakpoint, as shown in. After Debugging starts, you can assign a value to the specified variable in the Variables area (select a variable with the left mouse click, right-click the variable and choose setValue… from the context menu ...). This function can quickly detect your condition statements and loop statements. Click the plus sign on the arrow 3 or right-click the debug code variable and add watcher to view the trace variable value.

Arrow 1 points to the breakpoint you have set, and Arrow 2 can set a conditional breakpoint (when a condition is met, the execution of the program is paused, such as index = 5 ). After debugging, delete the breakpoint set at Arrow 1 (select the breakpoint to be deleted and click the red minus sign on the top ).

These are some of the AS debugging skills.

Basic knowledge of building a system using Android Studio

After the project is successfully created, Gradle is automatically downloaded. This process is very slow. We recommend that you go over the wall. The downloaded Gradle on Windows platform defaults to the C: \ Documents and Settings \ <username>. gradle \ wrapper \ dists Directory, which has a folder for the gradle-x.xx-all ,. You can also manually download the corresponding file to gradle, then copy the downloaded. ZIP file (which can also be decompressed) to the above gradle-x.xx-all folder.

Each Module must have a gradle configuration file with the same syntax. The only difference is that the application plug-in is declared at the beginning. Differentiate build. gradle files in different locations.

The build. gradle file under the project root directory of:

Buildscript {// set the script runtime environment repositories {// supports java dependency library management (maven/ivy, etc.) for project dependencies // mavenCentral () // only different network repositories are supported. jcenter () // This repository is recommended.} // The definition of dependency packages. Supports maven/ivy, remote, local library, and single file. The previous definition of the repositories {} jcenter library is as follows. android. tools. build: gradle: 1.0.0-rc2, gradle automatically downloads the corresponding dependencies to the remote database. Dependencies {classpath 'com. android. tools. build: gradle: 1.0.0-rc2 '// NOTE: Do not place your application dependencies here; they belong // in the individual module build. gradle files} // centralized configuration for multiple projects. Most build tools support inheritance-based configuration for subprojects. In addition to setting sub-projects in the inheritance mode, Gradle also provides this configuration allprojects {repositories {jcenter ()}}

The settings. gradle file under the project root directory of:

    include ':app'      //module    include ':my_lib'   //module(build as lib)

The build. gradle file of the Module under the project root directory of AS (Here we use a simple gradle of Lib module AS an example ):

// The value of plugin in AS is generally 'com. android. library 'or 'com. android. application 'apply plugin: 'com. android. library '// build as lib android {compileSdkVersion 17 // compile the SDK version buildToolsVersion "19.1.0" // the SDK Manager determines that the local version is installed before defaconfig config {minSdkVersion 8 // The minimum version targetSdkVersion 17 // target version} buildTypes {// compilation item release {minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt '), 'proguard-rules.txt '}}} dependencies {// compile 'com. android. support: support-v4: 18. + '}
Gradle package APP Signature

By default, debug is configured to use a debug keystory. Debug keystory uses the default password, default key, and default key password. The debug build type is automatically configured using the debug signature. Add the following in the build. gradle file of your Module:

Android {...... signingConfigs {myConfig {storeFile file ("yanbober. keystore ") storePassword" gradle "keyAlias" gradle "keyPassword" gradle "}}buildtypes {release {runProguard true zipAlignEnabled true // Remove useless resource files shrinkResources true proguardFiles done '), 'proguard-rules. pro 'signingconfig signingConfigs. myConfig }}}

Although the relative path of the Project root directory is often used as the keystore path, the absolute path can also be used, although this is not recommended (except for the debug keystore automatically created ). Run gradle clean gradle build to generate an app with mixed signature alignment.

Gradle builds multi-channel packages for Android applications (batch packaging)

The release of Android applications must face various markets, which are called channels. Generally, as developers, we need to know the channel from which the application is downloaded. This type of statistical information is commonly used by Baidu or umeng. Here, we use umeng statistics as an example to illustrate the problem. The principle is the Manifest Merger of Gradle.

Configure the so-called PlaceHolder in AndroidManifest. xml.

    <meta-data        android:name="CHANNEL"        android:value="${CHANNEL_VALUE}" />

Add the PlaceHolder in the defaultConfig of the module build. gradle file to declare that CHANNEL_VALUE is the PlaceHolder Of The replaceable value, and set the default value of yanbober for it.

    android {        ......        defaultConfig {            ......            manifestPlaceholders = [ CHANNEL_VALUE:"yanbober" ]        }       }

Add the ProductFlavors configuration in the build. gradle file of the module. ProductFlavors is actually a product feature that can be defined. When used with Manifest Merger, multiple versions with their own feature configuration can be generated during a compilation process. The following configuration is used to generate different CHANNEL_VALUE values for each channel package.

    android {        ......        defaultConfig {            ......            manifestPlaceholders = [ CHANNEL_VALUE:"yanbober" ]        }           productFlavors {            yanbober{}            wandoujia{}            xiaomi{}            baidu{}        }        productFlavors.all { flavor ->            flavor.manifestPlaceholders = [ CHANNEL_VALUE:name ]        }    }

Batch generate multi-channel packages: Enter the project directory and run gradlew assembleRelease. We can see that a total of four apk packages are generated for compilation, which correspond to the four channels defined in the productFlavors segment. When AndroidManifest. xml is decompiled, you will find that the CHANNEL configuration has been modified.

Generate a single channel package: Open the Gradle Tasks panel module of AS to have many Tasks. Double-click the corresponding delayed channel task to generate the corresponding apk. Use the command line to generate a separate xiaomi channel and use gradlew assemblexiaomiRelease.

Now let's talk about the basic situation of Gradle. For details, read the official website or consult other materials. The use of Gradle requires accumulation of experience.

Install Android Studio plug-in and use Genymotion Simulator

The simulator provided by Android Studio is faster than the Eclipse plug-in, but it is not violent enough. Now let's talk about how the most violent Genymotion simulator works with. First, download and install Genymotion on the Genymotion official website. At the same time, you need to register an account on the Genymotion official website so that you can use Genymotion normally.

On the left side of the Settings interface of AS, find Plugins and click the arrow Button (online installation ):

By the way, the interface is the general method for installing plug-ins in AS. You can see the plug-ins that have been installed now. You can choose to install them online or from the hard disk, that is, for the plug-ins you have downloaded, you can select your plug-in for installation.

AS shown in, enter the plug-in name in area 1, select in area 2, download and install in Area 3, and return to the plug-in. On the AS toolbar, you can see the Genymotion icon, which is the one pointed by Arrow 4, install OK.

The next Step is to set Genymotion and create a virtual machine device. This is Genymotion. It is not difficult to get Step by Step. Click the simulator icon on the AS to start and use it. Run the AS program, select the simulator, and you will be able to see your program in the simulator. This is the Genymotion startup interface.

Now Genymotion has been completed in the fast simulator to speed up your operation. Other plug-ins can also be installed.

Others

Other things are shortcut keys. This must be accumulated by yourself. The strange problem is google and Du Niang. In fact, the current version of AS still has some bugs, but it meets the basic requirements. When you encounter bugs, check and modify them, or use big moves-restart the AS to solve the problem, you are welcome to discuss other strange issues and grow together.

PS: if you have other problems with AD, this article is a summary of the translation of AD and the problems you have encountered.

In short, you will fall in love with him.

Android Studio Summary

Now you can use Android Studio for application development. I believe that you can solve other problems with Google. Good luck! In short, the strength of AS requires you to explore slowly, you will find that you will fall in love with him without knowing it.

(Please be considerate of the author's Labor achievements and repost the link to the remarks. Your statement and discussion are the motivation of your writing. This article is being updated based on time and personal circumstances ......)

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.