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

后端 未结 1 2109
走了就别回头了
走了就别回头了 2021-02-20 13:45

I have some problems with my Native Activity application. It works fine on 99% of devices. But sometimes users get the following error:

java.lang.RuntimeExceptio         


        
1条回答
  •  -上瘾入骨i
    2021-02-20 14:24

    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.

    0 讨论(0)
提交回复
热议问题