Running an executable jar in android

Android uses the Dalvik VM, whereas you need the Java VM to run a jar-file. So no, you can't run a jar-file on android.


is it possible to run an executable jar file (command line based) in android?

possible, check "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 "$@"

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.

You can however use JBed which runs a whole JSE JVM under Android: http://jbed.en.malavida.com/android/


You can install an app built as an APK through adb:

adb install my_apk_file.apk

And once inside an adb shell, you can launch an APK application using the am command. See How to start an application using android ADB tools?

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.

I think you would need to embed your .jar file inside a minimal Android application that invokes the jar and prints results to stdout. Then you would build that APK and install/run it as I described above.

Tags:

Java

Android

Jar