Android Studio: the correct method for importing projects and modules. androidproject

Source: Internet
Author: User

Android Studio: the correct method for importing projects and modules. androidproject
Gradle Project, Module Import


Recently, many people complained on the Internet that it is difficult for Android Studio to import some projects downloaded from github, including:

1. Import Gradle
2. No import


Next I will explain the correct import posture in two parts:

1. Import the complete Github Project

We are looking for a project on github.



The project catalog is shown in the preceding figure. There are two parts in the project catalog: project-related and project-related.

The project is used to configure the compilation environment and dependencies of the entire project. The project is your code and configuration file.


Let's first look at the project. It contains the following folders:



Because Gradle is not yet mature, version updates will be faster. If the project author used Gradle of another version but you didn't have it, AS will download the most matched Gradle by default, but in China, the download speed is extremely slow, and the Gradle file is also quite large, 50 + MB, so we need to modify the configuration first:


Open the gradle folder warpper folder and open the gradle-wrapper.properties

#Wed Apr 10 15:27:10 PDT 2013distributionBase=GRADLE_USER_HOMEdistributionPath=wrapper/distszipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/distsdistributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip

The author uses gradle-1.12-all.zip, and we open this directory C: \ Users \ Administrator \. gradle \ wrapper \ dists \ gradle-2.1-all \ 27drb4udbjf4k88eh2ffdc0n55

We use gradle-2.1-all.zip, and the next gradle-1.12-all.zip is taken as an example. OK, we can modify the configuration:

distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip

Then select


Open exiting: select the Build. gradle file to open the project.

However ----------------------------------------------

This method seems like ---------------------------------------------- on the latest 2.1.

I did not find the specific reason, but I can think that Android Studio and gradle are both beat stuff, and it's not surprising that something goes wrong. I hope they can be OK in the official version in the future.


Next we will use another method:

Let's take a look at what the project we created looks like after compilation:



I have a few more gradle files. Okay. copy the gradle folder related to the project and replace the gradle folder to be imported to the project.

Copy requires these folders:


OK. Next, re-import the Exiting Project and select the Build. gradle file to import the Project.


2. Import a module

If we create a new project, how do we import a module of another project? Just like the project above, we need to import its library

This is actually very simple. We have done so much before, because the project cannot find the correct compilation file, but the module is different. He just uses a Build. the gradle file is used to control the compilation rules of this module. Therefore, we only need to import the module. The compilation configuration of the project is also the configuration of our own project, but you need to pay attention to it during import, here, we need to select the module Directory instead of the Build directory. gradle file.


OK. Select import to add the module.


In the final analysis, the gradle compilation method is a bit similar to the Android Makefile method. In this way, the larger the project, the more obvious the advantage, but in our daily small app development, it seems a little bloated, and the compilation time is too long !!! I hope the official version can be improved and Google can do it.


The failure to import a project is caused by the fact that you are not familiar with the Gradle syntax and compiling environment. Therefore, it is very important to learn things and understand the principles, especially for something that has just begun to become popular, where there are so many ready-made things that can be used for your reference, you can only rely on yourself to Read The F ** king Source Code.


Above.



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.