I'm making a cordova plugin that would be a simple wrapper for a .jar file and its two .so dependencies. I have tried it before in a normal android application with android studio. By copying the native libraries into the jniLibs/armeabi folder and the jar file into libs/ it worked perfectly.
At the cordova plugin I've made the same folder structure and everything is on the same place. In the plugin.xml I have copying the two files into libs/armeabi which is working because if I look into the apk, they are in the "right" folder.
But when I try to use the plugin from the cordova application it throws an UnsatisfiedLinkError when it tries to call the native library:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.ionicframework.*******-2/base.apk"],nativeLibraryDirectories=[/data/app/com.ionicframework.*******-2/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libjni.so"
W/System.err( 4224): at java.lang.Runtime.loadLibrary(Runtime.java:366)
W/System.err( 4224): at java.lang.System.loadLibrary(System.java:988)
W/System.err( 4224): at *******.<clinit>(ComIO.java:407)
W/System.err( 4224): at *******.<init>(Printer.java:33)
W/System.err( 4224): at net.terbe.dev.cordova.*******.print(*******.java:54)
W/System.err( 4224): at *******.cordova.*******.execute(*******.java:42)
W/System.err( 4224): at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
W/System.err( 4224): at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
W/System.err( 4224): at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:57)
W/System.err( 4224): at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
W/System.err( 4224): at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err( 4224): at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
W/System.err( 4224): at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err( 4224): at android.os.Looper.loop(Looper.java:135)
W/System.err( 4224): at android.os.HandlerThread.run(HandlerThread.java:61
Where should I copy these libraries?
I've recently needed to cross-compile a C library for use in a Cordova app, so based on that experience, I've created an example Cordova plugin and corresponding test app that uses it.
If you look in my plugin.xml you'll see I also copy the armeabi
library to /libs/armeabi
, as well as the other libraries for the other architectures.
That plugin is definitely working (you can try it), so hopefully you can use it as a working reference.
Stupid question: you're not copying only the armeabi
library? Because I'm pretty sure most modern Android devices don't support that (ARMv5/ARMv6) and require armeabi-v7a
to be in /libs/armeabi-v7a
...