是否可以在android中运行可执行jar文件(基于命令行)?我的一个朋友告诉我,可以运行用C编写的可执行文件。是否有可能是java?我将通过adb shell运行该工具。
您可以通过adb安装构建为APK的应用:
adb install my_apk_file.apk
一旦进入adb shell,您就可以使用am
命令启动APK应用程序。见How to start an application using android ADB tools?
但我不认为有一种方法可以在桌面操作系统上直接运行jar文件,因为Android不使用标准Java VM。
我想你需要将你的.jar文件嵌入一个最小的Android应用程序中,该应用程序调用jar并将结果打印到stdout。然后你将构建该APK并安装/运行它,如上所述。
Android使用Dalvik VM,而您需要Java VM来运行jar文件。所以不,你不能在android上运行jar文件。
在Android中运行jar的唯一问题是JVM,它在Android下是一个Dalvik VM,无法运行JSE编译的java程序。
但是你可以使用在Android下运行整个JSE JVM的JBed:http://jbed.en.malavida.com/android/
实际上,你可以通过UI Automator运行java代码。创建一个jar,添加junit样式类,然后通过UI Automator运行它。
是否可以在android中运行可执行jar文件(基于命令行)?
可以,检查“adb shell input”shellscript - >“exec app_process”
shell@flo:/ $ ls -l /system/bin/input
-rwxr-xr-x root shell 203 2015-11-10 01:44 input
https://android.googlesource.com/platform/frameworks/base/+/oreo-release/cmds/input/input
# Script to start "input" on the device, which has a very rudimentary
# shell.
#
base=/system
export CLASSPATH=$base/framework/input.jar
exec app_process $base/bin com.android.commands.input.Input "$@"