android 没有 java 的 NDK adb 可执行文件
android NDK adb executable without java
我正在尝试通过 adb shell 在 android 模拟器上 运行 一个 c++ 可执行文件。
我正在使用 opencv。
一切正常,代码工作正常,但我需要知道如何显示
图片使用 cv::imshow(...)
。我知道如果不通过 JNI 并将此代码附加到可以内置到 apk 中的实际 android 应用程序,这可能是不可能的。但这不是我现在想要做的。
我只需要能够做到
adb shell am start -d file:///path/to/someimage/someimage.jpg -t image/jpg -a android.intent.action.VIEW
通过 C++ 代码。
当我尝试通过我的 C++ 代码调用 cv::imshow(...)
然后通过 adb shell 调用 exe 运行 时,我目前遇到以下错误:
terminate called after throwing an instance of 'cv::Exception'
what(): openCV(3.4.3) /build/3_4_pack-android/opencv/modules/highgui/src/window.cpp:632:error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.X or Carbon support. If you are on Ubutu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script function in 'cvShowImage'
是否有我可以添加到 LOCAL_LDLIBS 的链接器标志或我可以用来使它工作而无需使用 java/JNI 拐杖的其他一些小修复程序?
在很大程度上,你是 "going about this all wrong"。但是,如果您想做您似乎正在尝试做的事情,不管 的限制,并且愿意永久绑定到 运行 下的 adb shell那就有办法了
本质上:
- 您有一个有效的 shell 命令。
- 你有一个程序想要执行这个命令。
- 程序的执行上下文与shell命令相同
这是 system()
系统调用
的作业
#include <stdlib.h>
int system(const char *command);
所以你只需做类似
的事情
system("am start -d file:///path/to/someimage/someimage.jpg -t image/jpg -a android.intent.action.VIEW)
...大概命令字符串是您在运行时构造的内容,用于填充文件名等
当然,在 Android 上 可部署 的任何东西还有很长的路要走,除非你打算始终通过 adb 进行操作。要到达您 应该 的地方,更大的挑战是将您的可执行文件转换为 jni 子例程,或者可能将其作为子进程调用。作为一个子进程,您可能无法发送意图 - 但您仍然可以使用管道或套接字与拥有的应用程序通信,并让它显示图像或代表您发送意图,以便其他东西可以。
我正在尝试通过 adb shell 在 android 模拟器上 运行 一个 c++ 可执行文件。
我正在使用 opencv。
一切正常,代码工作正常,但我需要知道如何显示
图片使用 cv::imshow(...)
。我知道如果不通过 JNI 并将此代码附加到可以内置到 apk 中的实际 android 应用程序,这可能是不可能的。但这不是我现在想要做的。
我只需要能够做到
adb shell am start -d file:///path/to/someimage/someimage.jpg -t image/jpg -a android.intent.action.VIEW
通过 C++ 代码。
当我尝试通过我的 C++ 代码调用 cv::imshow(...)
然后通过 adb shell 调用 exe 运行 时,我目前遇到以下错误:
terminate called after throwing an instance of 'cv::Exception'
what(): openCV(3.4.3) /build/3_4_pack-android/opencv/modules/highgui/src/window.cpp:632:error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.X or Carbon support. If you are on Ubutu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script function in 'cvShowImage'
是否有我可以添加到 LOCAL_LDLIBS 的链接器标志或我可以用来使它工作而无需使用 java/JNI 拐杖的其他一些小修复程序?
在很大程度上,你是 "going about this all wrong"。但是,如果您想做您似乎正在尝试做的事情,不管 的限制,并且愿意永久绑定到 运行 下的 adb shell那就有办法了
本质上:
- 您有一个有效的 shell 命令。
- 你有一个程序想要执行这个命令。
- 程序的执行上下文与shell命令相同
这是 system()
系统调用
#include <stdlib.h>
int system(const char *command);
所以你只需做类似
的事情system("am start -d file:///path/to/someimage/someimage.jpg -t image/jpg -a android.intent.action.VIEW)
...大概命令字符串是您在运行时构造的内容,用于填充文件名等
当然,在 Android 上 可部署 的任何东西还有很长的路要走,除非你打算始终通过 adb 进行操作。要到达您 应该 的地方,更大的挑战是将您的可执行文件转换为 jni 子例程,或者可能将其作为子进程调用。作为一个子进程,您可能无法发送意图 - 但您仍然可以使用管道或套接字与拥有的应用程序通信,并让它显示图像或代表您发送意图,以便其他东西可以。