简体   繁体   English

在Android Studio 0.8.2中使用.so库

[英]Use .so library in Android Studio 0.8.2

I tested All previously shown answers on stackoverflow more than once. 我多次测试了所有先前显示的关于stackoverflow的答案。 None of them working. 他们都没有工作。 I use Android Studio 0.8.2 with the latest Gradle Version . 我将Android Studio 0.8.2与最新的Gradle版本一起使用

I have libfourier.so . 我有libfourier.so This is a native library made in .c . 这是.c制作的本地库。

I don't have any other files. 我没有其他文件。

It has been used in a previous app and did work. 它已在以前的应用程序中使用,并且可以正常工作。

I need this library because it can perform fast fourier transform without the input being a power of 2. 我需要这个库,因为它可以执行快速傅立叶变换,而输入的2幂次方。

Is this possible? 这可能吗? If yes, how? 如果是,怎么办?

Currently I have put the libfourier.so in /libs/armeabi/libfourier.so 目前,我已经将libfourier.so放在/libs/armeabi/libfourier.so中

And I call it by using 我用

static {  
    System.loadLibrary("fourier");  
}  

But I get an UnsatisfiedLinkException stating the library could not be found. 但是我收到一个UnsatisfiedLinkException异常,指出找不到该库。

There is no real magic. 没有真正的魔术。 Just put it in libs/armeabi/libfourier.so like every other library. 就像其他所有库一样,只需将其放在libs / armeabi / libfourier.so中即可。

Everybody saying otherwise is wrong. 所有人都说错了。

First of all, the library was immediately found on a real device. 首先,立即在真实设备上找到该库。 So emulators in Android Device Manager and Genymotion cannot find this libraries apparently. 因此,Android设备管理器和Genymotion中的仿真器显然找不到该库。 Or the application is not installed as *.apk. 或应用程序未安装为* .apk。

For the diehards, it is certainly possible to install the apk-file. 对于顽固派来说,当然可以安装apk文件。 But for the lazy ones like me, a real device will do the trick. 但是对于像我这样的懒惰人来说, 真正的设备可以解决问题。

Secondly, you have to make sure your package name corresponds in the native function in the native code with the call to the native function in the android code. 其次,您必须确保您的包名称与本机代码中的本机功能相对应,并且要调用android代码中的本机功能。

If you have in Android intec.ugent.be.MyClass.nativeMethod() than your native method should be named: Java_intec_ugent_be_MyClass_nativeMethod(..) . 如果在Android中具有intec.ugent.be.MyClass.nativeMethod()则应将本机方法命名为: Java_intec_ugent_be_MyClass_nativeMethod(..) This is the case if you do not use JNI_onLoad in your native library. 如果您在本机库中不使用JNI_onLoad ,就是这种情况。

Of course you have than to rebuild the jni-package with ndk-build . 当然,您还需要使用ndk-build重建jni-package。 And add the new so-file to libs/armeabi. 并将新的so文件添加到libs / armeabi。

So I would advice if you work with NATIVE CODE/LIBRARY just use a REAL device to RUN TEST DEBUG (do not forget to enable debugging on the device) 因此,我建议您是否使用NATIVE CODE / LIBRARY,仅使用REAL设备运行测试调试 (不要忘记在设备上启用调试)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM