本地应用程序与ndk无法正常工作

时间:2012-06-19 21:30:44

标签: android android-ndk

我有两个设备。一个是运行2.3.6的HTC Nexus-One,另一个是运行2.2.2的LG Optimus V.该项目有一个jni库,我正在使用android ndk构建。 该应用程序在Nexus-One设备上安装和运行时没有任何问题,但它在LG设备上崩溃时出现以下错误:

06-19 16:20:57.192: E/AndroidRuntime(3044): FATAL EXCEPTION: main
06-19 16:20:57.192: E/AndroidRuntime(3044): java.lang.ExceptionInInitializerError
06-19 16:20:57.192: E/AndroidRuntime(3044):     at java.lang.Class.newInstanceImpl(Native Method)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at java.lang.Class.newInstance(Class.java:1429)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at android.os.Looper.loop(Looper.java:123)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at android.app.ActivityThread.main(ActivityThread.java:4627)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at java.lang.reflect.Method.invokeNative(Native Method)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at java.lang.reflect.Method.invoke(Method.java:521)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:893)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:651)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at dalvik.system.NativeStart.main(Native Method)
06-19 16:20:57.192: E/AndroidRuntime(3044): Caused by: java.lang.UnsatisfiedLinkError: Library filters-jni not found
06-19 16:20:57.192: E/AndroidRuntime(3044):     at java.lang.Runtime.loadLibrary(Runtime.java:466)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at java.lang.System.loadLibrary(System.java:557)
06-19 16:20:57.192: E/AndroidRuntime(3044):     at com.test.MainActivity.<clinit>(MainActivity.java:427)
06-19 16:20:57.192: E/AndroidRuntime(3044):     ... 15 more

我的make文件(Android.mk)如下所示:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE    := filters-jni
LOCAL_SRC_FILES := filters.c
LOCAL_CFLAGS := -DHAVE_CONFIG_H -DFPM_ARM -ffast-math -O3 -Wall
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -ldl
# for native audio
LOCAL_LDLIBS    += -lOpenSLES
# for logging
LOCAL_LDLIBS    += -llog
# for native asset manager
LOCAL_LDLIBS    += -landroid
LOCAL_STATIC_LIBRARIES := cpufeatures
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cpufeatures)

我的Application make文件只有一行

    APP_ABI := all

什么给,我无法理解。感谢您的建议。

2 个答案:

答案 0 :(得分:2)

OpenSLES库仅适用于Android 2.3。

请参阅NDK发行版中的docs/STABLE-APIS.html文件,了解适用于Android版本的库列表。

答案 1 :(得分:0)

将它放在Application.mk文件中,看看会发生什么:

APP_ABI := armeabi armeabi-v7a x86

这为设备提供了三个.so,可以从中选择