简体   繁体   English

Android中AAR、JAR、DEX、APK的区别

[英]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?在Android系统或开发环境中,AAR、JAR、DEX、APK文件有什么区别? What is the purpose of each one?每一项的目的是什么?

AFAIK, JAR are just like a collection of .class files (like in Java). AFAIK,JAR 就像 .class 文件的集合(就像在 Java 中一样)。

AAR are JAR files + resources. AAR 是 JAR 文件 + 资源。 But what's its usage case?但它的用例是什么? To be used to distribute development libraries for Android?用于分发 Android 的开发库?

APK seems to be similar to packages like .deb or .rpm. APK 似乎类似于 .deb 或 .rpm 之类的软件包。 Is it the only way to install applications on Android?这是在 Android 上安装应用程序的唯一方法吗?

What about DEX files? DEX 文件呢? Compiled applications... but what's the difference with a JAR or AAR file?已编译的应用程序...但与 JAR 或 AAR 文件有什么区别?

Moreveor, when distributing .so (ie native code) files for Android, what's the best way to do it?此外,在为 Android 分发 .so(即本机代码)文件时,最好的方法是什么?

JAR (Java Archive) JAR(Java 档案)

JAR is a package file format designed for distribution of Java application on its platform. JAR 是一种包文件格式,设计用于在其平台上分发 Java 应用程序。 It contains compiled Java class files + some more files like MANIFEST.它包含已编译的 Java 类文件 + 一些其他文件,如 MANIFEST。 Basically it is just an ZIP archive with some restrictions.基本上它只是一个有一些限制的 ZIP 档案。

DEX (Dalvik Executable) DEX(Dalvik 可执行文件)

DEX is binary file format, so it is compiled. DEX 是二进制文件格式,所以它被编译。 We could say, that .dex file is for DVM (Dalvik Virtual Machine) something like .class files for JVM.我们可以说, .dex文件用于 DVM(Dalvik 虚拟机),类似于 JVM 的.class文件。

DEX file format is really generated from java CLASS files by dex compiler from Android SDK. DEX 文件格式实际上是由 Android SDK 中的 dex 编译器从 java CLASS 文件生成的。 This compiler translates JVM bytecode to DVM bytecode and put all class files to one dex file.这个编译器将 JVM 字节码转换为 DVM 字节码,并将所有类文件放在一个 dex 文件中。

APK (Android Application Package) APK(安卓应用程序包)

APK is file format designed for distributing Android application on its platform. APK 是专为在其平台上分发 Android 应用程序而设计的文件格式。 It has some similarities with JAR format.它与 JAR 格式有一些相似之处。 Again it is simply just a ZIP archive, but APK files have pre-defined specific structure.同样,它只是一个 ZIP 存档,但 APK 文件具有预定义的特定结构。 For example, it always must contains file named AndroidManifest.xml and many more.例如,它必须始终包含名为AndroidManifest.xml 的文件等等。 Also this package aggregates compiled classes in dex format.这个包也以 dex 格式聚合编译的类。

AAR AAR

AAR is the binary distribution of an Android Library Project. AAR 是 Android 库项目的二进制分发版。 It has similar structure as APK.它具有与 APK 相似的结构。

JAR are just like a collection of .class files (like in Java). JAR 就像 .class 文件的集合(就像在 Java 中一样)。

That is because it is a Java JAR.那是因为它一个 Java JAR。

AAR are JAR files + resources AAR 是 JAR 文件 + 资源

Correct.正确的。

But what's its usage case?但它的用例是什么? To be used to distribute development libraries for Android?用于分发 Android 的开发库?

Correct.正确的。

APK seems to be similar to packages like .deb or .rpm. APK 似乎类似于 .deb 或 .rpm 之类的软件包。 Is it the only way to install applications on Android?这是在 Android 上安装应用程序的唯一方法吗?

Generally speaking, yes.一般来说,是的。

What about DEX files? DEX 文件呢?

DEX files contain the cross-compiled Dalvik bytecodes representing the application code. DEX 文件包含表示应用程序代码的交叉编译的 Dalvik 字节码。 Developers write Java, but Android runs Dalvik bytecodes.开发人员编写Java,但 Android运行Dalvik 字节码。 In the APK, you will find a DEX file representing those bytecodes.在 APK 中,您会找到一个表示这些字节码的 DEX 文件。

Moreveor, when distributing .so (ie native code) files for Android, what's the best way to do it?此外,在为 Android 分发 .so(即本机代码)文件时,最好的方法是什么?

I do not know what you mean by "distributing".我不知道你所说的“分发”是什么意思。

If you mean "distributing an app", your .so files will be in the APK.如果您的意思是“分发应用程序”,那么您的.so文件将位于 APK 中。

If you mean "distributing as a library for other developers", use an AAR or just an Android project in source form.如果您的意思是“作为库分发给其他开发人员”,请使用 AAR 或仅使用源代码形式的 Android 项目。

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

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