Android Studio refactoring, let's get back to Google's official Android development tools

Source: Internet
Author: User
Tags configuration settings jcenter

Android Studio refactoring, let's get back to Google's official Android development tools

Remember my first blog is to write Android Studio, but now it seems a little rough, all refactoring a bit of thought, covering a

    • Google main push-android development tool--android Studio, which is probably the most complete as Tutorial!

Android Studio, since the release of Google2013, has been a favorite for Android developers, our book is based on Android studio to demonstrate the case, as we all know, Android The predecessor of studio was based on IntelliJ idea, and prior to that, our development of Android has been developed in the form of an ADT plugin for Eclipse, which may be the growing Android Google decided to develop a custom tool for its products like Apple's Xcode or Microsoft Visual Studio, so Android studio came into being, at this stage, Android The studio version has been updated to the 2.X version, the performance has been very stable, this is the reason why we use it to develop

1.1 Official Profile

Now that I'm using Android Studio, I'd like to take a look at the official introduction so that when we talk about how to use it later, we can pro

1.1.1 Smart Code Editor

At the heart of Android Studio is an intelligent Code editor that enables advanced code completion, refactoring, and code analysis.

This powerful code Editor can help you become a more productive Android app developer.

1.1.2 Code templates and GitHub integration

The New Project Wizard makes it easier than ever to start a new project.

You can start your project with template code for different modes, such as a drawer navigation bar and a view pager, or even import Google code samples from GitHub.

1.1.3 Multi-screen application development

Build apps for Android phones, tablets, Android Wear, Android TV, Android Auto, and Google Glass.

The new Android Project view and module support in Android Studio makes application projects and resource management easier.

1.1.4 for simulating all shapes and sizes of virtual appliances

Android Studio has pre-configured an optimized emulator image.

The updated and streamlined virtual Device Manager provides pre-defined device profiles for common Android devices.

1.1.5 Android version with Gradle evolution

Create multiple APK with different features for your Android app using the same project.

Use Maven to manage app dependencies.

Build the APK using Android Studio or the command line.

1.1.6 Summary
    • The Java IDE, launched by JetBrains and popular, is built on IntelliJ idea Community Edition
    • A flexible building system based on Gradle
    • Build variants and multiple APK builds
    • Extended template support for Google services and a variety of device types
    • Rich layout editor that supports theme editing
    • Lint tools to capture performance, availability, version compatibility, and other issues
    • Proguard and App Signature features
    • Built-in support for Google Cloud platform for easy integration with Google Cloud Messaging and application engine
1.2 Download and install

Android Studio download is very simple, not only the official can download, there are a lot of domestic resource sites are available to download

Official address: http://developer.android.com/sdk/index.html

But here's a look at the downloaded version

There is only one download for Mac and Linux platforms here, but there are three windows, so here are the three differences.

    • The Android Studio installation package integrates the SDK
    • Android Studio installation Package
    • Android Studio Package decompression can be used

The first two are one with SDK, one no, third, he does not need to install, download down decompression, it can be used, and he has two initiators, a 32-bit, a 64-bit

We have integrated the SDK installation package as an example, to demonstrate how to install, in fact, it is not difficult, as long as you double-click to open the installation package, always point to the next step, you will be prompted to import the project, select the path of the SDK, download some of the SDK support package needs, then, our Android Studio is finished with the installation

1.3 Configuration settings

A good IDE, strong premise, but also to conform to their own coding style, so we have to do some settings for her, so as to experience his power

1.3.1 Themes

The black theme of Android Studio is also very in line with the programmer's style, so a lot of people will choose this style, we enter the settings (tool class wrench icon), here theme default is our choice Darcula here, Then click Apply to apply this black theme.

1.3.2 Coding Style

When we write code, some of the font color size and so on is worth noting, including the code to display the number of lines can also help us debug the bug

    • Font size

      We entered the Settings-editor-colors & Fonts-font, the default two themes we can not modify, we need to customize a theme and then to be modified, the operation is as follows: We click Save As to prompt you to name, you write a name, You can see that 1.3.2 shows


Here the primary font is the font, you can choose the font you like, size is the font, line spacing is line spacing

Of course, you can also see a lot of settings in the colors & fonts directory, such as the font size of the Consale font console, this is not much to repeat here.

    • Automatic Guide Package

      Manual Guide Package is still a bit troublesome, we are in line with the principle of saving, set up the function of automatic guide package, the path is: Settings-editor-general-auto import option, tick the following several options

      • Xml
        • Show Import Popup
      • Java
        • Insert Imports on paste Select None
        • Show Import Popup
        • Optimize imports on the fly
        • Add unambiguous imports on the fly
      • C + +
        • Show Import Popup
    • Show lines of code

      This function is also very important, we can tick settings-editor-general-appearance-show line numbers on it.

1.3.3 Intelligent

Here we can set the smart for Android studio to set shortcut keys, Automatic code hints, automatic code completion and other functions

    • Shortcut keys

      Android Studio shortcut compared to eclipse or do some changes, but, Google does very flexible, he provides the choice of shortcut keys, we enter the Setting-keymap to choose Eclipse, familiar shortcut key back

    • Code Automatic Hints

      Code automatic hints set up is also very convenient, eclipse, your mouse hover over the code will pop up the prompt box, but then Android Studio default is not, because if the computer configuration is not very high, this will make the interface very card, If you want to open this function we can go into the settings-editor-general and put the show Quick doc on mouse move hook on it.

    • Case insensitive

      Android Studio is case-sensitive by default, that is, when you enter the code, if you enter lowercase, the code may not prompt, of course, we can also set the Settings-editor-general-code, in the completion, Case sensitive completion to choose None.

    • Cancel Load

      I think it's a great feature, like I'm doing a project, then I'm shutting down Android studio, and I'm going to open Android studio next time and he'll automatically load this a project, but I actually want to do the B project, so we're canceling this feature, Let him every time to enter the homepage for our project selection, but also very simple, into the Systems-system settings, put reopen last project startup tick off can

1.3.4 Log

In development, log is an essential link, he can feedback a lot of programs to help us develop and debug bugs, so now there are a lot of log framework and tools, the default log in Android Studio is not really clear, We can set our own color for log to change his feedback interaction, we go into Settings-editor-colors & fonts-android log, we can see each level of log, as long as we put the use inberited Attributes the hook removed, you can change the color, here, provide a set of my color scheme for everyone to reference

    • VERBOSE BFB9B9
    • DEBUG 0374c0
    • INFO 4bc332
    • WARN c6c61e
    • ERROR FF0006
    • ASSERT a00308
1.3.5 Export/Import settings

It's a headache for Android studio to set up so many configurations every time you install it, and it leads to a humanized design of Android Studio, where you can save the setup as a jar package, and if you're newly installed Android studio, Can be imported directly into this jar, it is not so wasted time to configure, the method is very simple, our menu bar-file

    • Import Settings Importing settings
    • Export Settings Exporting settings
1.3.6 Plug-in

Android Studio Plug-in is still very convenient for us to develop, we have to sigh at once the powerful Android studio, such as Gsonformat,butterknife, we have a little introduction to the installation of plug-in several ways, We enter Settings-plugins.

Here is the list of plugins you installed, the following three buttons are

    • Install Letbrains plugin ... Official plugins
    • Browse repositories ... Third-party plugins
    • Install plugin from disk ... Local plugins
Official/third-party installation

We clicked Install Letbrains Plugin/browse repositories, here is a search page, we take Gsonformat for example, search Gsonformat. Then click Install, after the installation is complete, we can see the gsonformat figure in the list, the third-party plug-in method is the same

Local plug-in installation

Install the local plug-in is actually import, plug-in in the form of jar or zip, we just click Install plugin from disk, we select the plugin to

1.4 Gradle

What is Gradle? Gradle is the build system for the Android Studio project, which is based on the Groovy language and is oriented toward Java applications, based on the DSL (domain-specific language) syntax of the automated build tool, so there's the Android The project structure of studio is not the same as eclipse, so let's take a look at what we see in the project's Gradle scripts file.

Figure 1.4.1

These are some of the Gradle configuration checklists that have been built after our project, so let's take a concrete look at what these folders do.

    • Build.gradle Building Files
    • Build.gradle Module Build File
    • Gradle-wrapper.properties Gradle Related configuration files
    • Proguard-rules.pro Confusing files
    • Gradle.propertles configuration file
    • Setting.gradle setting up the configuration file
    • Local.propertles SDK,NDK configuration file

And what we need to know is not all, just know the build file and module build file, and we'll look at what's in the build file.

    sub-projects/modules.    buildscript {        repositories {            jcenter()        }        dependencies {            ‘com.android.tools.build:gradle:2.1.0‘            not place your application dependencies here; they belong            // in the individual module build.gradle files        }    }    allprojects {        repositories {            jcenter()        }    }    task clean(type: Delete) {        delete rootProject.buildDir    }

In this, is a standard Gradle build system code, we see

    • Jcenter () repository can be replaced
    • Classpath dependent version of Gradle
    • Repositories repository for all projects

Let's take a look at the module building system

Apply plugin:' Com.android.application 'Android {Compilesdkversion atBuildtoolsversion"23.0.3"Defaultconfig {ApplicationID"Com.lgl.helloandroid"Minsdkversion theTargetsdkversion atVersioncode1Versionname"1.0"} buildtypes {release {minifyenabledfalseProguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro '}}} dependencies {compile Filetree (dir:' Libs ', include: [' *.jar ']) Testcompile' junit:junit:4.12 'Compile' com.android.support:appcompat-v7:23.3.0 '}

Here, we need to pay more attention.

    • Apply plugin: Declaring the type of a project
    • Compilesdkversion: Highest API
    • Buildtoolsversion: Compilation tool version
    • ApplicationID: Package Name
    • Minsdkversion: Minimal API
    • Targetsdkversion: Compiled version
    • Versioncode: Version number
    • Versionname: Version number (subdivision)
    • Buildtypes: Build Type
    • Minifyenabled: Whether to compress apk
    • Proguardfiles getdefaultproguardfile: Confusing configuration file
    • Dependencies: Dependency Configuration
    • Compile Filetree: Relying on binary binaries
    • Compile: Remote binary dependencies
1.5 Multi-Channel packaging

The domestic Android Market so much, in order to count the download of each channel and other data statistics, we need to be packaged separately for each channel, if let you hit dozens of market package is not exhausted, but we saw gradle in the last section, this is not what the matter, here also derived a new word- Multi-channel packaging, as the name implies, is a key package of multiple channels, on the multi-channel packaging use of the platform and tools online is also more, seemingly with more than the Friends of the League, the details of the Friends of the League of the official online to see it!

The following values are modified in Androidmanifest.xml:

    <meta-data android:name="UMENG_CHANNEL" android:value="wandoujia" />    

Meta-data Modify the following look:

    <meta-data         android:name="UMENG_CHANNEL"         android:value="${UMENG_CHANNEL_VALUE}" />

The value in ${umeng_channel_value} is the value you customized in the Gradle.

Build.gradle file is written using productflavors:

    productFlavors {    wandoujia {    "wandoujia"]    }    baidu {    "baidu"]    }    c360 {    "c360"]    }    uc {    "uc"]    }    }

Where [umeng_channel_value: "Wandoujia"] is the value corresponding to ${umeng_channel_value}.

In fact, the above code is still a bit redundant, we can reduce

    productFlavors {    wandoujia {}    baidu {}    c360 {}    uc {}    productFlavors.all { flavor ->    flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]    }    }
1.5.1 Traditional Packaging method

We are familiar with the traditional way of packaging, with eclipse students should know that in eclipse, we just export Android can be packaged a project, in fact, the way Android studio is similar, the menu bar--build-- Generate signed APK

Here to fill in the fact that the same as eclipse, first is the path of the key store, we do not, all point create new to build

We fill in the path, password and so on, press OK, now he will help us to automatically fill, if not, you lose, then next, then finish will be OK

We can find our packaged apk in the app directory, and we can find our signature file in our designated location Xxx.jks

This article I have been writing a long time ago, was prepared to write a book when used, but the busy chores, give up, just want to share it, or later version update too fast, these also meaningless

If interested, you can add group: 555974449, we have a good chat ~

Android Studio refactoring, let's get back to Google's official Android development tools

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.