Methods and issues for integrating third-party libraries in Android

Source: Internet
Author: User

Methods and issues for integrating third-party libraries in Android


Statement:

1. This article refers to the online students of the existing results, here to express appreciation, reference materials in the post have links.

2. This article focuses on the third part, is in the development of problems and solutions. First, the second part is a reference to the results of the online students to be collated.

3. Welcome reprint, Exchange, please respect the author's labor results; reprint please indicate the source, thank you!



Android There are two possible ways to use third-party libraries in Java libraries. jar and native library. SO/.A, if you are just doing the top APK development, both libraries can be integrated through the Eclipse integrated development environment, and if it is platform-level development, it can be integrated through the source code. This article organizes the use of these two integration methods, the following assumption of the program Scanerapp, integrated Java library Scanerjar.jar, the native library libscanerbase.so/libscanerbase.a,libscanerplus.so/ Libscanerplus. Among them, so library to refer to the Android Reference library specifications to write, internal function naming should also be standardized (although not specification may also be used),. A library is static-linked, and is typically used for C/


first, Eclipse integration
1, Scanerjar.jar package integration

A. Create libs directory under current project Scanerapp

B. Import Scanerjar.jar packages with Eclipse

2, libscanerbase.so and libscanerplus.so integration

A. Create Libs/armeabi directory under current project Scanerapp

B. Copy the libscanerbase.so and Libscanerplus library files to the Libs/armeabi directory. Because the libscanerbase.so and libscanerplus.so libraries are native repositories, it is common to do dynamic libraries that are loaded at run time.

C.java file Reference Loading library

The resulting apk will automatically pack Libscanerjar.jar and libscanerbase.so and libscanerplus.so files in.


Second, the source code integration

There are at least two ways to integrate the source code into a third-party library: The Prebuild-C + + link and the Android approach, which of course don't seem to integrate libscanerjar.jar packages. C + + mode

1. The link method of C + +

static libraries and dynamic libraries are generally placed in the Libs/armeabi directory, if the library file is more, you can also separate directory storage, as long as the corresponding modification of the library file path (search path).

Modify the Android.mk file, sample link libscanerbase.a Static library:

Local_ldflags: = $ (Local_path)/libs/armeabi/libbase.a

2. Android prebuild mode 1) Libscanerbase.jar Package Integration

A. Create the Libs directory under Packages/app/scanerapp , assuming the package is placed under Packages/app.

B. Copy the Scanerbase.jar package to this directory

C. Modify the Android.mk file with the following example:

Include $ (clear_vars) Local_static_java_libraries: = scanerjarlocal_prebuilt_static_java_libraries: =scanerjar:libs /libscaner.jarinclude $ (build_multi_prebuilt)


which

local_static_java_libraries to refer to the Jar library alias, can be arbitrarily named, the general is to use the library name on it.

local_prebuilt_static_java_libraries to specify the prebuilt Java Library rule, the format is: alias: The full path to the jar file, where the alias is the name of the local_static_java_libraries.

when the source code is developed, SCANERAPP.APK will be packaged together with Libscaner.jar and placed in the out/target/product/<prjname>/system/app/directory;

2) libscanerbase.so and libscanerplus.so integration

A. Create a Libs/armeabi directory under packages/app/scanerapp

B. Copy the . so library to the Libs/armeabi directory

C. To Modify the android.mk configuration file, add the following:

Include $ (clear_vars) Local_static_libraries: = libscanersolocal_prebuilt_libs: = libscanerso:libs/armeabi/ Libscanerbase.so Libs/armeabi/libscanerplus.soinclude $ (build_multi_prebuilt)


which

Local_prebuilt_libs Specify the prebuilt so library rule, format: alias: So file path.

source Development, this libscanerbase.so will be placed under the out/target/product/<prjname>/system/lib/, which system/ LIB is the default search path when loading a dynamic library.

In addition, libscanerbase.so can also be integrated into the BUILD/CORE/USER_TAGS.MK, but it is generally not recommended, we should minimize the modification of system-level configuration.

3) source code integration compilation

Mmm/packages/apps/scanerapp

The above instructions are used on Spreadtrum's Android platform, and other platforms may be different.


third, the problem prone points and solutions
1. Integrated library file to eclipse project

When you add a library file to an Eclipse project, be sure to add the location of the library, not misplaced it, or it cannot be used normally. The jar package is placed in the libs/directory, so library files must be placed in the Libs/armeabi directory.

2. Integrated library files into the source code

In the source integration environment (our platform is Spreadtrum platform), other platforms can refer to


(1) in the application directory (Scanerapp) Under the Android.mk file, when referencing multiple libraries, the library file alias can not be declared, but if the alias is declared, you must pay attention to the problem: after the alias to write all the referenced libraries, and an alias after adding all the libraries to be referenced.

For example:

Should be written in the following format:

Include $ (clear_vars) Local_static_java_libraries: = scanerjarlocal_prebuilt_static_java_libraries: =scanerjar:libs /libscaner.jar Libs/libscanerplus.jar #问题点include $ (build_multi_prebuilt) include $ (clear_vars) local_static_ LIBRARIES: = libscanersolocal_prebuilt_libs: = libscanerso:libs/armeabi/libscanerbase.so libs/armeabi/ Libscanerplus.so #问题点include $ (build_multi_prebuilt)


Instead of being written in the following format:

Include $ (clear_vars) Local_static_java_libraries: = scanerjarlocal_prebuilt_static_java_libraries: =scanerjar:libs /libscaner.jar Scanerjar:libs/libscanerplus.jar #注意问题点include $ (build_multi_prebuilt) include $ (clear_vars) LOCAL_ Static_libraries: = libscanersolocal_prebuilt_libs: = libscanerso:libs/armeabi/libscanerbase.so libscanerso:libs/ Armeabi/libscanerplus.so #注意问题点include $ (build_multi_prebuilt)


(2) in the case of using JNI code in the application package , in the package JNI directory (SCANERAPP/JNI) ANDROID.MK, refer to the following declaration method:

Include $ (clear_vars) local_module    : = libscanerjnilocal_src_files: = scaner.cpplocal_ldlibs    : =-lloglocal_ Module_tags: = Optionalinclude $ (build_shared_library)


among them, Local_module will be used by the application, local_module_tags must declare, or compile will be error, can not be compiled.

Be sure to declare local_jni_shared_libraries in the Android.mk file in the application (Scanerapp) directory, as shown in the following example:

Local_jni_shared_libraries: = libscanerjnilocal_proguard_enabled: = disabled

where Libscanerjni is the JNI module declared in the Android.mk file in the application (scanerapp/jni) directory.

If you apply a package that prompts for Proguard errors at compile time , set local_proguard_enabled to Disabled;


(3) according to the rules to correctly write the Android.mk file, the use of MMM alone compiled Scanerapp can also be compiled through the normal, can see the prompt has been used to copy so library files to out/.../system/libs directory. But when the whole project was fully compiled, we found that the Out/.../system/libs directory did not have the. So library file. In this case, you can do the following, (Spreadtrum platform can be copied, other platforms can be consulted, the idea is the same)

First: Copy the so file to be referenced in the Project/vendor/sprd/proprietaries/<projectname>/system/lib directory

Second: Open project/device/sprd/<prjecetname>/proprietaries.mk

Add the so library file asking for reference to the Propmods key.

Third: Make–j4 Compile the project


Finish

---------------------------

References:

http://blog.csdn.net/thl789/article/details/7918093

Http://www.zzqhost.com/?post=14

Http://www.metsky.com/archives/635.html


----------------------------------

Welcome to browse and technical ExchangePlease respect the fruits of laborReprint Please indicate the source, thank you! http://blog.csdn.net/netwalk/article/details/24737241


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.