Android studio uses configuration for the first time (2) create a project and install the Genymotion simulator androidgenymotion

Source: Internet
Author: User
Tags jcenter

Android studio uses configuration for the first time (2) create a project and install the Genymotion simulator androidgenymotion

[Development Environment]

Physical server version: Win7 flagship edition (64-bit)

Android Studio version: official version 1.1


1. Create a project:

1. Create a Project:

Open Android Studio and create a Project. The interface is as follows:

After you have set the project name and path, you can click next:

Ii. Usage of Android Studio;

1. Modify the Project Structure View:

After the Project is created, the default structure is as follows:

AS you can see, the directory structure of AS is quite different from that of Eclipse. We can see the following table at a Glance:

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

After switching, the view is as follows:

In, the app at the arrow is actually a module. The concept of the module will be explained later.

 

2. Common Features of the toolbar:

There are several commonly used buttons in the AS toolbar, including Gradle synchronization, AVD Manager, SDK Manager, and DDMS, AS shown in:

Explanation:

  • Gradle synchronization: click this button when you run your project or change the Gradle configuration to download the corresponding dependency.
  • AVD Manager: simulator Management
  • SDK Manager: Manages your SDK version.
  • DDMS: Dalvik Debug Monitor Service and Dalvik Debug Monitoring Service.

 

3. Import third-party jar packages:

To import a jar package in eclipse, copy the jar package to the project file and add to build path. However, this is not the case in Android studio. How 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 the import, select the jar package and click the button at the arrow in (synchronize: synchronization, which can be understood as refresh)

Done.

 

3. Install genymotion simulator:

1. Install Genymotion:

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

First register and then download. The simplest way to install VirtualBox is to download the Genymotion package containing VirtualBox, as shown in the red box section:

After the download is complete, start the installation. Run the Genymotion software and you will be prompted to create a virtual device. Click "yes" to create a virtual device:

Use the previously registered account for connection:

Then select one of the simulators:

Of course, if you want to run the program on the simulator, make sure that the simulator has loaded the Android SDK:

Note: If the following error occurs when the simulator is started:

Just upgrade the computer graphics card driver.

In this way, our simulator is built and can be started. Next we will associate the simulator with Android Studio.

 

2. Associate the simulator Genymotion with Android Studio:

The Genymotion official website prompts two methods (as shown in): Online installation and offline installation. The method is quite clear, so I won't take screenshots to demonstrate it.

After the plug-in is installed, restart the software to make the new plug-in take effect. After restarting the software Android Studio, select "View -- Toolbar" on the menu bar to display the Toolbar. You can see that Genymotion Device Manager is added to the Toolbar:

Click this icon to bring up the following interface:

Load the previously installed Genymotion folder. Then click the icon to bring up the following interface:

Success.

Then, run the program on the simulator:

The running effect is as follows:

In, we can see that the version I compiled is API 19, but the Simulator version is API 16, but the program can still run. This shows that Android Studio is doing well in terms of version compatibility. However, when IntelliJ IDEA is used, the compiled version must be consistent with that of the simulator.

4. Create a third-party library in the module form: (introduce the concept of module)

Let's take a look at this table:

After reading the figure, you should know the concept of module. Careful friends can find that the application module has a mobile phone icon:

1. Create a module as the library: (take the Library StickyScrollViewItems as an example)

Note: The Role of StickyScrollViewItems is: ScrollView that the child control can hover over (it is fixed to the top when the child control scrolls to the top of the page ).

In AS, we can create a module to use AS the library. The operation is AS follows:

, Create a new module in the current project, and then bring up the following interface:

In, select the module type as Android Library, and then continue:

, Since this module is A libray, no Activity is required.

There are two modules at the arrow in the middle: the first is the module of the application, and the second is the module of the lirary. We can see that their icon is different.

 

2. Copy part of the StickyScrollViewItems-master package downloaded from GitHub to the lirary module:

The procedure is as follows:

(1) copy the attrs. xml file in the StickyScrollViewItems-master \ library \ res \ values directory to the values directory in the module of lirary.

(2) copy the secure-master \ StickyScrollViewItems-master \ library \ src \ com \ emilsjolander \ components \ StickyScrollViewItems directory StickyScrollView. java file to the java directory of the module in lirary.

The final result is as follows:

 

Summary: the common practice of creating a third-party library in the form of a module is:

(1) create a module in the library format and delete all the files in the src/main directory of the module (including deleting java, res, AndroidManifest. xml)

(2) copy the AndroidMainfest. xml, res, and src files from a 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) Delete the dependencies and release modules in the build. gradle file in the library module (Be sure not to modify the wrong part ).

 

3. Dependency the module of the application on the module of the library:

The procedure is as follows:

Right-click the app and select "Open Module Settings". The following page is displayed:

Add "Module dependency" to the Dependencies tab by following the steps below. The following page is displayed:

To import the StickyScrollViewItems module.

The dependency is successful, so we can see the code prompt in the layout file:

Let's test it.

 

4. Test the availability of the module of library:

Modify activity_main.xml to the following code:

 1 <com.smyhvae.stickyscrollview.StickyScrollView 2     android:layout_width="match_parent" 3     android:layout_height="match_parent" 4     android:fadingEdge="none" 5     android:overScrollMode="never" 6     android:fillViewport="true" 7     xmlns:android="http://schemas.android.com/apk/res/android"> 8  9     <LinearLayout10         android:layout_width="match_parent"11         android:layout_height="wrap_content"12         android:orientation="vertical">13 14         <View15             android:layout_width="match_parent"16             android:layout_height="200dp"17             android:background="@color/blue"/>18 19         <View20             android:layout_width="match_parent"21             android:layout_height="100dp"22             android:background="@color/red"23             android:tag="sticky"/>24 25         <View26             android:layout_width="match_parent"27             android:layout_height="100dp"28             android:background="@color/green"/>29         <View30             android:layout_width="match_parent"31             android:layout_height="100dp"32             android:background="@color/white"/>33 34         <View35             android:layout_width="match_parent"36             android:layout_height="300dp"37             android:background="@color/purple"/>38 39         <View40             android:layout_width="match_parent"41             android:layout_height="100dp"42             android:background="@color/yellow"/>43 44     </LinearLayout>45 </com.smyhvae.stickyscrollview.StickyScrollView>

In the code above, we introduced the StickyScrollView module as the library, and the core code is 23rd lines. We added the android: tag = "sticky" label for the red View, so it will have the property of hovering. Then run the program directly.

The entire project file of this section is AS follows: (you can import it to your own AS to see the effect)

Link: http://pan.baidu.com/s/1eQ8epsY

Password: k9i1

 

5. delete a module:

If I want to delete the StickyScrollView module, what should I do? The method is: select the module StickyScrollView and right-click the module. If no delete option is found, it does not matter. We select the "Open module Settings" option in the red box. The following interface is displayed:

Click the minus sign at the arrow to delete it. At the same time, we need to remove the dependency of the app module on it:

Then, the module icon StickyScrollView disappears:

Right-click it and delete it from the hard disk:

 

 

6. Tips for deleting files: (secure deletion)

If you want to delete a file, you can right-click it and delete it, But Android Studio has a more user-friendly experience. For example, when I want to delete a layout file:

Click delete to delete the file. The following page is displayed:

, If you hook the red box and click OK, the software will prompt you where the file is used:

It shows that this file is used in one place. Click "View usages" to View the details:

If you want to delete it, click the arrow in it. What should you do? Is the user experience good?

Why? Not satisfied yet? I will continue to fight tomorrow ~~~

 

Note:

In section 4, I created a module to reference the library StickyScrollViewItems. The download link is also provided at the end of section 4 of the project file. The gradle file code is as follows: (gradle will be mentioned in the next article)

Application build. gradle:

 1 // Top-level build file where you can add configuration options common to all sub-projects/modules. 2  3 buildscript { 4     repositories { 5         jcenter() 6     } 7     dependencies { 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 allprojects {16     repositories {17         jcenter()18     }19 }

 

App build. gradle:

 1 apply plugin: 'com.android.application' 2  3 android { 4     compileSdkVersion 19 5     buildToolsVersion "21.1.1" 6  7     defaultConfig { 8         applicationId "com.smyhvae.helloworld" 9         minSdkVersion 1410         targetSdkVersion 1911         versionCode 112         versionName "1.0"13     }14     buildTypes {15         release {16             minifyEnabled false17             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'18         }19     }20 }21 22 dependencies {23     compile fileTree(dir: 'libs', include: ['*.jar'])24     compile project(':stickyscrollview')25 }

 

Library module build. gradle:

 1 apply plugin: 'com.android.library' 2  3 android { 4     compileSdkVersion 19 5     buildToolsVersion "21.1.1" 6  7     defaultConfig { 8         minSdkVersion 14 9         targetSdkVersion 1910         versionCode 111         versionName "1.0"12     }13     buildTypes {14         release {15             minifyEnabled false16             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'17         }18     }19 }20 21 dependencies {22     compile fileTree(dir: 'libs', include: ['*.jar'])23 }
Source: http://www.cnblogs.com/smyhvae/p/4392611.html

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.