在使用Android应用程序存在的共享库(。所以) [英] Using existing shared library (.so) in Android application

查看:177
本文介绍了在使用Android应用程序存在的共享库(。所以)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有后续方案去努力。我得到了一个共享库(libeffect.so)在Android项目我工作的一个客户端使用。我没有共享的库源$ C ​​$ C,我刚才的.so文件和我在一起。图书馆是pre-编制工作在Android设备上。随着共享库我有方法的签名

 公共静态本地无效doEffect(INT参数1,IntBuffer intBuffer);
 

所以现在我对如何使调用此本地方法,来源,如果可能的话有刚刚.so文件的一些questiosn,所以它们是:

  1. 我是否需要将本地方法的签名在同一个包/类的定义时。所以是我​​也可以在任何包/班在我的项目中使用此签名,在运行时,JVM会能够找到共享库的方法是什么?例如,如果这个共享库中的一类mypackage.MyClass首先使用,是否需要创建相同的包,类,然后把方法签名呢?

  2. 我在哪里需要把这个.so文件我的Eclipse Android项目里面得到这个文件部署在我的apk文件?

这些问题听起来小白,但我从来没有使用JNDI工作过,所以我有点担心,如果在调用该方法doEffect没有任何错误可以实现。任何答案,可以指导我来说是非常值得欢迎的。

非常感谢 蒂亚戈

解决方案
  
      
  1. 请我需要把本地方法的签名在同一个包/类   这些规定的时候。所以是还是我   可以在任何使用这个签名   包/班在我的项目,   在运行时,JVM将能够   找到共享库的方法是什么?   例如,如果这个共享库   在一个类中首次被使用   mypackage.MyClass,做我需要创建   同一个包,类,然后把   该方法的签名呢?
  2.   

没有必要创建相同的包/班。你可以把方法签名的任何包。

 公共类NativeLib {

  静态{
    的System.loadLibrary(so_file);
  }

  公共静态本地无效doEffect(INT参数1,IntBuffer intBuffer);

}
 

  

2.Where我需要把这个.so文件我的Eclipse Android项目内   得到这个文件部署在我的apk文件?

您已经把这个.so文件在应用程序的lib文件夹。如果lib文件夹中是不存在的,那么你可以创建一个lib文件夹,并把.so文件。您可以通过使用的System.loadLibrary(so_文件)称呼它;

I have the follow scenario to work on. I was given a shared library (libeffect.so) to use in a Android project i am working for a client. I dont have the shared library source code, i have just the .so file with me. The library is pre-compiled to work on android devices. Along with the shared library I have the method signature

public static native void doEffect(int param1, IntBuffer intBuffer);

So now I have some questiosn on how to make the call to this native method, of source, if this is possible having just the .so file, so there they are:

  1. Do I need to place the native method signature in the same package/class as those defined when the .so was or I can use this signature in any package/class in my project that during runtime the jvm will be able to find the method in the shared library? For example, if this shared library was firstly used in a class mypackage.MyClass, do I need to create the same package, class and then put the method signature there?

  2. Where do I need to place this .so file inside my eclipse android project to get this file deployed inside my apk file?

These question might sound noob, but I have never worked with jndi before so I am a bit concerned if calling the method doEffect without any error can be achieve. Any answer that can guide me is very welcome.

Many Thanks Thiago

解决方案

  1. Do I need to place the native method signature in the same package/class as those defined when the .so was or I can use this signature in any package/class in my project that during runtime the jvm will be able to find the method in the shared library? For example, if this shared library was firstly used in a class mypackage.MyClass, do I need to create the same package, class and then put the method signature there?

No need to create same package/class. You can put the method signature in any package.

public class NativeLib {

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

  public static native void doEffect(int param1, IntBuffer intBuffer);

}

2.Where do I need to place this .so file inside my eclipse android project to get this file deployed inside my apk file?

You have put this .so file in lib folder of your application . IF lib folder is not there then you can create a lib folder and put the .so file. you can call it by using System.loadLibrary("so_ file");

这篇关于在使用Android应用程序存在的共享库(。所以)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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