Android uses third-party jar packages

Source: Internet
Author: User

From: http://www.cnblogs.com/bmate/archive/2012/09/07/2674432.html

 

Use third-party jar packages

Apart from the methods described below, I have basically tried other methods and may encounter compilation or running errors. The following methods have been tested for compilation and running.

Steps:

Method 1: In eclipse,

Right-click the project,
Build path,
Java build path, select Libraries
Click "add library" in the button on the right"
Select "User library" and click "Next"
Click "User librarys ".
On the displayed page, click "new ...".
In the pop-up interface, enter a name and click "OK"
Click "add jars" to select a third-party jar package and click "OK.
The subsequent steps are very important if you do not perform subsequent operations. There will be no errors when compilation is passed in eclipse, but errors such as Java. Lang. noclassdeffounderror may occur when running on a simulator or a real machine:
1. Create a libs folder under the root directory of the android project;
2. Copy the required third-party jar package to this directory;

3. Right-click the libs directory and choose bulid path-> use as source folder.

Method 2: In the android source code environment,

1. Put the classess. jar file in out/target/common/obj/java_libraries/powersave_intermediates in your project directory. The jar package in the out/target/product/Ventana/system/framework directory cannot be verified by using the following methods, because it has been converted into a DEX file, it is not acceptable to reference its package in the project;

2. Modify the Android. mk file as follows:

Local_path: = $ (call my-DIR)
Include $ (clear_vars)

Local_module_tags: = optional

Local_src_files: = $ (call all-Java-files-under, Src)

Local_static_java_libraries: = libpowerjar libpowersave

Local_package_name: = testpowerjar

Local_certificate: = Platform

Include $ (build_package)
######################################## ######
Include $ (clear_vars)

Local_prebuilt_static_java_libraries: = libpowerjar: classes. Jar libpowersave: testlily. Jar
Include $ (build_multi_prebuilt)

# Use the folloing include to make our test APK.
Include $ (call all-makefiles-under, $ (local_path ))

 

Explanation: local_static_java_libraries: = libpowerjar and local_prebuilt_static_java_libraries: = libpowerjar: classes. jar actually libarity is a name that can be obtained at will. The values of the two attributes should be the same, but you must write your jar package name in the colon, your jar package must be placed in the root directory of the project. Here is an example of using two jar packages.

3. Compile the package in the source code Directory: # Mmm package/APP/testpowerjar. If an error occurs and the package cannot be found, # touchclasses. jar.

 

Generate a jar package:

Method 1: In eclipse,
1. Create a Java or android project;
2. Add Android. jar to Java build path> libraries.
3. In package explorer, right-click the project and choose export Java-> JAR file.

Method 2: In the android source code Environment

1. Modify the Android. mk file,

Local_path: = $ (call my-DIR)
# The Library
#===================================================== ==================================
Include $ (clear_vars)

Local_module_tags: = optional

Local_src_files: = powersave. Java

Local_module: = powersave

Include $ (build_java_library)

# Additionally, build unit tests in a separate. APK
Include $ (call all-makefiles-under, $ (local_path ))

2. Compile # Mmm powersave (your own module)

Build_java_library indicates that the jar package is generated. The package is stored in out/target/product/Ventana/system/framework and out/target/common/obj/java_libraries/powersave_intermediates (your own module) lower

 

 

 

How to Use third-party jar for Android mk

Blog type:

  • Android
 

Local_path: = $ (call my-DIR)
Include $ (clear_vars)

Local_module_tags: = optional

Local_static_java_libraries: = robotimu-solo

Local_src_files: = $ (call all-Java-files-under, Src)

Local_sdk_version: = Current

Local_package_name: = Calculator

Include $ (build_package)
######################################## ##########
Include $ (clear_vars)

Local_prebuilt_static_java_libraries: =Robobench-solo: Lib/robotium-solo-2.3.jar
Include $ (build_multi_prebuilt)

# Use the folloing include to make our test APK.
Include $ (call all-makefiles-under, $ (local_path ))

Pay attention to the three lines in red.
TheRobotium-solo-2.3.jar Is a third-party jar package.

 

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.