Introduction:

This problem involves NDK development in Android or JNI development in JAVA and the production of the corresponding. So library; For developers who do not have an NDK or JNI development operation, the following explanation may be difficult to understand

About the NDK development refer to: blog.csdn.net/ezconn/arti…

Note: NDK is Android and not directly related to Java

To:

1), the above problems are actually used in other projects after Android NDK development and generation of. So library; In order to use the. So library directly, you must define the corresponding native methods in the project that uses the. So library. Because. So library C or C++ functions and Java native methods correspond one to one, calling a local method is equivalent to calling a. So library function, local methods are only declared empty methods, specific logic is generally implemented in. So library C or C++ functions;

2), C or C++ function definition rules:

A, format = Java package name_class name_java method name (native Java method name) b,Java initials must be uppercase C, for package names, in package names. To change; _ is going to be _1

C or C++ functions are defined by the name of the package in which the class containing the Java native methods resides. But C or C++ functions, Google has done, that is, the function format has been determined, so the upper application needs to create a specified package name and copy the defined local can be called;

  1. Functions in the.so library can be called only by Java native methods that generate the corresponding. So

4), so if you use Google open source project for SerialPort development in your own project, you need to create the package name of android_serialport_api in your own project and paste SerialPort and SerialPortFinder classes in the package name; Take a look at the SerialPort class, which contains native methods that are used to call C or C++ functions in the. So library

    

Conclusion:

The above are based on already written or implemented C++ or C functions, create Java native methods flow; In fact, you can also change the package name of the implemented C or C++ function, so that you do not need to write android_serialport_API; But there are a lot of problems to pay attention to, I won’t go into specifics;