Getting Started with Android Studio

Source: Internet
Author: User
Tags android sdk manager

本文适用于从Eclipse转AndroidStudio的开发人员

Recently intends to write a series of ANDROID0 basic development tutorials, an estimated more than 40 articles, combined with my actual work experience, write some of the work is often used in the technology, so that people just start learning can be less detours, this is the first article of this series, 345 great God wrote.

Original address

One. Download and install
    1. Installing the JDK and configuring the JAVA_HOME environment variable

      这个就略过了,纯小白请自行百度
    2. Android Studio Installation

      截止到2016年4月9日Android studio的最新稳定版本号为2.0,推荐使用该稳定版本号。

    • 1 website download page Portal

      假设下载速度非常慢。请复制下载连接到迅雷,万能的迅雷会帮你提速的。假设根本打不开请移步地址2
    • 2 Androiddevtools

      You need the basic will have here, strongly recommend to download here.


      If you have downloaded the SDK locally, it is recommended to download the zip-free version, the first time you start the configuration of the SDK directory is good.

Two. First time start
    1. Do not rush to start after installation, the first boot will pop up check the SDK update components and other settings, click Finish may be downloaded. Assume that the proxy is not set. This interface will be stuck for a very long time.

Workaround

    • Close Android Sutdio, open the bin directory under the Android Studio installation directory, locate idea.properties and open it.

    • Add the following code at the end of the file, for example:
# 禁用首次检查sdk功能disable.android.first.run=true
    • Restarting Android Studio will no longer show the SDK Setup Check screen.

      1. When you are finished, you will see the following interface

Click Configure Select SDK Manger to configure properties such as SDK directory

Click on the lower left corner to connect to launch SDK Manger Configuration SDK Update image
I want to say this step in the celestial kingdom is necessary, reason I think you understand

The following is the usage of the SDK update Mirror site:
Please refer to Androiddevtools for more details.
1. Launch Android SDK Manager. Open the main interface and select Tools, Options ... to eject the Android SDK manager-settings form.

    1. In the "Android SDK manager-settings" form. Fill in the "HTTP proxy server" and "HTTP proxy Port" input boxes with the above mirrored Server addresses (not including http://.) For example) and port. Also select the "force https://... sources to be fetched using http://..." check box.

      Click "Close" button to close the "Android SDK manager-settings" form to return to the main interface;

    2. Select "Packages", "Reload" in turn.

      选择镜像站点的时候要注意的是,并非全部的适合别人的就适合你还有可能根本无法更新。因为server远近带宽的问题,你应该选择适合自己的镜像,怎么选择。

      。。。我想说设置成功后选择更新个没下载的文件能成功下载更新而且速度不慢的就是合适的

    3. Theme Settings

This is nothing to say, but the pursuit of the black theme of the small partners to care about this a lot, here is the explanation.
Start Page Click configure-> Select Prefrences->appearance->theme->darcula that's the black Visual Studio style theme->apply finished

If you want a lot of other font keywords color what personalized configuration, recommend to the following URL download

View=index ">http://color-themes.com/?view=index
Choose the theme you like to download and download it to a jar file. Usage:

    在AS中选择File->import settings ->选择下载的jar文件->勾选editor color 确认
Three. Project projects
    1. New Project

Follow the guidance step by step, and note the selection of the minimum compatible version number. When creating a new project, there is no option to compile the version number, the highest version number of the currently installed SDK. As gives a few activity templates, the implementation of the template is more classic. Recommended new one take a look.

    1. Project directory Structure

Create a new project Click on the top left structure view toggle. Switch to the project directory structure (often used in development is Android view, relatively concise) app2 and mylibrary is to facilitate the next explanation after the newly completed manually added module default new project is not.

  • MyApplication directory status is quite eclipse of workspace

      Unlike the Asproject directory, which has more configuration files for global projects, More important are the local.properties, Setting.gradle, Gradle.properties, Build.gradle, and Gradle directories  
    • Local.properties
      can set your SDK, NDK configuration, normally do not need to change
    • settings.gradle
      The file contains only a sentence, the declaration includes the module
      For example, the above project includes three module

      include ': App ', ': app2 ', ': MyLibrary '
    • gradle.properties
      Some of the parameters that are used by the Gradle compilation do not need to be changed under normal circumstances
    • Build.gradle
      Defines the version number of the warehouse dependencies and some gradle commands normally do not need to change
  • Module directory

    This directory, like the Eclipse directory, is very easy to understand the corresponding relationships of the various catalogs, and more specifically a series of mipmap directories than Eclipse. Mipmap and drawable directories are used to store pictures, according to the official document is the mipmap directory just put the application icon.

    Other drawable resources that need to be used are placed in the corresponding drawable directory as before.

    When you create a new moudle, the drawable directory has only the default non-resolution parameters, and the directories for different resolutions need to be built manually. As provides a convenient way to create

    Right-click on Moudle on the Android resource directory, select the type drawable the left side list select density Select the DPI
    For example with



    Other res files are created in the same vein.

    1. Open the online download Asprojectgradle error problem

Sometimes we download a demoproject on the Internet after opening Gradle error can not be executed, this situation most because the Gradle version number is inconsistent, as download the corresponding version number of failure caused by the problem. In general, there are two ways to solve the problem
* Manually download the corresponding Gradle version number to the local directory

    这样的方式不推荐有兴趣的自行搜索

* Change the Gradle configuration to open Project

Refer to the same file for local new project
Gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip//改动版本号号与本地project文件同样

Build.gradle

dependencies {        ‘com.android.tools.build:gradle:2.0.0‘        //改动版本号号与本地project文件同样}
Four. Join the dependency

Understanding the project structure after simple compilation execution debugging generally there should be no problem, after all, the menu bar, the bottom functional form function tips are very clear. Here's a more problematic place to be: Join a dependent project or perform a third-party project error.

There are generally three ways to join a dependency
1. Dependencies on adding code warehouses

The simplest way to do this is to add a word to the dependencies inside the Build.gradle of the project module and build it again. Such as:

dependencies {    compile fileTree(dir‘libs‘, include: [‘*.jar‘])    ‘junit:junit:4.12‘    ‘com.android.support:appcompat-v7:23.3.0‘    ‘com.android.support:design:23.3.0‘    //加入了OKHttp的依赖    ‘com.squareup.okhttp3:okhttp:3.2.0‘}

Ability to manually join or right-click Project to search in open module settings (recommended way)

AS会自己主动联网下载加入的依赖 这个一般不须要FQ
    1. Dependency of the JAR package

This is the simplest and does not have to be networked, like Eclipse to copy the jar package into the Libs directory, and then need to build the project again click the menu bar Build button to

The left side of the jar file in the left sidebar should have a pointed tip to expand view jar Package Contents

Some jars also need to be associated. So library just need to build a directory named Jnilibs below the main directory of the SRC directory to copy the so library in (same as res directory)

3. Reliance on the Libray project

Very often we need to use the project we downloaded from GitHub to add the libraries we provide to our project, such as the following first importing the module and then joining the dependent
Open project structure, join new Moudle, select the module for the library you want to import in the downloaded project file
note Instead of importing the entire project directory that is downloaded, select the module directory



Add the imported library to the dependency of the target project

当导入的library里的项目build.gradle文件里包括一些上传到版本号仓库的信息的话导入过后可能会报错,这时候仅仅须要把不必要的信息凝视掉就可以,须要保留的是编译配置,依赖关系。目录配置。例如以下
apply plugin:  ' com.android.library '     //Project compilation information  Android {compilesdkversion 23  Buildtoolsversion  "23.0.2"  defaultconfig {minsdkversion 11  targetsdkversion 23  versioncode 1
      versionname  "1.0" }}//dependency information  dependencies {Compile filetree (dir :  ' Libs ' , include: [ ' *.jar ' ]) testcompile  ' junit:junit:4.12 '  compile  ' com.android.support:appcompat-v7:23.2.1 '  compile  ' com.android.support:design:23.2.1 ' }  

Of course, you can also manually copy the module directory to the project directory and then change the Settings.gradle file. Just do not recommend such a way.

Five. Shortcut keys

As the self-active prompt function is very powerful, there will be input after the active pop-up prompts do not need to press alt+/like eclipse as prompted, as for the other as the shortcut keys are not explained, the last picture take to self-cultivation bar

Six. Plug-in installation

Open Setting page Find plugins search installation

Recommended a few as plug-ins, detailed usage please self-Baidu
1. Gsonformat
2. Android-butterknife-zelezny
3. Jsononlineviewer

Seven. Multi-channel Package

Domestic online apps are generally published from multiple channels. In order to count the amount of channel installation it is generally necessary to produce one installation package per channel. As comes with multi-channel packaging capabilities. The multi-channel packaging feature is definitely one of the most useful features of AS. Here's a little bit of emphasis.

    1. Generate Signature File

Signature files can be generated in Build->generate signed APK---Select project Next->create new, in the same way as Eclipse

    1. Set up a signed file for packaging

Open module setting Create a new signing entry select signature file fill in the password alias of the signature file, etc.

    1. New Flavors Configuration

As a demo sample I've created three new configurations and selected the signature configuration for packaging a offline_debug, a release_360, a Release_baidu

    1. Change module's build.gradle and mainfest files

Follow the previous step to configure it. The build.gradle will have more productflavors and singconfig configurations. What we're going to change is the Productflavors section.


How to change us to illustrate

This is part of the change in the Build.gradle file.

Defaultconfig {ApplicationID"Com.example.mark.myapplication"Minsdkversion -Targetsdkversion atVersioncode1Versionname"1.0"Buildconfig. is_sign = False Buildconfigfield"Boolean","Is_sign","false"} productflavors {offline_debug {signingconfig signingconfigs. SignconfigHere is the notation for a variable manifestplaceholders = [app_name:"Debug Version number"]} release_360 {Signingconfig signingconfigs. SignconfigBuildconfig. is_sign = True Buildconfigfield"Boolean","Is_sign","true"Here is the notation for multiple variables manifestplaceholders = [App_name:"360 version number", EXAMPLE:" the"]} release_baidu {Signingconfig signingconfigs. SignconfigBuildconfigfield"Boolean","Is_sign","true"Manifestplaceholders = [App_name:"Baidu version No.", EXAMPLE:"Baidu"]        }    }

The Buildconfigfield "boolean", "Is_sign" and "false" in Defaultconfig include a bool variable named Is_sign in the Buildconfig class generated by the build project. and assigns a value of false.
This variable is able to be used in the code, such as the following code can be used to switch the line and the next request address

publicstatic String BASE_URL;    static {        if(BuildConfig.IS_SIGN){            "线上地址";        }else{            "线下地址";        }    }

Manifestplaceholders = [app_name: Debug version number] In productflavors is the meaning of replacing the variable app_name in the Androidmanifest.xml file with the string following the colon. This is just a notation for a variable to be replaced. Examples of how many variables you should follow. This app_name in the manifest file definition format For example the following ${variable name} in the packaging of the time Gradle will take the initiative to replace the placeholder variable.

<activityandroid:name=". Loginactivity "android:label=" ${app_name} ">                                    <intent-filter>                <action android:name="Android.intent.action.MAIN" />                <category android:name="Android.intent.category.LAUNCHER" />            </intent-filter>        </activity>

Such a variable definition can be in today mainfest no matter what need string position, I above is just a demo sample, please ingenious do not copy copy.

    1. Packaged

At the same time, select the configuration item you want to package click Finish, and then you will be generating multiple apk at the same time.

Recommended to create their own Android QQ group: 202928390 welcome everyone to join.

Suppose you want to read our post in the first time, sweep the code to follow the public number. Weekly occasional Android Development tutorial articles are pushed off. What are you waiting for. Hurry up and pay attention. Learn technology,. Become CEO, win white Rich beauty.

。。。

.....

Getting Started with Android Studio

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.