java Android中AAR、JAR、DEX、APK的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33533370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between AAR, JAR, DEX, APK in Android
提问by sapito
In Android systems or development enviroments, what are the differences between AAR, JAR, DEX, and APK files? What is the purpose of each one?
在Android系统或开发环境中,AAR、JAR、DEX、APK文件有什么区别?每一项的目的是什么?
AFAIK, JAR are just like a collection of .class files (like in Java).
AFAIK,JAR 就像 .class 文件的集合(就像在 Java 中一样)。
AAR are JAR files + resources. But what's its usage case? To be used to distribute development libraries for Android?
AAR 是 JAR 文件 + 资源。但它的用例是什么?用于分发 Android 的开发库?
APK seems to be similar to packages like .deb or .rpm. Is it the only way to install applications on Android?
APK 似乎类似于 .deb 或 .rpm 之类的软件包。这是在 Android 上安装应用程序的唯一方法吗?
What about DEX files? Compiled applications... but what's the difference with a JAR or AAR file?
DEX 文件呢?已编译的应用程序...但与 JAR 或 AAR 文件有什么区别?
Moreveor, when distributing .so (i.e. native code) files for Android, what's the best way to do it?
此外,在为 Android 分发 .so(即本机代码)文件时,最好的方法是什么?
回答by hradecek
JAR (Java Archive)
JAR(Java 档案)
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.
JAR 是一种包文件格式,设计用于在其平台上分发 Java 应用程序。它包含编译的 Java 类文件 + 一些更多的文件,如 MANIFEST。基本上它只是一个有一些限制的 ZIP 档案。
DEX (Dalvik Executable)
DEX(Dalvik 可执行文件)
DEX is binary file format, so it is compiled. We could say, that .dexfile is for DVM (Dalvik Virtual Machine) something like .classfiles for JVM.
DEX 是二进制文件格式,所以它被编译。我们可以说,.dex文件用于 DVM(Dalvik 虚拟机),类似于JVM 的.class文件。
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.
DEX 文件格式实际上是由 Android SDK 中的 dex 编译器从 java CLASS 文件生成的。这个编译器将 JVM 字节码转换为 DVM 字节码,并将所有类文件放在一个 dex 文件中。
APK (Android Application Package)
APK(安卓应用程序包)
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.xmland many more. Also this package aggregates compiled classes in dex format.
APK 是专为在其平台上分发 Android 应用程序而设计的文件格式。它与 JAR 格式有一些相似之处。同样,它只是一个 ZIP 存档,但 APK 文件具有预定义的特定结构。例如,它必须始终包含名为AndroidManifest.xml 的文件等等。这个包也以 dex 格式聚合编译的类。
AAR
AAR
AAR is the binary distribution of an Android Library Project. It has similar structure as APK.
AAR 是 Android 库项目的二进制分发版。它具有与 APK 相似的结构。
回答by CommonsWare
JAR are just like a collection of .class files (like in Java).
JAR 就像 .class 文件的集合(就像在 Java 中一样)。
That is because it isa 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. Is it the only way to install applications on Android?
APK 似乎类似于 .deb 或 .rpm 之类的软件包。这是在 Android 上安装应用程序的唯一方法吗?
Generally speaking, yes.
一般来说,是的。
What about DEX files?
DEX 文件呢?
DEX files contain the cross-compiled Dalvik bytecodes representing the application code. Developers writeJava, but Android runsDalvik bytecodes. In the APK, you will find a DEX file representing those bytecodes.
DEX 文件包含表示应用程序代码的交叉编译的 Dalvik 字节码。开发人员编写Java,但 Android运行Dalvik 字节码。在 APK 中,您会找到一个表示这些字节码的 DEX 文件。
Moreveor, when distributing .so (i.e. 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 项目。