Android Studio imports third-party class libraries.

Source: Internet
Author: User

Android Studio imports third-party class libraries.

1. Import the *. jar package

1. Direct copy

① Copy the *. jar package and paste it to the libs under the main project directory.

② Right-click and set the jar package to your own library

③ Right-click the project, select the project, and click Open Module Settings. In Dependencies, select Add file.

In this way, the jar package is successfully added.

Open build. gradle in the app directory

Indicates that the add operation is successful.

2. Add a sentence in build. gradle:

compile fileTree(include: ['*.jar'], dir: 'libs')

 

After writing this sentence, copy and paste the jab package to the libs directory and add the as library automatically.

 

Ii. Import third-party java class libraries with source code packages

1. decompress the library downloaded from github, and copy all the folders in the library to the bottom of the project (similar to the main project app, which can be copied to files or projects)

 

2. Add settigs. gradle in the project root directory: include ': app',': viewpagerindicatorlibrary'

3. Add: compile project (': viewpagerindicatorlibrary') to dependencies of app/build. gradle ')

4. open the open Module Settings and check that viewpagerindicatorlibrary has been added.

If you click Try again, an error will be reported during compilation...

5. Edit the compilation report: you must add a build. gradle file under the viewpagerindicatorlibrary directory.

Apply plugin: 'com. android. application'

Android {
CompileSdkVersion 24
BuildToolsVersion "24.0.0"

DefaultConfig {
MinSdkVersion 14
TargetSdkVersion 24
}
BuildTypes {
Release {
MinifyEnabled false
ProguardFiles getDefaultProguardFile('proguard-android.txt '), 'proguard-rules. Pro'
}
}
}

Dependencies {
Compile 'com. android. support: support-v4: 18. +'
}

It is similar to the main app/build. gradle, that is, defaultConfig only keeps two Version versions and only adds dependencies to its own dependencies.

Compile 'com. android. support: support-v4: 18. + ', libs on
compile fileTree(include: ['*.jar'], dir: 'libs')。

After compilation, an error may occur. You need to modify the AndroidManifest. xml file in the viewpagerindicatorlibrary Directory, which may conflict with the file in your project or cause syntax errors due to a large version span.

Iii. Introduction of aar

1. A separate project depends on its own library. You can run your project and find the. aar file in the project directory.

 

2. paste the. aar file to the libs directory of your project.

3. Modify the app/build. grdle configuration file

Add: repositories flatDir {dirs 'libs '}}

Add a local repository and use the libs directory as the repository address.

Add a row to dependencies:

compile(name:'pullrefreshlibrary', ext:'aar')

4. recompile the project:

Select "Build" --> "rebuild project" from the toolbar"

5. After compilationApp/build/intermediates/exploded-aar/ A can see the referenced aar Package content, where the jar directory is the jar file, and the res is the resource file in our aar package.

 

You can use it.


 

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.