未从Cordova APK下载本地库 [英] Native library not loaded from cordova apk

查看:73
本文介绍了未从Cordova APK下载本地库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个cordova插件,它将是.jar文件及其两个.so依赖项的简单包装.我之前在带有android studio的普通android应用程序中尝试过.通过将本机库复制到jniLibs/armeabi文件夹中,并将jar文件复制到libs/中,它可以正常工作.

在cordova插件中,我制作了相同的文件夹结构,并且所有内容都位于同一位置.在plugin.xml中,我已将两个文件复制到libs/armeabi中,这是可以正常工作的,因为如果我查看apk,它们将位于正确的"文件夹中.

但是,当我尝试使用cordova应用程序中的插件时,尝试调用本机库时会引发UnsatisfiedLinkError:

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

我应该在哪里复制这些库?

解决方案

我最近需要交叉编译一个C库以用于Cordova应用程序,因此,基于该经验,我创建了一个示例Cordova插件和相应的插件. xml ,您还将看到我还将armeabi库以及其他库用于其他体系结构复制到了/libs/armeabi. 该插件肯定可以正常工作(您可以尝试),因此希望您可以将其用作有效参考.

愚蠢的问题:您不是只复制 armeabi库吗?因为我敢肯定大多数现代Android设备都不支持(ARMv5/ARMv6),并且要求armeabi-v7a必须位于/libs/armeabi-v7a ...

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...

这篇关于未从Cordova APK下载本地库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆