Android 12: Android Studio imports third-party class libraries, jar packages, and so libraries

Source: Internet
Author: User

Third-party class library source code

The XMPP code of a netizen from ADT to as, found that it used a third-party class library, source code in the Lib, directly in as in the import project, the third-party class library is not automatically imported into, it seems to need to do their own hands.

The directory structure of the project is as follows:

XMPP$ lsapp    build.gradle  gradlew      import-summary.txt  XMPP.imlbuild  gradle        gradlew.bat  local.properties settings.gradle
    • 1
    • 2
    • 3
    • 1
    • 2
    • 3

Copy the third-party source qqemoji-lib to this directory, modify the Settings.gradle to add this lib:

include ‘:app‘,‘:qqEmoji-lib‘
    • 1
    • 1

Modify the Build.gradle under the app to add in dependencies:

dependencies {    compile project(‘:qqEmoji-lib‘)    ...
    • 1
    • 2
    • 3
    • 1
    • 2
    • 3

Create a new Build.gradle file under Qqemoji-lib, with the following reference:

Apply plugin:   ' android-library ' Android {compilesdkversion 19 buildtoolsversion" 21.1.2 "DefaultConfig { Minsdkversion 8 targetsdkversion 18} sourceSets {main {manifest.srcfile  ' androidmanifest.xml ' java.srcdirs = [ ' src '] resources.srcdirs = [ ' src '] aidl.srcdirs = [ ' src '] renderscript.srcdirs = [ ' src '] res.srcdirs = [ ' res ']}}} Dependencies {compile  com.android.support:appcompat-v7:19.1.0 '//compile  ' com.android.support:support-v4:19.1.0 '}     
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21st
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21st
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

The configuration content of Gradle is referred to the last second link.

At this point the structure of the project is shown:

At this point compile, pass, import success!

Third-party class library jar packages

This is much simpler, just copy the jar package to app/libs and add the jar dependency in the Build.gradle under the app. As follows:

dependencies {    ‘com.android.support:support-v4:19.1.0‘    compile files(‘libs/libammsdk.jar‘)    compile files(‘libs/universal-image-loader-1.8.6-with-sources.jar‘) compile files(‘libs/YoumiSdk_v5.00_2015-01-08.jar‘)}
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
Third party so library

In general, we do not need extra work to call a third-party so library, just put it in the specified directory and load it in the Java file.
For example, I quoted the previous "first NDK program" compiled in the libfirstlib.so, put it under the app/src/main/jnilibs/armeabi/, in the source of reference:

    static {      System.loadLibrary("FirstLib");     }  
    • 1
    • 2
    • 3
    • 1
    • 2
    • 3

Can. Programs Run as:

Reference:
Http://www.cnblogs.com/neozhu/p/3458759.html
Http://www.open-open.com/lib/view/open1415793464648.html

Android 12: Android Studio imports third-party class libraries, jar packages, and so libraries

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.