简体   繁体   English

在android中运行一个可执行的jar

[英]Running an executable jar in android

is it possible to run an executable jar file (command line based) in android?是否可以在 android 中运行可执行的 jar 文件(基于命令行)? one of my friend told me that it is possible to run executables written in C. Is it possible for java too?我的一位朋友告诉我,可以运行用 C 编写的可执行文件。 java 也可以吗? I will run the tool through adb shell.我将通过 adb shell 运行该工具。

Android uses the Dalvik VM, whereas you need the Java VM to run a jar-file. Android 使用 Dalvik VM,而您需要 Java VM 来运行 jar 文件。 So no, you can't run a jar-file on android.所以不,你不能在 android 上运行 jar 文件。

You can install an app built as an APK through adb:您可以通过 adb 安装构建为 APK 的应用程序:

adb install my_apk_file.apk

And once inside an adb shell, you can launch an APK application using the am command.一旦进入 adb shell,您就可以使用am命令启动 APK 应用程序。 See How to start an application using android ADB tools?请参阅如何使用 android ADB 工具启动应用程序?

But I don't think there's a way to directly run a jar file the way you can do so on a desktop operating system, because Android doesn't use the standard Java VM.但我不认为有一种方法可以像在桌面操作系统上那样直接运行 jar 文件,因为 Android 不使用标准的 Java VM。

I think you would need to embed your .jar file inside a minimal Android application that invokes the jar and prints results to stdout.我认为您需要将 .jar 文件嵌入到调用 jar 并将结果打印到标准输出的最小 Android 应用程序中。 Then you would build that APK and install/run it as I described above.然后,您将构建该 APK 并按照我上面的描述安装/运行它。

is it possible to run an executable jar file (command line based) in android?是否可以在 android 中运行可执行的 jar 文件(基于命令行)?

possible, check "adb shell input" shellscript -> "exec app_process"可能,检查“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 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 "$@"

The only problem with running a jar inside Android is the JVM which under Android is a Dalvik VM which cannot run JSE compiled java programs.在 Android 中运行 jar 的唯一问题是 JVM,它在 Android 下是一个 Dalvik VM,它不能运行 JSE 编译的 Java 程序。

You can however use JBed which runs a whole JSE JVM under Android: http://jbed.en.malavida.com/android/但是,您可以使用在 Android 下运行整个 JSE JVM 的 JBed: http ://jbed.en.malavida.com/android/

Actually, you can run java code via the UI Automator that's. 实际上,您可以通过UI自动器运行Java代码。 Create a jar, add junit style classes, and just run it via UI Automator. 创建一个jar,添加junit样式类,然后通过UI Automator运行它。

You cannot directly run jar files in android as android runs on Dalvik Virtual Machine , whereas to run jar files you will need Java Runtime Environment which has Java Virtual Machine .您不能直接在 android 中运行jar files ,因为 android 在Dalvik Virtual Machine上运行,而要运行 jar 文件,您将需要具有Java Virtual Machine Java Runtime Environment

Note: You will need root access and a file manager with root access:注意:您将需要 root 访问权限和具有 root 访问权限的文件管理器:
But you can run it, for that you have to install an application Jbed.apk and copy lib jbed.so to your system\\lib folder.但是您可以运行它,为此您必须安装一个应用程序Jbed.apk并将lib jbed.so复制到您的system\\lib文件夹中。 Then you can run jar/jad files from the application on your android device.然后,您可以从您的 android 设备上的应用程序运行 jar/jad 文件。

Here's the link to jbed: http://jbed.en.malavida.com/android/这是 jbed 的链接: http ://jbed.en.malavida.com/android/

Read the full post here on XDA Developers: XDA Developers, Run jar/jad on Android在此处阅读有关 XDA 开发人员的完整帖子: XDA 开发人员,在 Android 上运行 jar/jad

There are few posts which claims that there are ways to convert jar to apk, I haven't tried it myself: jar to apk If it doesn't works you may need to use an emulator:很少有帖子声称有将 jar 转换为 apk 的方法,我自己没有尝试过: jar to apk如果它不起作用,您可能需要使用模拟器:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM