In the development process, third-party libraries are often used, such as maps, videos, document edits, charts, and so on. Depending on these libraries, you need to add their SDK, sometimes using the JNI layer of so files, such as Baidu map.
So the question is, what if there is a conflict between the so files of two different libraries?
For example: Add a library of maps separately, run no problem. Add a single video library and run without problems. But both are added, and one of the libraries errors when init. This certainly has a lot to do with the level of development of third-party libraries, but how do we solve this problem? This uses the method of dynamic loading.
This is the original static loading method, all dependent libraries of so files all a brain into the Armeabi folder.
Dynamically loaded methods, I put conflicting so files in the assets folder
It is important to note that dynamically loaded so files can only be placed in two places: 1. Lib folder, which corresponds to the Jnilibs folder in Android Studio. 2. Local data/data/package Data directory. Therefore, when the application first launches, we must put in the assets folder in the so file copy milk Local data directory.
Of course, the above method is to put so files in the program's assets folder. Alternatively, it can be downloaded from the network and placed in the local data directory. The advantage is that it not only reduces the size of the APK, but also makes it possible to use the latest dependent libraries at any time, which is one of the most useful applications for dynamic loading.
Dynamically Loading so files