我目前正在尝试在 AT&T 三星 Galaxy S3 上构建和运行这个项目: https ://github.com/arrayfire/androidcl。问题是当我尝试运行时: ./ndk-build -C ~/Desktop/ArrayFire/androidcl/jni
然后我尝试通过转到“运行 -> 运行方式 -> Android 应用程序”在手机上运行它。
我收到“不幸的是,droidcl 已停止工作”。我是个菜鸟,但经过几天的研究,我认为这与 NDK 有关。在 LiveFeatureActivity 的第 19 行,“System.loadLibrary("JNIProcessor");” 是我最大的怀疑。
所有文件都在 Git 上。帮助将不胜感激,因为我尝试运行它 3 天但无济于事。
这是 ndk-build 所说的:
./ndk-build -C ~/Desktop/ArrayFire/androidcl/jni
Android NDK: WARNING:/home/laptop/Desktop/ArrayFire/androidcl/jni/Android.mk:JNIProcessor: non-system libraries in linker flags: /usr/lib/libOpenCL.so
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
make: Entering directory `/home/laptop/Desktop/ArrayFire/androidcl/jni'
[armeabi] Compile++ arm : JNIProcessor <= processor.cpp
[armeabi] SharedLibrary : libJNIProcessor.so
arm-linux-androideabi-g++: error: /usr/lib/libOpenCL.so: No such file or directory
make: *** [/home/laptop/Desktop/ArrayFire/androidcl/obj/local/armeabi/libJNIProcessor.so] Error 1
make: Leaving directory `/home/laptop/Desktop/ArrayFire/androidcl/jni'
这是Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := JNIProcessor
LOCAL_ARM_MODE := arm
LOCAL_SRC_FILES := processor.cpp
LOCAL_CPPFLAGS := -DARM -DOS_LNX -DARCH_32 -fexceptions
LOCAL_CPPFLAGS += -I$(LOCAL_PATH)/include
LOCAL_CPPFLAGS += -fexceptions
LOCAL_LDLIBS := -ljnigraphics -llog $(LOCAL_PATH)/libs/libOpenCL.so
include $(BUILD_SHARED_LIBRARY)
我尝试进入 Android.mk 文件并直接指向 /usr/lib/libOpenCl.so (在检查库之后)但仍然无法正常工作。
这是logcat文件:
02-06 22:52:27.515: D/ActivityThread(3233): setTargetHeapUtilization:0.25
02-06 22:52:27.515: D/ActivityThread(3233): setTargetHeapIdealFree:8388608
02-06 22:52:27.515: D/ActivityThread(3233): setTargetHeapConcurrentStart:2097152
02-06 22:52:27.575: W/dalvikvm(3233): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/example/LiveFeatureActivity;
02-06 22:52:27.575: W/dalvikvm(3233): Class init failed in newInstance call (Lcom/example/LiveFeatureActivity;)
02-06 22:52:27.575: D/AndroidRuntime(3233): Shutting down VM
02-06 22:52:27.575: W/dalvikvm(3233): threadid=1: thread exiting with uncaught exception (group=0x40cb6300)
02-06 22:52:27.575: E/AndroidRuntime(3233): FATAL EXCEPTION: main
02-06 22:52:27.575: E/AndroidRuntime(3233): java.lang.ExceptionInInitializerError
02-06 22:52:27.575: E/AndroidRuntime(3233): at java.lang.Class.newInstanceImpl(Native Method)
02-06 22:52:27.575: E/AndroidRuntime(3233): at java.lang.Class.newInstance(Class.java:1319)
02-06 22:52:27.575: E/AndroidRuntime(3233): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
02-06 22:52:27.575: E/AndroidRuntime(3233): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2090)
02-06 22:52:27.575: E/AndroidRuntime(3233): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
02-06 22:52:27.575: E/AndroidRuntime(3233): at android.app.ActivityThread.access$600(ActivityThread.java:142)
02-06 22:52:27.575: E/AndroidRuntime(3233): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
02-06 22:52:27.575: E/AndroidRuntime(3233): at android.os.Handler.dispatchMessage(Handler.java:99)
02-06 22:52:27.575: E/AndroidRuntime(3233): at android.os.Looper.loop(Looper.java:137)
02-06 22:52:27.575: E/AndroidRuntime(3233): at android.app.ActivityThread.main(ActivityThread.java:4931)
02-06 22:52:27.575: E/AndroidRuntime(3233): at java.lang.reflect.Method.invokeNative(Native Method)
02-06 22:52:27.575: E/AndroidRuntime(3233): at java.lang.reflect.Method.invoke(Method.java:511)
02-06 22:52:27.575: E/AndroidRuntime(3233): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
02-06 22:52:27.575: E/AndroidRuntime(3233): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
02-06 22:52:27.575: E/AndroidRuntime(3233): at dalvik.system.NativeStart.main(Native Method)
02-06 22:52:27.575: E/AndroidRuntime(3233): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load JNIProcessor: findLibrary returned null
02-06 22:52:27.575: E/AndroidRuntime(3233): at java.lang.Runtime.loadLibrary(Runtime.java:365)
02-06 22:52:27.575: E/AndroidRuntime(3233): at java.lang.System.loadLibrary(System.java:535)
02-06 22:52:27.575: E/AndroidRuntime(3233): at com.example.LiveFeatureActivity.<clinit>(LiveFeatureActivity.java:19)
02-06 22:52:27.575: E/AndroidRuntime(3233): ... 15 more
02-06 22:52:43.723: I/Process(3233): Sending signal. PID: 3233 SIG: 9