我目前正在尝试在AT& T三星Galaxy S3上构建并运行此项目:https://github.com/arrayfire/androidcl。问题是当我尝试运行时:./ right-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
答案 0 :(得分:0)
运行应用时收到的UnsatisfiedLinkError
只是因为您的模块无法构建,因此未包含在应用中。让NDK构建链接到libOpenCL.so
应解决此问题。
您首先需要获取一个libOpenCL.so
链接,您应该能够在目标设备上找到它(如果它不在那里,那么这个应用程序无论如何都不会工作) 。在我的设备上,OpenCL库位于/system/vendor/lib/libOpenCL.so
,但您可能需要使用adb shell
来查找它。要将其复制到本地计算机,请运行adb pull /system/vendor/lib/libOpenCL.so
。
如果您将此库放在jni/
目录中,那么您只需要在libOpenCL.so
变量中添加LOCAL_LDLIBS
即可。否则,我通常只是在NDK平台目录中粘贴此库的副本(例如$NDK_DIR/platforms/android-17/arch-arm/usr/lib/
),然后通过将-lOpenCL
添加到LOCAL_LDLIBS variable
,可供所有应用程序使用。在这两种情况下,您可能会在链接器标志中收到有关非系统库的警告,但这些应该是安全的。
答案 1 :(得分:0)
@Cookiez不确定您是通过谷歌搜索偶然发现了这个存储库,还是在阅读了我写的关于它的博客文章之后。如果您不知道该帖子,请通过this帖子了解如何在Android设备上运行代码。如果您仍然无法让应用程序运行,请告诉我。
普拉迪普。