Java – Android 6 Marshmallow crashes when calling native libraries

Android 6 Marshmallow crashes when calling native libraries… here is a solution to the problem.

Android 6 Marshmallow crashes when calling native libraries

My app uses native libraries and works fine from Android 2.2 to 5.1

But on Android 6 the Marshmallow app crashes with the error: E/AndroidRuntime (1602): java.lang.UnsatisfiedLinkError: 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

).

How do I fix a 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 comment call:

// FSApi.Init();

There is no crash. This means that the native library loads successfully.
I also get the 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 tried to find Java_com_ipc_sdk_FSApi_Init or Java_com_ipc_sdk_FSApi_Init__ in the library, but without success.
But if I open .so in a text editor, I find Java_com_ipc_sdk_FSApi_Init!

The problem occurs only if both conditions exist:
1. android:targetSdkVersion=”23″ in list
2. Device Android 6 Marshmallow.

It does not crash on android:targetSdkVersion=”22″ and Android 6 Marshmallow

, nor does it crash on android:targetSdkVersion=”23″ and devices prior to Marshmallow.

Solution

I’m having the same issue with the Foscam SDK for Android.

As @135 says, you just need to change targetSdkVersion to 21. It’s not the best solution, but it works.

I’ll update this answer if I find another workaround.

Related Problems and Solutions