Android Studio, Android Studio

Source: Internet
Author: User

Android Studio, Android Studio

This article is an original article. For more information, see the source.

This article mainly recommends developers who have switched from Eclipse to Android Studio (hereinafter referred to AS) to introduce the most basic and commonly used functions of, old drivers should bypass O (lead _ lead) O to avoid delay in valuable time.

Main content:

(1) Environment Construction

(2) create a project (including Module creation)

(3) code obfuscation

(4) common debugging functions and Application Analysis

(5) package APK

I. Environment setup (Windows)

(1) install JDK. Note that AS requires JDK 7 and later. The installation process will not be repeated;

(2) download AS. If you cannot download it from the official website for special reasons, please download it here;

(3) AS Installation

1. Select your desired installation location, for example:

2. If the installation succeeds step by step, the following interface is displayed:

3. Configure the first run

 

4. If the Android SDK fails to be downloaded, go to the AS startup page.

 2. Create a project (including Module creation)


(1) create a project

Go to the AS, and click File> New Project in the upper left corner, AS shown below:

Go to the following page:

Next step:

Next step:

Next step:

Complete.

(2) Main Interface Introduction

(3) Preview

 

(4) create a Module

The Module is provided for medium and large project AS, which facilitates project hierarchy and separation logic, making the project logic clearer and easier for project maintenance. The creation module is as follows:

Go to the following page:

Go to the next step and complete the creation as follows:

For details about how to create and use a Module, refer to my other article.

Ii. code obfuscation

The AS project is built and managed by Gradle. A lot of information about the application can be set here, AS shown below:

For code obfuscation in AS, you need to set it in the build. gradle file and the proguard-rules.pro file (you can use the jd-gui tool to compare the effects before and after obfuscation ):

 

(1) build. gradle File

 

 

MinifyEnabled: Indicates whether to enable obfuscation. The default value is false.

 

ProguardFiles: obfuscated configuration files, typically using the default proguard-rules.pro file in the project.

 

(2) proguard-rules.pro documents

 

 

For details about obfuscation settings, refer to the progurad official website.

 

Note the red box section in the figure, because all jar packages (here, JAR package obfuscation examples are provided, and APP obfuscation is similar to this) both require external interfaces (modules without external interfaces do not make much sense). There are multiple ways to set external interface classes:

 

A:-keep public class *, for example:

 

-Keep public class *{
Public protected *;
}

 

B: See.

 

A module generally has many class files. When obfuscation, we hope that the class names of all the class files except for the external interface classes will also be confused. Then we can create a separate base class or interface, let the external interface class inherit the base class or interface.

 

C:-keep public class XXX. The specific classes are not obfuscated. For example:

 

-Keep public class xiaoshubao. player. UserLogin {
Public protected *;
}

Iv. common debugging functions and Application Analysis

(1) create a simulator (the creation process is omitted)

(2) run the simulator

 

(3) Application Analysis

1. log output, as shown in.

2. Memory Analysis

A:

B:

C:

D: memory information collection

E: Use MemoryAnalyzer (MAT) to analyze Memory leakage

First, importing the hprof file generated in the previous step into the MAT tool is not usable and requires conversion. There are two conversion methods:

  • Method 1:

 

  • Method 2: Use the hprof-conv tool for conversion and then import it to the MAT tool. The hprof-conv tool is in the platform-tools directory of the Android SDK, as shown below:

Copy the Snapshot_2016.07.20_21.52.57.hprof file to e:/1/folder, export it to the hprof-conv.exe directory, and run the conversion command as follows:

Generate the Target 3. hprof file as follows:

Import the converted hprof file in MAT as follows:

The CPU, GPU, and other tabs will not be repeated. You can study them on your own.

5. Package APK

Build-> Generate Signed APK

The following page is displayed:

(1) Create a New JKS signature file as follows:

(2) Select an existing JKS File

(3) Here we will demonstrate creating a new JKS signature file, as shown below:

Click OK. The following page is displayed:

Click Next, as shown below:

Click Finish to generate the APK file with our own signature:

When the new version of the APP is released in the future, you can use the JKS file generated just now to sign the APP. Note that the new version of the signature file must be the same as the old version of the signature file, multiple apps can share the same signature file.

Conclusion,This article mainly explains how to use AS to create a project, debug a project, and publish a project. With the increasing degree of familiarity, you can study it in depth, such AS Gradle construction and memory analysis.

 

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.