Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running an executable jar in android

Tags:

java

android

jar

is it possible to run an executable jar file (command line based) in android? one of my friend told me that it is possible to run executables written in C. Is it possible for java too? I will run the tool through adb shell.

like image 202
P basak Avatar asked Oct 15 '12 22:10

P basak


People also ask

Can I run a .jar file on Android?

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 .

How do I open Java files on Android?

Install the lastest Java SDK. Make sure to set your JAVA_HOME variable after installing and also include %JAVA_HOME%\bin in your PATH environment variable. It is installed correctly when you can go to a command prompt and type java -version and get a valid response (something other than Bad command or File Name).

What is a JAR file in Android?

A JAR (Java Archive) is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file to distribute application software or libraries on the Java platform.


2 Answers

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.

like image 191
Florian Minges Avatar answered Sep 18 '22 02:09

Florian Minges


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.

like image 43
mportuesisf Avatar answered Sep 21 '22 02:09

mportuesisf