Android 6 marshmallow crashes when Java calls the native library

My application uses the native library, and there is no problem from Android 2.2 to 5.1

However, on Android 6, the marshmallow application crashed due to an error: e / androidruntime (1602): java.lang.unsatisfiedlinkerror: no implementation was found for int com.ipc.sdk.fsapi.init() (try java_com_ipc_sdk_fsapi_init and java_com_ipc_sdk_fsapi. Sdk.fsapi.init (native method)

How to solve the crash?

Update fsapi.java

   package com.ipc.sdk;
   public class FSApi 
   {
   ...  
   public static native int Init();
   ...
   static {
    try{
        System.loadLibrary("IOTCAPIs"); 
    }catch(UnsatisfiedLinkError ule)
    {
    }
    try{
        System.loadLibrary("RDTAPIs"); 
    }catch(UnsatisfiedLinkError ule){
    }
    try{
        System.loadLibrary("iconv");
        System.loadLibrary("FSApi"); 
    }catch(UnsatisfiedLinkError ule){
    }
   }
   }

In mainactivity, I call:

FSApi.Init();

If I have a comment, please call:

// FSApi.Init();

No crash. This means that the native library was loaded successfully. In addition, I got an error in logcat:

No implementation found for int com.ipc.sdk.FSApi.Init() (tried Java_com_ipc_sdk_FSApi_Init and Java_com_ipc_sdk_FSApi_Init__) at com.ipc.sdk.FSApi.Init(Native Method)

It looks like marshmallow is trying to find Java in the library_ com_ ipc_ sdk_ FSApi_ Init or Java_ com_ ipc_ sdk_ FSApi_ Init__, However, if I open. So in a text editor, I will find Java_ com_ ipc_ sdk_ FSApi_ Init!

Only two conditions can cause problems at the same time: 1. Android: targetsdkversion = "23" in the list 2. Device Android 6 marshmallow

If Android: targetsdkversion = "22" and Android 6 marshmallow do not crash, the devices before Android: targetsdkversion = "23" and marshmallow will not crash

resolvent:

I encountered the same problem when using the foscam SDK for Android

Just like @ 135, you just need to change targetsdkversion to 21. This is not the best solution, but it won't crash

If other solutions are found, I will update this answer

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>