1 So loading process
So the process of loading can refer to the article of Xiaomi's system engineer LoadLibrary Dynamic Library loading process analysis
2 Problem Analysis 2.1 issues
Years ago the project added a so library, but found that the native method can not find a crash lot of, better is reported java.lang.unsatisfiedlinkerror native method not found , and basically appear in the 4.x system, especially the 4.4,4.2 system. Search the web for related causes that may cause this problem:
- So files are not found in the corresponding schema directory;
-
There is an error in the method name;
2.2 Analysis 1
We initially suspected that the application did not properly extract the corresponding files to the corresponding directory at the time of installation so , so the corresponding statistics were added to see if the corresponding crash files were not found so , but the statistics found that the corresponding files could be found in these phones. so Therefore, the elimination of non so -existence of files caused crash ;
2.3 Analysis 2
Our colleague used to find out in the Android 4.x system, if the so file is loaded at the time of application startup, but the timing is at a later point, the so memory loaded into the phone may be recycled by the system due to resource constraints, which can be reloaded once so File to reduce the correlation crash , this method fix is related to a very high amount of so crash . But our so crash obvious is not in this case, because we are System.load() after loading the file through the method, so then call the relevant method, then the memory is definitely still there. After analyzing a range of possible causes, it is suspected that the crash files extracted from the application installation so are corrupted, so we try to place this in the first time this occurs, crash crash catch and then in the catch block will be the original directory soDelete the file and re-extract the corresponding file from the app's installation directory so to the original directory, and add the relevant statistics to verify it. soloaded with the Relinkder. The associated simplified version code is as follows:
Relinker.loadLibrary(Getapplicationcontext(),"So_name");Try{//Call native method}Catch(Unsatisfiedlinkerror e) {//some StatsString Library ="So_name"; String libname = System.Maplibraryname(library); File Workaroundlibdir =Getapplicationcontext().Getdir("Lib", Context.mode_private); File Workaroundlibfile =NewFile (Workaroundlibdir, libname); Workaroundlibfile.Delete(); Apklibraryinstaller.installlibrary(Getapplicationcontext() ,Supportedabis(), Libname, Workaroundlibfile, relink ER); System.Load(Workaroundlibfile.GetAbsolutePath());//call Native Method //Some stats}
2.4 Analysis 3
After using the 2.3 solution, most of our so java.lang.unsatisfiedlinkerror native method not found disappears. In theory, once the file is re so -decompressed, this user should not have similar before the next upgrade crash , but our statistics found that some users need to enter the block every time to catch avoid crash , and each time can be through reload To use our application normally, this is still a mystery, and we have no idea what the situation is causing the problem. Have a problem with your phone's storage? But the others so do not have the problem. Hope that if there are peers to solve similar problems, pointing out.
3 Summary
After the Android 4.X system loaded So, the reason for the appearance in addition to the internet said that there is java.lang.unsatisfiedlinkerror native method not found crash no problem with this so and the method name (commercial applications should not have this problem), there are two reasons:
- So loaded into the system of memory by the system due to the shortage of resources to recover, in this case directly after the
load so file can be solved most;
- So file has a problem, in this case, you can solve the majority by re-extracting the corresponding files from the application installation directory
so and reloading them;
These two methods are not guaranteed to solve the problem 100%, but can reduce the majority of the problem (90%);
Reason analysis for Android 4.X system loading so failure