The correct way for Android studio to import project and module

Source: Internet
Author: User

Gradle project projects, module modules import


Recently seen many people on the internet complaining that Android studio is difficult to import some of the items that are downloaded from GitHub, mainly including:

1, the import is in download Gradle
2, the fundamental lead not in


Let me explain the correct import posture in 2 parts:

1. Import the full GitHub Project

We're looking for a project on GitHub.



Project catalog as above, the inside of the stuff is actually divided into 2 parts, engineering-related and project-related

Engineering-related build environment and dependencies for configuring the entire project, project-related is your code and configuration file.


Let's take a look at project-related, which contains several folders:



Because now Gradle is not too mature, so the version of the update will be faster, if the project author is using a different version of the Gradle, and you do not, as is good default to download the most matching gradle, but in the country, this download is extremely slow, and Gradle file is also very big 50 +MB, so we need to modify the following configuration first:


Open the Gradle folder Warpper folder, open gradle-wrapper.properties

#Wed APR 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

Can see the last line, the author uses gradle-1.12-all.zip, and we, we open such a directory C:\Users\Administrator\.gradle\wrapper\dists\gradle-2.1-all\ 27drb4udbjf4k88eh2ffdc0n55

We are using gradle-2.1-all.zip, so as is idiot to the next gradle-1.12-all.zip, OK we modify the configuration to read:

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

And then select


Open exiting, select our Build.gradle file and you can start your project.

But ——————————————————————————————————————————————

It's like ———————————————————————————————————— on the latest 2.1.

The specific reason I did not find, but can think of Android studio and Gradle 2 are beat in the things, not surprising, I hope the official version will be OK


Here we use another method, counter switch:

Let's take a look at what our own created projects look like when they are compiled:



A few more gradle files ha, OK, we copy the project-related Gradle folder, replace the Gradle folder to import the project

Copy requires these folders:


OK, then re-import exiting project and select the Build.gradle file to import project.


2. Import a module

If we create a new project, we need to import a module of other projects, like the one above us, need to import his library.

This is actually very simple, we are in front of so many, all because the project can not find the correct compilation file, but the module is not the same, He just used a build.gradle file to control the module's compilation rules, so we just import it, the project's compile configuration or our own project configuration, just import the time need to pay attention to, here we need to choose Module directory, instead of choosing build.gradle Piece of it.


OK, select Import, you can complete the module added.


In the final analysis, Gradle's compilation and Android makefile is a bit similar, such a way, the bigger the project, the more obvious advantages, but in our usual small app development, does seem a bit bloated, compile time is too long!!! I hope the official version will improve, I believe Google can do it.


For the inability to import the project, in the final analysis of the Gradle Grammar and the compilation environment is not familiar with the cause, so that, learn things, make clear the principle is very important Ah, especially like this just beginning to popularize things, where so many ready-made things can let you learn from, only on their own, Read the f**king Source Code.


Above.



The correct way for Android studio to import project and module

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.