Android Studio Tutorial: Getting Started to Develop the First Program

Develop the first application

To be an excellent Android developer, you need a complete  knowledge system . Here, let us grow together to be what we think~.

Is it a little exciting to be able to develop your own application? Ok! Let's start, first click Start a new Android Studio Project to create a project:

Next, you need to enter the application name (the first letter should be capitalized), the company domain and the designated application storage directory, and click the Next button to enter the next step:

If the first letter is not capitalized, it will prompt:The application name for most app begins with an uppercase letter

Next, you need to choose which device to develop (optional "phone and tablet", "Wear", "TV", "Android Auto", etc.), and determine the minimum SDK version number.

The function of the Minimum SDK is to verify the Android version of the device before the application is installed. If the Android version of the device is lower than this minimum version, it will prevent the user from installing the application.

If you don’t know how to choose the smallest version, you can click Help me choose to see the distribution chart and description of each version:

Continue to click the Next button to proceed to the next step. We need to select the style of our first Activity through the image-friendly GUI template:

Then you need to give a name to Activity and Layout.

After clicking the Finish button, Android Studio starts to create and compile the application. After the compilation is over, we can see the IDE interface of Android Studio.

It can be seen from the picture that Android Studio has helped us organize the project very well.

Interface introduction

As shown in the figure above, I divided the interface into 5 areas for detailed explanation:

Zone 1 introduction

说明: C:\Users\wqm\AppData\Local\Temp\SNAGHTML5a24778.PNG

This area is related to operation and debugging.

1. Compile the module shown in 2

2. The module list of the current project

3. Run the module shown in 2

4. Debug the module displayed in 2

5. Module code coverage shown in test 2

6. Debug the running process of Android

7. Re-run the module shown in 2

8. Stop running the module shown in 2

Zone 2 introduction

说明: C:\Users\wqm\AppData\Local\Temp\SNAGHTML5a94cd5.PNG

This area is mainly for operations related to Android devices and virtual machines.

1. Virtual device management.

2. Synchronize the Gradle file of the project. Generally, it needs to be synchronized when the Gradle configuration is modified.

3. Project structure, some project-related attribute configuration.

4. Android SDK management

5. Genymontion simulator (need to install Genymontion plug-in, install [simulator installation] part)

Zone 3 introduction

说明: C:\Users\wqm\AppData\Local\Temp\SNAGHTML5bde3b7.PNG

This area is mainly related to operations such as project file resources.

1. The organization method of the files in the display project is displayed in Android mode by default. You can choose "Project, Packages, Scratches, ProjectFiles, Problems..." and other display methods. Android and Project are the two most commonly used.

2. Locate the position of the currently opened file in the project directory.

3. Close all expansion items in the project directory.

4. Some additional system configuration, after clicking open, a pop-up menu:
image

After Autoscroll to Source and Autoscroll from Source are checked, Android Studio will automatically locate the position of the currently edited file in the project, which is very cool to use. You can explore other functions yourself.

Zone 4 introduction

说明: C:\Users\wqm\AppData\Local\Temp\SNAGHTML5cee482.PNG

This area is mainly used to write code and design layout.

1. Tab page of the opened file. (Press the Ctrl key + click the mouse on the Tab page and a pop-up menu will appear, which will surprise you!)

2. The UI layout preview area.

3. Layout editing mode switching. For some veterans, they prefer to edit the layout through Text. Novices can try Design editing layout. After editing, switch to Text mode, which is very helpful for learning Android layout design.

Zone 5 introduction

Most of this area is used to view some output information.

1. Terminal-Partners who like command line operation do not need to start the terminal additionally.

2. Monitoring-You can view some output information of the application.

3. Information-some output information of project compilation.

4. Run-some relevant information after the application runs.

5. TODO-a list marked with TOTO comments.

6. Events-some event logs.

7. Gradle console, through which you can understand some output information when Gradle builds the application.

Android Studio directory structure

说明: C:\Users\wqm\AppData\Local\Temp\SNAGHTML6038007.PNG

1. Gradle compilation system, the version specified by the wrapper

2. Files required by Android Studio IDE

3. Storage directory of application related files

4. Relevant files generated after compilation

5. Store related dependency libraries

6. Code storage directory

7. Resource file storage directory (including: layout, image, style, etc.)

8. A list of basic information about the application, describing which components exist

9. Git version management ignores files and marks which files do not need to enter the git repository

10. Project files of Android Studio

11. The gradle related configuration of the module

12. Code obfuscation rule configuration

13. Gradle related configuration of the project

14. Global property settings related to gradle

15. Local attribute settings (key settings, android sdk location and other attributes)

Application development and debugging

说明: C:\Users\wqm\AppData\Local\Temp\SNAGHTML60a7a4d.PNG

As shown in Figure 1 above, click to set a breakpoint at the line number to be debugged, and then click the Debug button shown in 2 (or directly press the Shift+F9 shortcut key) to start debugging.

As shown in the figure above, a debug view appears under Android Studio.

1. The line of code where the current program stays

2. Some buttons related to debugging

3. The program call stack area, this area shows all the methods called by the program execution to the breakpoint, the lower the lower, the earlier it will be called.

4. Local variable observation area

5. User-defined variable observation area

1. Step Over (F8)-the program executes one line down. If there is a method call in the current line, this method will return after execution, and then go to the next line.

2. Step Into(F7)-The program executes one line down, if the current line has a user-defined method (unofficial class library method) called, then enter the method.

3. Force Step Into(Alt+Shift+F7)-The program executes one line down. If there is a method call in the current line, enter the method.

4. Step Out (Shift+F8)-If you enter a method during debugging and think that the method is okay, you can use Step Out to jump out of the method and return to the next line where the method is called. It is worth noting that the method has been executed.

5. Drop Frame-After clicking this button, you will return to the call of the current method to execute again, and the values ​​of all context variables will also return to that time. As long as there is a superior method in the call chain, you can jump to any one of them.

6. Run to Cursor(Alt+F9)-Run to the cursor position.

7. Resume Program (F9)-keep running the program until it hits the next breakpoint.

8. View Backpoints (Ctrl + Shift +F8)-View all breakpoints you have set and can set some properties of the breakpoints

9. Mute Backpoints-After selecting, all breakpoints are set to invalid state. Click again to reset all breakpoints to be valid.

After clicking the View Backpoints button, a breakpoint properties window will appear, allowing you to make some more advanced settings for the breakpoint.

说明: C:\Users\wqm\AppData\Local\Temp\SNAGHTML6dbfefa.PNG

1. List the breakpoints set in all programs

2. Conditions can be entered, and the breakpoint will work only after the condition is established (for example: input i == 8 in the input box). This conditional breakpoint is very useful in the actual development process. You can also set a conditional breakpoint by right-clicking the breakpoint, as shown in the following figure:

Well, the debugging related functions are all introduced here.

Application packaging signature

basis

In an Android Studio project, there will be multiple .gradle files. Among them, there is a build.gradle file in the project directory and a build.gradle file for each module.

Build.gradle in the project

buildscript {
	repositories {	 
	  jcenter()   // 声明使用 maven 仓库
	}
	dependencies {	 
	  // 依赖android提供的2.1.0-alpha5的gradle build
	  classpath 'com.android.tools.build:gradle:2.1.0-alpha5'
	}
}
// 为所有的工程的repositories配置为jcenters
allprojects {
	repositories {
	jcenter()
	}
}

// 清楚工程的任务
task clean(type: Delete) {
	delete rootProject.buildDir
}

Build.gradle in the module

// 这表示该module是一个app module
apply plugin: 'com.android.application'
android {
	// 基于哪个版本编译
	compileSdkVersion 23
	// 基于哪个构建工具版本进行构建的
	buildToolsVersion "23.0.3"

	// 缺省配置主要包括:应用ID,最小SDK版本,目标SDK版本,应用版本号、应用版本名
	defaultConfig {
	    applicationId "open_open.com.helloworld"
	    minSdkVersion 10
	    targetSdkVersion 23
	    versionCode 1
	    versionName "1.0"
	}

	// buildTypes是构建类型,常用的有release和debug两种,可以在这里面启用混淆,启用zipAlign以及配置签名信息等。
	buildTypes {
	    release {
	        minifyEnabled false
	        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
	    }
	}

}

// dependencies它定义了该module需要依赖的jar,aar,jcenter库信息。
dependencies {
	compile fileTree(dir: 'libs', include: ['*.jar'])
	testCompile 'junit:junit:4.12'
	compile 'com.android.support:appcompat-v7:23.2.1'
}

Package signature

Select Build->Generate Signed APK..., as shown below:

Continue to Next in the pop-up window until the following interface:

If there is no Key, we can first click the Create new... button to create a Key. The creation process is very simple, as shown below:

If you already have a Key, click the Choose existing... button to specify the location of the .jks file, as shown below:

Enter the Key store password and Key password (the two passwords entered when creating the Key), and click the Next button:

Next, click the Finish button and wait for the AS package and signature to be completed. After the signature is completed, AS will prompt us:

Click Show in Explorer, you can find our signed APK file:

This article  has been included in the open source project: https://github.com/Android-Alvin/Android-LearningNotes , which contains self-learning programming routes in different directions, a collection of interview questions/faces, and a series of technical articles, etc. The resources are continuously being updated …

Original link: http://www.apkbus.com/blog-822715-68465.html

Author: jeck cat
link: https: //www.imooc.com/article/76264
Source: Mu class network

Guess you like

Origin blog.csdn.net/weixin_43901866/article/details/108623077