How to import third-party jar packages (including android system programs) to android programs)

Source: Internet
Author: User

[Javascript]


1. android general application developers

What we saw most on the internet is Add jars, Add External Jars or Add Library in Java Build Path. In fact, these are just to ensure that compilation is normal.

Only after you have tried it can you find out that the corresponding third-party jar package cannot be found during running.

For example, if you want to import jar packages of org.apache.commons.net (implementation of various protocol stacks) to your program

First, you must check your ADT version.

Before ADT17, you need to create the lib directory under the root directory, put the jar package under lib, and right-click add to build path

After ADT17, it will be more intelligent. You only need to create the libs directory in the root directory and put it into the jar package. It will automatically generate Android Dependencies

Do not forget to right-click the project and choose android tools> Fix project properties.

Success or failure depends on whether Android Dependencies are generated in Libraries of Java Build Path (the jar package you depend on can be seen in it)

 


2. android system application developers

You need to modify the android. mk file of your app.


[Javascript]
LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
 
LOCAL_MODULE_TAGS: = optional
<SPAN style = "COLOR: # ff0000"> LOCAL_STATIC_JAVA_LIBRARIES: = apache-net </SPAN>
 
LOCAL_SRC_FILES: = $ (call all-subdir-java-files)
 
LOCAL_PACKAGE_NAME: = xxx
 
LOCAL_CERTIFICATE: = platform
 
Include $ (BUILD_PACKAGE)
<SPAN style = "COLOR: # ff0000 "> #################################### ##############
Include $ (CLEAR_VARS)
 
 
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES: = apache-net: lib/commons-net-3.2.jar
Include $ (BUILD_MULTI_PREBUILT) </SPAN>

LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)

LOCAL_MODULE_TAGS: = optional
LOCAL_STATIC_JAVA_LIBRARIES: = apache-net

LOCAL_SRC_FILES: = $ (call all-subdir-java-files)

LOCAL_PACKAGE_NAME: = xxx

LOCAL_CERTIFICATE: = platform

Include $ (BUILD_PACKAGE)
######################################## ##########
Include $ (CLEAR_VARS)


LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES: = apache-net: lib/commons-net-3.2.jar
Include $ (BUILD_MULTI_PREBUILT)

 

The red font indicates the part you want to add. LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES only compiles the third-party jar package under the lib directory into the static jar java library and rename it to apache-net.

This is why LOCAL_STATIC_JAVA_LIBRARIES is equal to apache-net.

Run the command after modifying mm.

 

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.