Couldn't load library from loader

2019-09-07 11:28发布

问题:

I have a problem loading some .dll libraries through my android app, in fact there is tons of questions about this issue but not any one of them solves my problem, the following is how I'm trying to implement them:

public class MainActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    System.loadLibrary("NetSDKDLL"); // this is where I'm getting the Exception
    simpleDLL INSTANCE = (simpleDLL) Native.loadLibrary(
            ("NetSDKDLL"), simpleDLL.class);
  }

   public interface NetSDKDLL extends StdCallLibrary {
      int IP_NET_DVR_RealPlay(NativeLong nLoginId);
   }
}

And this is the log:

01-29 12:20:34.407: E/AndroidRuntime(1623): FATAL EXCEPTION: main
01-29 12:20:34.407: E/AndroidRuntime(1623): Process: com.example.removed, PID: 1623
01-29 12:20:34.407: E/AndroidRuntime(1623): java.lang.UnsatisfiedLinkError: Couldn't load NetSDKDLL from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.removed-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.removed-2, /system/lib]]]: findLibrary returned null
01-29 12:20:34.407: E/AndroidRuntime(1623):     at java.lang.Runtime.loadLibrary(Runtime.java:358)
01-29 12:20:34.407: E/AndroidRuntime(1623):     at java.lang.System.loadLibrary(System.java:526)
01-29 12:20:34.407: E/AndroidRuntime(1623):     at com.example.removed.MainActivity.onCreate(MainActivity.java:34)

And to give a clear overview:

1- I've no problem in SDK and it's path is already assigned in eclipse and in System Environments.

2- the dll libraries are placed in a source folder called dll.

3- the dll libraries also placed in libs folder.

4- I'm using the same way in a regular Java app and it works perfectly.


Updates:

new Exception:

02-01 09:18:44.840: E/AndroidRuntime(1145): Caused by: java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-i686/libjnidispatch.so) not found in resource path (.)

回答1:

You're missing JNA's own native support. See this question.

Note that you'll need to follow Android's specific rules for bundling and loading native code with your app.

EDIT

Specifically, your project must include the resource path

com/sun/jna/<arch-specific>/libjnidispatch.so

JNA will look for your native libraries under

<arch-specific>/<mapped-library-name>

You can set the system properties -Djna.debug_load=true and -Djna.debug_load.jna=true and JNA will emit to stdout where it's looking for your libraries and its own, respectively.

JNA provides the value for <arch-specific> in Platform.RESOURCE_PREFIX.