Current location - Health Preservation Learning Network - Healthy weight loss - How to modify and add custom java classes and so libraries, as well as android when packaging Android?
How to modify and add custom java classes and so libraries, as well as android when packaging Android?
Question description: How does Android call the third-party SO library? Known conditions: the SO library is an Android version connection library (*. So file) and provides a detailed interface description; Understand the solution: 1. Put the SO file directly under libs/armeabi, and then the system. Loadlibrary ("XXX") in the code; Then public native static int XXX _ XXX _ XXX (); Then you can directly call the xxx_xxx_xxx () method; 2. The second scheme is to create your own SO file, call the third-party SO in your own SO file, and then call your own SO in the program. This is complicated, you need to build a java class file and generate a. H file, write. The c source file generated before the h file is include, and the corresponding method is implemented. Finally, the ndk-build script in the android NDK development package is used to generate the corresponding. So * * share the library; Solution: 1 Are the above two schemes feasible? What's the problem if it's not feasible? 2. What's the difference between these two schemes? Why do most people on the Internet use the second option? 3. There is only one *. So file, and provides a detailed interface description. Can it be used on Android? First, it depends on whether this SO is a JNI standard SO, for example, whether it returns a type that JNI does not directly support. In other words, can this be directly called JNI? If the answer is no, you can only choose the second plan. If the answer is yes, it depends on whether you want this SO library to be directly exposed to the JAVA layer. If the answer is no, you can only choose the second option, for example, you are also a library provider. Generally, if you only have SO, it means that someone else provided it to you, and you can ask the other party to provide you with a matching JAVA call file. 1, it depends on whether this conforms to the specification of JNI call. It's up to you. 2. Because the second method is the most flexible, all kinds of situations can be realized. 3. The easiest way to see if you can call directly from JAVA is to see if the function name in SO is in JAVA_XXX_XXX_XXX format. You can write a supported JAVA file yourself, pay attention to the conversion rules between SO function names and Java function names, or ask the SO provider for it. If not, choose the second scheme. 1. Check whether the required documents are complete. To use a third-party dynamic library, there must be at least two files, one is a dynamic library (. The other is the header file containing the API declaration of the dynamic library. h)。 2. Encapsulating the original dynamic library The original dynamic library file does not contain the information needed by jni interface, so we need to encapsulate it. So our requirement is to encapsulate the API in libadd.so into a dynamic with jni interface. 3. Write the encapsulation function libaddjni.c. According to the previously generated COM _ Android _ libjni _ libjavaheader.h file, write libaddjni.c to generate the integrated third-party software package (. Can,. So) there may be third-party software packages used by Android in libaddjni.soAndroid, including Java packages. Jars and local packages. So ... Jar packages can be integrated through the Eclipse development environment or compiled source code, depending on your working environment. Assuming my own program is MyMaps, I need to use BaiduMaps libraries, including baidumapapi.jar and libbmapappingine _ v1_ 3 _1.so.1. By integrating third-party jar packages and creating directories libs and libs/armeabi. Therefore, in MyMaps project, the dynamic library in Eclipse, baidumapapi.jar is placed in libs/ directory, and libbmapappingine _ v1_ 3 _1.so is placed in libs/armeabi/. To package the third-party jar package baidumapapi.jar into MyMaps in Eclipse: 1. Right-click the project and select Properties; ; 2.Java builds the path and selects the library; ; 3. Right-click "Add Library …" on the library page; 4. Select "User Library" and click "Next"; 5. Click the User Library button; 6. In the pop-up interface, click "New …"; 7. Enter "User Library Name" and click "OK" to confirm; 8. After returning, select the newly created user library and click "Add Jars" on the right; 9. Select baidumapapi.jar under MyMaps/libs/; 10. Return after confirmation. In this way, the compiled jar package will be typed as MyMaps.apk, and libbmapappingine _ v1_ 3 _1.so will also be packaged in lib/armeabi/. During the program running, libbmapapigine _ v1_ 3 _1.