Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between AAR, JAR, DEX, APK in Android

In Android systems or development enviroments, what are the differences between AAR, JAR, DEX, and APK files? What is the purpose of each one?

AFAIK, JAR are just like a collection of .class files (like in Java).

AAR are JAR files + resources. But what's its usage case? To be used to distribute development libraries for Android?

APK seems to be similar to packages like .deb or .rpm. Is it the only way to install applications on Android?

What about DEX files? Compiled applications... but what's the difference with a JAR or AAR file?

Moreveor, when distributing .so (i.e. native code) files for Android, what's the best way to do it?

like image 237
sapito Avatar asked Nov 04 '15 22:11

sapito


People also ask

What is difference between AAR and APK?

If you mean "distributing an app", your . so files will be in the APK. If you mean "distributing as a library for other developers", use an AAR or just an Android project in source form.

What is the difference between AAR and jar?

The main difference between a Jar and an AAR is that AAR s include resources such as layouts, drawables, etc. . For example if you have multiple apps that use the same login screen, with Jar's you could share classes but not the layout, styles, etc., you still had to duplicate them.

Is an APK a jar?

5 Answers. APK file is just a JAR file with additional Android platform specific files included in it such as AndroidManifest.

What is AAR file in Android?

AAR files can contain Android resources and a manifest file, which allows you to bundle in shared resources like layouts and drawables in addition to Java classes and methods. AAR files can contain C/C++ libraries for use by the app module's C/C++ code.


2 Answers

JAR (Java Archive)

JAR is a package file format designed for distribution of Java application on its platform. It contains compiled Java class files + some more files like MANIFEST. Basically it is just an ZIP archive with some restrictions.

DEX (Dalvik Executable)

DEX is binary file format, so it is compiled. We could say, that .dex file is for DVM (Dalvik Virtual Machine) something like .class files for JVM.

DEX file format is really generated from java CLASS files by dex compiler from Android SDK. This compiler translates JVM bytecode to DVM bytecode and put all class files to one dex file.

APK (Android Application Package)

APK is file format designed for distributing Android application on its platform. It has some similarities with JAR format. Again it is simply just a ZIP archive, but APK files have pre-defined specific structure. For example, it always must contains file named AndroidManifest.xml and many more. Also this package aggregates compiled classes in dex format.

AAR

AAR is the binary distribution of an Android Library Project. It has similar structure as APK.

like image 123
hradecek Avatar answered Oct 17 '22 13:10

hradecek


JAR are just like a collection of .class files (like in Java).

That is because it is a Java JAR.

AAR are JAR files + resources

Correct.

But what's its usage case? To be used to distribute development libraries for Android?

Correct.

APK seems to be similar to packages like .deb or .rpm. Is it the only way to install applications on Android?

Generally speaking, yes.

What about DEX files?

DEX files contain the cross-compiled Dalvik bytecodes representing the application code. Developers write Java, but Android runs Dalvik bytecodes. In the APK, you will find a DEX file representing those bytecodes.

Moreveor, when distributing .so (i.e. native code) files for Android, what's the best way to do it?

I do not know what you mean by "distributing".

If you mean "distributing an app", your .so files will be in the APK.

If you mean "distributing as a library for other developers", use an AAR or just an Android project in source form.

like image 21
CommonsWare Avatar answered Oct 17 '22 13:10

CommonsWare