我可以用我的NDK的应用程序的本地库(安装在Android软件开发包)?我的、可以用、应用程序、开发包

2023-09-04 10:18:13 作者:故人叹

从这篇文章

http://marakana.com/forums/android/examples/49.html

我已经看到了应用程序建立与NDK的帮助下做下面的事情

i have seen that the application build with help of NDK do following things

1>它编译所有的C code(JNI文件夹中),使图书馆,停留在文件夹

1> it compile all c code (inside jni folder) and make library which stays in libs folder

2> .apk文件包里面也是库停留在 LIB 文件夹

2> inside .apk package also that library stays inside lib folder

和里面的java文件我可以加载该库具有以下code

and inside java file i can load that library with following code

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

问题1: 所以现在是有可能的,而不是保留该库的apk文件的一部分,我可以在安卓系统上安装它,并从系统中我的应用程序的负载?

Question1: so now is there possible that instead of keeping that library as part of .apk i can install it in android system and my application load from system ?

问题2: 同样的方式我可以使用一些其他的库中的所有准备安装在机器人像开放GL 的SQLite

Question2: same way can i use some other libraries all ready installed in android like open GL, sqLite ?

推荐答案

解答这两个问题是可以呀。

Answer to both the questions is Yes you can.

Q1: 如果你想测试它,你可以按照这种方式。

Q1 : If you want to test it you can follow this way.

1),使用NDK编译源$ C ​​$ C。

1) Compile the source code using NDK.

2)复制(ADB推)在你的Andr​​oid设备/系统/ lib中的库。运行应用程序。

2) Copy (adb push) the library in /system/lib of your android device. Run the Application.

在加载检查库无论是从apk文件中或从系统/系统/ lib文件夹lib文件夹中。但要复制到/系统/ lib中,你应该重新挂载文件系统。对于这一点,你必须有root权限。

When you load a library it checks either from lib folder of apk file or from /system/lib folder of the system. But to copy into /system/lib, you should remount the filesystem. For this you got to have root permissions.

Q2:

答到Q1回答部份效果以及。如果库为present在/系统/ lib中,你可以藏汉调用现有库。但是有一个小问题。你不能叫内直接因为命名约定的图书馆应遵循的JNI接口的功能。所以,最后您必须使用现有的库以创建自己的图书馆。

Answer to Q1 answers ths aswell. If the library is present in /system/lib, you can call the existing libraries aswell. But there is a small problem. You cannot call the functions inside the library directly because of the naming convention to be followed for jni interface. So ultimately "you have to create your own library using the existing library".

步骤是这样的:

拉​​库(ADB拉)

写您的本地code将被调用现有库的例程(出埃及记的OpenGL)

Write your native code which will be calling the routines of the existing library(Ex. OpenGL)

通过与prebuilt库链接它编译你的code(请参阅NDK的文档文件。这是写的很清楚如何做到这一点,你需要在编译时提到它在Android.mk文件)。

Compile your code by linking it with the prebuilt library(See NDK documentation file. It is very clearly written how to do this. You need to mention it in Android.mk file while compiling).

您将最终得到一个共享库,它内部含有现有的库。

You will finally get a shared library which internally contains the existing library.

我也做了同样的事情,一个现有的库,libsqlite。如果你被卡住的地方,让我知道。谢谢

I did the same thing for one of the existing libraries, libsqlite. If you are stuck somewhere let me know. Thanks