不能建立对系统库函数库函数、系统

2023-09-05 05:03:20 作者:純情ベ小骚莮

我要疯了这里。

基本上,我试图访问某个功能定位系统/ lib下的共享库/​​ android平台,利用NDK上。

Basically, I'm trying to access some functions in a shared library located in system/lib/ on the android platform, using the NDK.

我想利用图书馆是libsonivox.so。我的主要目标是从NativeActivity的使用它。我理解这可能使事情变得复杂,因为我需要加载此库(静态)之前,我打开我自己的库,它依赖于它。因此,我试图得到它的工作,通过定期活动和JNI。

The library I'm trying to make use of is libsonivox.so. My main goal is to use it from a NativeActivity. I understand this can complicate things because I would need to load this library (statically) before I load my own library which depends on it. Therefore I am trying to get it to work through a regular Activity and JNI.

在活动我加载库,就像这样:

In the Activity I load the libraries like so:

static {
  System.loadLibrary("sonivox");
  System.loadLibrary("native-audio-jni");
}

在原生音频JNI图书馆是从NDK样,但我修改它的一个基本试图访问sonivox功能。

The "native-audio-jni" library is from the NDK samples, but I am modifying it in a rudimentary attempt to access the sonivox functions.

在没有任何通话从libnative-AUDIO-JNI来libsonivox,一切编译罚款。 这条线从LogCat中输出给了我希望:

Without any calls to libsonivox from libnative-audio-jni, everything compiles fine. This line from the LogCat output gives me hope:

  04-26 15:01:14.973: D/dalvikvm(691): No JNI_OnLoad found in /system/lib/libsonivox.so   
  0x412a1100, skipping init

因此​​,库被加载。

So the library is loaded.

然后,我添加此功能,本机的音频jni.c:

Then I add this function to native-audio-jni.c:

void Java_jay_enn_eye_JNImidiActivity_createMidi(JNIEnv* env,
        jclass clazz)
{
  pLibConfig = EAS_Config();
}

pLibConfig是这样的声明:

pLibConfig is declared like this:

static const S_EAS_LIB_CONFIG* pLibConfig = NULL;

当被声明,不加入上述功能的,它编译细。因此,至少在头文件......那里。

When that is declared, without the addition of the above function, it compiles fine. So at least the header files are... there.

当我放下那个函数到code,这是NDK建造的输出:

When I plop that function into the code, this is the output of ndk-build:

  Compile thumb  : native-audio-jni <= native-audio-jni.c
  SharedLibrary  : libnative-audio-jni.so
  ./obj/local/armeabi/objs/native-audio-jni/native-audio-jni.o: In function
  `Java_jay_enn_eye_JNImidiActivity_createMidi':
  /home/anthony/Documents/eclipse/JNImidi/jni/native-audio-jni.c:202: undefined   
  reference
  to `EAS_Config'
  collect2: ld returned 1 exit status
  make: *** [obj/local/armeabi/libnative-audio-jni.so] Error 1

我不知道,如果libnative-AUDIO-JNI只是不能访问libsonivox,或者如果我需要的dlsym()或符号()链接sonivox功能来使用它们。我一直没能去尝试任何这些,因为磁带库系统中的/ lib目录中/而不是由我提供的,所以我没有一个完整路径,以提供这样做。

I'm not sure if libnative-audio-jni just can't access libsonivox, or if I need to dlsym() or sym() link the sonivox functions to use them. I haven't been able to try either of those since the library is found in system/lib/ and not provided by me, so I don't have a full path to provide to do that.

另一种选择,我考虑是抓住libsonivox.so,将其复制到一个目录中的项目,改变Android.mk,使其包含的lib为prebuilt共享库。我想也许库需要包括在编译的时候。

Another option I am considering is grabbing libsonivox.so, copying it into a directory in the project, and changing the Android.mk so that it includes the lib as a prebuilt shared library. I was thinking maybe the library needs to be included at compile time.

编辑:这里的Andr​​oid.mk文件:

Here's the Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := native-audio-jni
LOCAL_SRC_FILES := native-audio-jni.c
# for native audio
LOCAL_LDLIBS    += -lOpenSLES
# for logging
LOCAL_LDLIBS    += -llog
# for native asset manager
LOCAL_LDLIBS    += -landroid

include $(BUILD_SHARED_LIBRARY)

这一定是在那里的东西是不对的。我觉得sonivox库的会需要编译一切,当是present。然而,该库将不会加载无论什么样的变化我做这个文件,已主要涉及试图把它作为一个preBUILT_SHARED_LIBRARY或preBUILT_STATIC_LIBRARY。此外,OpenSL东西的作品完美的罚款。我希望sonivox会的工作,如果我只是把它作为-lsonivox,但没有。

This must be where something isn't right. I'd think the sonivox library would need to be present when compiling everything. However, the library won't load no matter what changes I make to this file, which have mainly involved trying to include it as a PREBUILT_SHARED_LIBRARY or PREBUILT_STATIC_LIBRARY. Also, the OpenSL stuff works perfectly fine. I wish sonivox would work if I were to just include it as -lsonivox, but no.

推荐答案

我被冲昏头脑其他的东西,但我想通了这个问题的答案最近... libsonivox.so可动态加载。你需要从Android设备复制的。所以,并将其放置在$ NDK-ROOT /平台/ Android为14 /弓臂/ usr / lib中,机器人-14可以是任何版本代替。 这样,它可以对被编译,而当该应用是一个设备上运行它使用的库,设备上的

I got carried away with other things, but I figured out the answer to this recently... libsonivox.so can be loaded dynamically. You need to copy the .so from your android device and place it in $NDK-ROOT/platforms/android-14/arch-arm/usr/lib, "android-14" can be whatever version instead. That way it can be compiled against, and when the app is running on a device it uses the library on that device.