4

There is a large amount of Java jars in /system/framework, for example, am.jar. I understand that Android uses Java in a very confusing way (at least for me). I do not completely understand the way that dalvik works.

Basically, I do not understand how Android runs these jars. Can somebody explain how it does this, and possibly how I can run my own jars? I am on Resurrection Remix, 6.0.1, with Xposed framework, if it helps.

Thanks

| improve this question | | | | |
  • What are you trying to accomplish by running your own JARs? New apps, changing OS behavior, etc? – Mufasa May 18 '17 at 18:58
  • @Mufasa I just want to know how it runs them. I dont want to run my own. (At least for now) – Tyler Richardson May 18 '17 at 19:21
  • @Mufasa I know this is kinda old now, but if it only executes .dex'es, then what are those .jar's there for? – Tyler Richardson Jun 18 '17 at 21:51
  • I'm not totally sure, but I think they have to do with the boot process, core framework stuff, and possibly for compatibility reasons. After all, JARs are just ZIP files with a certain directory structure in them—it doesn't have to be using them strictly for executable code. The general idea is that Android usually doesn't execute JARs in the user space during normal operation. Also see stackoverflow.com/q/30656933/2291 which discusses how most of those JARs have simple meta data in them. – Mufasa Jun 19 '17 at 14:06
  • .jar files are Android's standard class library which is loaded by Dalvik/ART VMs just like JVM on PCs loads JCL from different .jar/.jmod files. Environment variable BOOTCLASSPATH defines a list of all such .jar files. Like .apk files, .jar files are also ZIP files and contain a classes.dex file which is either interpreted or JIT compiled (as was done by Dalvik) or AOT compiled to .odex or .oat files (as ART does). All apps built with Android SDK depend on this standard class library. – Irfan Latif Mar 6 at 15:31
2

You can run the Jar files using app_process, which replaces the java executable on Android. Looking at /system/bin/am for example, we see it's really running

exec app_process $base/bin com.android.commands.am.Am "$@"

You've mentioned running Xposed. If you'll google the manual installation of this framework, you'll see it both deploys a jar to /system/frameworks and replaces app_process with a modified one, where the hooks are added. It's also instructive to read through the modified app_process code.

Note you may need this answer to actually run your apps.

Finally, note that you seem to have misunderstood the link to stackoverflow answer in the comments (https://stackoverflow.com/q/30656933/2291). The Jars are installed. On newer systems, they are converted (and the files removed from the jar) to ART and run as native code (i.e. machine language). On older systems, I think the java class files are converted to Dex bytecode and run in the Dalvik VM. That means that the Dex bytecode is run in Dalvik in the same way Java bytecode is run by the Java VM on the fly. In any case, the JAR files always contain code initially.

| improve this answer | | | | |
1

That's a pretty big question; it's a very complicated and large system. If you can't narrow your question any more, then the short answer is from Android's docs:

the Dalvik VM is an interpreter-only virtual machine that executes files in the Dalvik Executable (.dex) format

Similar to the Java JVM, but a different implementation optimized for Android's usage patterns.

Also see What is Dalvik and dalvik-cache? which describes it a little more.

Otherwise, I suggest you read Google's documentation on the subject to find out more info about whatever parts of the dalvik system you are interested in. (If we tried to answer it all here, it would take a nearly infinite page scroll (exaggerating a little) to describe all the different parts and pieces how and why it works.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.