Android 存档库 (aar) 与标准 jar [英] Android Archive Library (aar) vs standard jar

查看:15
本文介绍了Android 存档库 (aar) 与标准 jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读一些关于新采用 Gradle 作为 Android 应用程序的标准构建系统的文章.嗯,来自标准 Java 开发,我通常依赖 jar 文件来构建我的项目.然而,Android 似乎也有 aar 包,它们相当于 Windows 操作系统中的 dll 文件,正如前面提到的 此处:

I've been reading some articles about the new adoption of Gradle as the standard build system for Android apps. Well, coming from standard Java development I usually depend on jar files in order to build my project. However it seems that Android has also aar packages, which are the equivalent to the dll files in a Windows OS, as mentioned here:

首先,你必须意识到Android平台不允许应用级的共享库".在传统"编程语言平台中,C、C++、Java 等等,我们都有这种共享运行时库的机制.(例如,Windows 上的 DLL、Unix 上的 DSO、JVM 上的 Jar 等).但是,在 Android 上,您不能这样做,除非您是 Google 或手机制造商(请参阅下面的脚注 1).作为应用程序开发人员,这可能是一个基本限制.在构建时和运行时共享"或重用"代码是软件工程实践中非常重要的一部分.由于上述限制,这在 Android 上相当困难(并非不可能,只是更难).

First, you have to realize that the Android platform does not allow application-level "shared libraries". In the "traditional" programming language platforms, C, C++, Java, you name it, we have this mechanism of sharing runtime libraries. (E.g., DLL on Windows, DSO on Unix, Jar on JVM, etc.). On Android, however, you cannot do that, unless you are Google or a handset manufacturer (See Footnote 1 below). As an application developer, this can be a fundamental limitation. "Sharing" or "reusing" codes, both at build time and run time, is a very important part of software engineering practice. This is rather hard (not impossible, just harder) on Android because of the aforementioned limitation.

但是,我对这个概念有些怀疑.我的意思是,开发人员什么时候应该对在其应用程序中包含 aar 依赖项感兴趣?是否将此依赖项收紧到某些 SDK 最低版本?

However, I have some doubts around this concept. I mean, when should a developer be interested including aar dependencies in its application? Are this dependencies tightened to some SDK minimum version?

例如,在一个项目中,我访问了一个 COM 端口,我使用了 NDK预编译 .so 库.如果我想共享这个实用程序,我必须创建一个 aar 吗?

For example, in one project I access a COM port, which I use NDK precompiled .so libraries for. Do I have to create an aar if I want to share this utility?

推荐答案

AAR 文件更类似于 Jars 而不是 Dlls原因如下:

AAR files are more similar to Jars than to Dlls for the following reason:

Dlls 可以在应用程序之间共享,而 AARs 和 jars 是与您的应用打包在一起.

Dlls can be shared across applications where as AARs and jars are packaged in with your app.

AARs vs Jars:

JarAAR 的主要区别在于 AAR 包括资源,例如 layouts, drawables 等.这使它变得更容易创建独立的视觉组件.例如,如果你有使用相同登录屏幕的多个应用程序,您可以使用 Jars共享类而不是布局、样式等,你仍然必须复制它们.使用 AAR 将所有东西都捆绑在一个整洁的包中.

The main difference between a Jar and a AAR is that AARs include resources such as layouts, drawables etc. This makes it a lot easier to create self-contained visual components. For example if you have multiple apps that use the same login screen, with Jars you could share classes but not the layout, styles, etc., you still had to duplicate them. With AARs everything is bundled in one neat package.

总而言之,AAR是朝着正确方向迈出的一大步.

In conclusion, AARs are a big step in the right direction.

注意:
apk-lib 进行了类似的尝试,但它们现在已经过时了,因为 AAR 更好.

Note:
Similar attempts were made with apk-libs but they are now obsolete as AARs are much better.

这篇关于Android 存档库 (aar) 与标准 jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆