Android Studio Learning----importing jar packages via Gradle

Source: Internet
Author: User
Tags jcenter

Reprint Address: http://www.th7.cn/Program/Android/201507/495477.shtml

File->project Structure can open the following diagram:

1. Configure third-party jar packages via Gradle

We see that each module has a build.gradle file, which is actually a configuration file corresponding to the module. We will explain in the last paragraph about the meaning of the specific content in the Build.gradle file.

Let's take a look at this module named app, whose build.gradle corresponds to the graphical interface of the following project Stucture:

, switch to the Dependencies tab, as shown in:

, click Add, and then select "Library dependency" to bring up the following screen:

, we enter "Gson" in the search box and then make sure that we have the jar package that we need at the arrow, and add it:

We will then find that the Build.gradle of the app module has a line of code that introduces the Gson.jar:

In fact, if you can remember to live above this line of code, write the code directly can also be imported.

At this point, Gson this jar package no longer appears in the Libs folder, but appears in the bottom external libraries, as shown in: (and the latest version OH)

2, Gradle Import Jar Package Features: (and Libs folder import jar package difference)

    • Gradle Importing jar packages is more convenient, one line of code can be done. Not like the latter, you have to go to the official download.
    • If the official will update the jar package, we only need to change the version number in Build.gradle, do not have to re-download the official website.

3. Where does the jar package imported through Gradle come from:

It is important to note that not all jar packages can be imported through Gradle. Where does the jar package imported through Gradle come from? The explanations are as follows:

We found HelloWorld This project directory has a build.gradle file that opens it:

The "Jcenter ()" In line 17th means that all jar packages imported through Gradle are stripped from the central warehouse of Http://bintray.com/bintray/jcenter. If the jar package you need is not on this website, then you can't import it by Gradle.

By the way, the Gradle 1.1.0 in Classpath in line 8th is a Gradle plugin for Android (also stripped from the central warehouse). And we use the Gradle version as shown:

The path to our own downloaded Gradle is as follows:

Android Studio Learning----importing jar packages via Gradle

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.