Everything you should know when using Android studio for the first time (ii): Create a new project of your own and install the Genymotion simulator

Source: Internet
Author: User
Tags jcenter

Statement

Welcome reprint, but please keep the original source of the article →_→

Life One number: http://www.cnblogs.com/smyhvae/

Article Source: http://www.cnblogs.com/smyhvae/p/4392611.html

Series

Everything you should know when using Android studio for the first time

Everything you should know when using Android studio for the first time (ii): Create a new project of your own and install the Genymotion simulator

Everything you should know when using Android studio for the first time (iii): Gradle project Build

Body

All said the holiday does not rest, playing is so capricious!!!

"Development Environment"

Physical Machine Version: Win7 flagship edition (64-bit)

Android Studio Version: 1.1 Official edition


First, the new project:

1. Create a new project:

Open Android Studio and create a new project with the following interface:

, after you have set the project name and path, you can follow it all the way next:

Second, the use of Android studio method;

1. Modify the project structure view:

When project is new, the default structure is as follows:

As you can see, the directory structure of as is very different from eclipse, so let's see the table below for a glance:

Of course, if you want to switch to a similar view in Eclipse, click on the top left corner to switch views:

After switching, the view is as follows:

, the app at the arrow is actually a module, and the concept of module is explained later.

2, the common functions of the toolbar:

There are several commonly used buttons on the as toolbar, namely Gradle Sync, AVD Manager, SDK Manager, DDMS, as shown in:

The explanations are as follows:

    • Gradle synchronization: When you run the project or change the Gradle configuration, you have to click this button, will download the corresponding dependency
    • AVD Manager: Emulator Manager
    • SDK Manager: Just manage your SDK version
    • DDMS: Dalvik Debug Monitor Service,dalvik Debug monitoring service.

3. Import third-party jar packages:

The import jar package in Eclipse is the first to copy the jar package into the project file and then add to build path, but not in Android studio. The way to import a jar package in Android Studio is: (take Google's Gjson.jar as an example)

Copy the Gson-2.3.jar file to the Libs directory of the project file:

After importing, select the Jar package and click the button at the Middle arrow: (Synchronize: Sync, can be understood as refresh)

Get.

4. Modify the default activity inheritance appcompatactivity:

Creating new activity in Android Studio 2.1 defaults to inheriting appcompatactivity, which is very uncomfortable (this is not the case with older versions of AS). Looking for a long time, finally found in the Android Studio installation directory has a template file, modify the parameters can be.

You can refer to this blog post for specific actions:

Android Studio modifies default activity inheritance Appcompatactivity

Third, install the Genymotion simulator:

1, the installation of genymotion:

Genymotion is undoubtedly the fastest and best simulator available. Official website: https://www.genymotion.com/

The simplest way to register, then download, and install VirtualBox is to download a genymotion package that contains VirtualBox, as shown in the Red box section:

When the download is complete, start the installation. Then run the Genymotion software, you will be prompted to create a virtual device, click the Yes button to start creating a virtual device:

Connect using a previously registered account:

Then select one of the versions of the emulator:

Of course, if you want to run the program on the emulator, make sure the emulator is loaded with the Android SDK:

Note: If the following error occurs when you start the emulator:

Upgrade your computer graphics card driver on the line.

In this way, our simulator is built and can be started up. Next, you'll associate the emulator with Android studio.

2. Associate Simulator Genymotion with Android Studio:

Genymotion Official website Tip There are two methods (as shown), one for online installation and the other for offline installation. The method is already very clear, I will not screen the demo ha.

After the plugin is installed, reboot the software and let the newly loaded plugin take effect. After restarting the software Android Studio, select the menu bar "View--toolbar" and let the toolbar appear, and you can see that the toolbar has a Genymotion Device Manager icon:

Click on this icon to bring up the following screen:

, load our previously installed Genymotion folder. Then click on this icon to bring up the following screen:

Done.

Next, run the program on the emulator:

The results are as follows:

, you can see that the version I compiled is API 19, but the emulator version is API 16, but the program is still running, which shows that Android studio does a good job with version compatibility issues. However, prior to using IntelliJ idea, you must require that the compiled version and the emulator (real machine) version be consistent.

Iv. creating a third-party library in module form: (Introduction of module concept)

Look at this table again:

After reading the picture, you should know the concept of module. The attentive little companion can find that the application module has a mobile icon:

1, a new module as the library: (take stickyscrollviewitems This library as an example )

Note: The effect ofStickyscrollviewitems is that the child control can hover over the ScrollView (fixed at the top when the child controls scroll to the top of the page).

In the AS, we can create a new module to use as the library, operating as follows:

, create a new module in the current project, and then pop up the following interface:

, select the type of module for the Android Library, and then continue:

, since this module is a libray, there is no need for activity.

The two module at the Middle Arrow: the first is the application module, the second is the Lirary module, and you can see that their icon icons look different.

2. Copy some of the files from the Stickyscrollviewitems-master compressed package on GitHub to the Lirary module:

The operation is as follows:

(1) The stickyscrollviewitems-master\stickyscrollviewitems-master\library\res\ The Attrs.xml file in the values directory is copied to the values directory in the Lirary module.

(2) The Stickyscrollviewitems-master\stickyscrollviewitems-master\library\src\com\emilsjolander\components\ The Stickyscrollview.java file in the Stickyscrollviewitems directory is copied to the Java directory in the Lirary module.

The final effect is as follows:

Summary: A common practice for creating a third-party library in module form is to:

(1) Create a new module in the library form and delete all the files in the src/main directory in this module (including deleting Java, res, androidmanifest.xml)

(2) Copy the Androidmainfest.xml, res, src files (clips) from the third-party library to the Src/main directory of the Library directory

(3) Rename the src directory under the Src/main directory (SHIFT+F6) to Java

(4) Remove the dependencies and release modules from the Build.gradle file in the Library module (be careful not to modify the wrong place)

3, the application module depends on the library module:

The operation is as follows:

, right-click on the app and select "Open Module Settings" to bring up the following interface:

Follow the steps, in the Dependencies tab, add "Module dependency", pop up the following interface:

, you can import the Stickyscrollviewitems module.

Depends on success, so we can see its code hints in the layout file:

Let's test it here.

4. Test the usability of the Library module:

Modify the Activity_main.xml to the following code:

1<Com.smyhvae.stickyscrollview.StickyScrollView2Android:layout_width= "Match_parent"3Android:layout_height= "Match_parent"4Android:fadingedge= "None"5Android:overscrollmode= "Never"6Android:fillviewport= "true"7Xmlns:android= "Http://schemas.android.com/apk/res/android">89<LinearLayout10Android:layout_width= "Match_parent"11Android:layout_height= "Wrap_content"12Android:orientation= "Vertical">1314<View15Android:layout_width= "Match_parent"16Android:layout_height= "200DP"17Android:background= "@color/blue"/>1819<View20Android:layout_width= "Match_parent"21stAndroid:layout_height= "100DP"22Android:background= "@color/red" Android:tag= "sticky"/>   2425<View26Android:layout_width= "Match_parent"27Android:layout_height= "100DP"28Android:background= "@color/green"/>29<View30Android:layout_width= "Match_parent"31Android:layout_height= "100DP"32Android:background= "@color/white"/>3334<View35Android:layout_width= "Match_parent"36Android:layout_height= "300DP"37Android:background= "@color/purple"/>3839<view40 android:layout_width=" match_parent "41  Android:layout_height= "100DP" 42  Android:background= "@ Color/yellow "/>43 44" Span style= "COLOR: #0000ff" ></linearlayout>45 </ Com.smyhvae.stickyscrollview.stickyscrollview>      

In the above code, we introduced the module Stickyscrollview as the library, the core code is the 23rd line, we added the red view android:tag= "sticky" this tag, so it will have hover properties. Then run the program directly.

The entire project file for this section is as follows: (You can import into your own as to run a look at the effect)

Links: Http://pan.baidu.com/s/1eQ8epsY

Password: k9i1

V. Delete a module:

, what should I do if I want to delete the module Stickyscrollview? The way is: Select Stickyscrollview this module, and right click, found no delete option, no relationship, we select the Red box section of the "Open module Settings" option, pop up the following interface:

, click the minus sign at the arrow to delete it. At the same time we want to remove the app this module relies on it:

You will then notice that the icon for the module Stickyscrollview disappears:

, and now right-click it, you can delete it and delete it from the hard disk directly:

Vi. tips for deleting files: (Safe removal)

If we want to delete a file, we can right-click and delete, but Android studio has a more user-friendly experience. For example, when I want to delete a layout file:

, click Delete to remove it, and the following screen appears:

, if the red box part is ticked, then click OK, the software will prompt you, where to use this file:

Show that there is a place to use this file, click on the "View usages", you can see the detailed situation:

If you are determined to delete, click the arrow position can be, how? Is the user experience good?

How? Still not satisfied? I will continue to fight tomorrow, so please wait ~ ~ ~

Note:

In my fourth paragraph, a new module was used as the library, and the library was quoted in Stickyscrollviewitems. The entire project file is also given a download link at the end of the fourth paragraph, where the Gradle file code is as follows: (Gradle will be covered in the next article)

Application's Build.gradle:

1//Top-level build file where can add configuration options common to all sub-projects/modules.23Buildscript {4repositories {5Jcenter ()6}7dependencies {8 Classpath ' com.android.tools.build:gradle:1.1.0 ' 9 10 // Note:do not place your application dependencies here; They belong11 // in the Individual module Build.gradle files12 }13 }14 15" Span style= "COLOR: #000000" >allprojects {16  repositories {17  Jcenter () 18 }19}        

App's Build.gradle:

1 Apply plugin: ' Com.android.application '23Android {4 Compilesdkversion 195 buildtoolsversion "21.1.1"67Defaultconfig {8 ApplicationID "Com.smyhvae.helloworld"9 Minsdkversion 14Ten targetsdkversion 19Versioncode 1Versionname "1.0"13}14 buildtypes {15  release { Span style= "COLOR: #008080" >16 minifyenabled false17 Proguardfiles getdefaultproguardfile (' proguard-android.txt '), ' Proguard-rules.pro '  }19 }20 }21 22 dependencies {23 compile Filetree (dir: ' Libs ', include: [' *.jar ') Span style= "COLOR: #000000" >) 24 Compile Project (': Stickyscrollview ' 

Library This module's build.gradle:

1 Apply plugin: ' Com.android.library '23Android {4 Compilesdkversion 195 buildtoolsversion "21.1.1"67Defaultconfig {8 Minsdkversion 149 Targetsdkversion 19Ten Versioncode 1Versionname "1.0"12 }13  Buildtypes {14  release {15 minifyenabled false16 proguardfiles Getdefaultproguardfile (' Proguard-android.txt '), ' Proguard-rules.pro ' 17 }18 }19" Span style= "COLOR: #000000" >}20 21 dependencies {22 compile Filetree (dir: ' Libs ', include: [' *.jar ' ") 23}         

Everything you should know when using Android studio for the first time (ii): Create a new project of your own and install the Genymotion simulator

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.