“Unable to find native library” error in Native Activity app

橙三吉。 提交于 2019-12-04 02:11:44

You will need to read the logcat output to see what happened prior to the crash, which prevented the native library from loading. I use Acra for my apps (generates crash reports containing logcat output), but as a quick solution to get the logcat output without implementing a whole crash reporting system, you could use something like this in a test build, and have the user run it:

try
{
    Process process = Runtime.getRuntime().exec( "logcat -d" );
    BufferedReader bufferedReader = new BufferedReader(
        new InputStreamReader( process.getInputStream() ) );
    StringBuilder log = new StringBuilder();
    String line = "";
    while( ( line = bufferedReader.readLine() ) != null ) {
        log.append( line );
    }
    // Output available via log.toString().. do whatever with it
} 
catch( IOException e ) {}

If you look at the source code for NativeActivty, this exception you are seeing gets thrown in the onCreate() method (see line 171), so if you override that method in a derived class of NativeActivity, you can catch it and grab the logcat output from there. Then you could save the log to a file and have a user with an affected device run the test and email the file to you, for example.

Another good thing about overriding onCreate(), is it will also allow you to reproduce some of what goes on behind the scenes, with more debug logging to help you track down the problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!