osgi bundles

    科技2022-07-31  122

    osgi bundles

    When building Android apps, you’ll be facing a myriad of different file formats and terminology. Particularly when exporting the final version of your app, you’ll be seeing two main output formats. In this article, we’ll compare Android App Bundle versus APK, which are composed of DEX files. But what do all these acronyms mean?

    在构建Android应用时,您将面临各种各样的文件格式和术语。 特别是在导出应用的最终版本时,您会看到两种主要的输出格式。 在本文中,我们将比较由DEX文件组成的Android App Bundle与APK。 但是所有这些首字母缩写词是什么意思?

    首字母缩写词含义 (Acronym meaning)

    Before digging deeper into the topics, it’s important to get the definition of each of the above-mentioned formats:

    在深入探讨主题之前,重要的是要获得上述每种格式的定义:

    AAB: Android App Bundle

    AAB: Android应用包

    APK: Android App Package

    APK: Android应用包

    DEX: Dalvik EXecutable

    DEX: Dalvik可执行文件

    APK:Android应用程序包 (APK: Android Application Package)

    Let’s begin by reviewing this format as it’s the one that’s most known and has been around for the longest time. As mentioned above, APK stands for Android App Package. An APK is basically a file that’s ready to be installed on a user’s device.

    让我们首先回顾一下这种格式,因为它是最著名的格式,并且使用时间最长。 如上所述,APK代表Android App Package 。 APK基本上是可以安装在用户设备上的文件。

    APKs have all of the app’s files and code inside. You can think of it as a .zip file but with its own particular extension. Just as you can find compressed files with extensions in .rar or .zip, you can have .apk. It’s mainly understood by the Android platform, but other platforms could support it if they had the same underlying architecture as Android does.

    APK包含所有应用程序的文件和代码。 您可以将其视为.zip文件,但具有自己的特定扩展名。 正如可以在.rar或.zip找到带有扩展名的压缩文件一样,您也可以具有.apk 。 Android平台主要了解它,但是如果其他平台具有与Android相同的基础架构,则其他平台可以支持它。

    Photo by Charles Deluvio on Unsplash Charles Deluvio在 Unsplash上 拍摄的照片

    The APK is already signed with the app’s certificate, which is a file that identifies every app in the Play Store. This file has to be kept by the developers throughout the life of the app, as it’s not possible to generate it again.

    APK已使用应用程序的证书签名,该证书是一个可识别Play商店中每个应用程序的文件。 开发人员必须在应用程序的整个生命周期中保留此文件,因为无法再次生成该文件。

    AAB:Android应用程序捆绑包 (AAB: Android Application Bundle)

    AAB, which stands for Android Application Bundle, is a more recent format for Android distribution. Android’s official documentation gives the following definition:

    AAB代表Android应用程序捆绑包 ,是一种用于Android发行版的更新格式。 Android的官方文档给出以下定义:

    “An Android App Bundle is a publishing format that includes all your app’s compiled code and resources, and defers APK generation and signing to Google Play.”

    “ Android应用程序捆绑包是一种发布格式,其中包含您应用程序的所有已编译代码和资源,并推迟了APK的生成和对Google Play的签名。”

    These application bundles are fairly new — they were introduced in Google I/O 2018. They’re about to get two years old. But ever since, they’ve become the official format for publishing Android apps.

    这些应用程序包是相当新的-它们是在Google I / O 2018中引入的。它们将诞生两年了。 但是从那以后,它们已经成为发布Android应用程序的官方格式。

    Just as APK is an extension, AAB files also have the extension .aab. The Android documentation provides an image explaining how AABs are composed.

    就像APK是扩展名一样,AAB文件也具有扩展名.aab 。 Android文档提供了一张图片,解释了AAB的组成方式。

    Android documentation Android文档

    If you had an APK, you’d only have the orange part of the app, which will have inside of itself all the assets, meaning you can only have one pack of them and no dynamic features.

    如果您有APK,那么应用程序只有橙色部分,它将包含所有资产,这意味着您只能拥有其中的一包,而没有动态功能。

    资产包 (Asset Packs)

    Asset packs are groups of files targeted to a group of devices. When using a traditional APK, the app will receive all of the assets and just choose and use the ones that are necessary for that specific device.

    资产包是针对一组设备的文件组。 使用传统的APK时,该应用会收到所有资产,只需选择并使用该特定设备所需的资产即可。

    On the other hand, when using AAB, the Play Store selects the assets that’ll be needed when the user downloads the app.

    另一方面,在使用AAB时,Play商店会选择用户下载应用程序时所需的资产。

    动态功能 (Dynamic Features)

    These features are modules that may not be needed on the first install of the app. You can either download them when the user requests to add that functionality or download the app and then start downloading them in the background to give the user a head start on using your app.

    这些功能是首次安装应用程序时可能不需要的模块。 您可以在用户请求添加该功能时下载它们,也可以下载该应用程序,然后在后台开始下载它们,从而使用户可以抢先使用您的应用程序。

    To install dynamic features, we have the SplitInstallManager that’ll be managed by the Play Core Library, which communicates directly to the Play Store.

    要安装动态功能,我们需要由Play核心库 (直接与Play商店通信)管理的SplitInstallManager。

    Android App Bundle与APK相比的优势 (Advantages of Android App Bundle vs. APK)

    Android stresses several disadvantages of using APKs:

    Android强调了使用APK的几个缺点:

    Lower conversion rates

    较低的转换率 Slower downloads

    下载速度较慢 Higher uninstalls

    更高的卸载 Lower update rates

    降低更新率

    尺寸 (Size)

    The first advantage is the size reduction. With asset packs and dynamic features, apps become, in average, 35% smaller. But some apps have gotten a decrease in size of around 50%.

    第一个优点是尺寸减小。 借助资产包和动态功能,应用平均缩小了35%。 但是某些应用程序的大小减少了约50%。

    After the introduction of AABs, the maximum size of an app is 150 MB. By using an APK, you can easily surpass this requirement.

    引入AAB后,应用程序的最大大小为150 MB。 通过使用APK,您可以轻松超越此要求。

    Photo by Rob Hampson on Unsplash Rob Hampson在 Unsplash上 拍摄的照片

    未压缩的本机库 (Uncompressed native libraries)

    For some reason, when you have an APK, the app gets a copy of all the native libraries that are needed in a compressed format. After the download, the device decompresses those libraries by creating a copy because it can’t use them without decompression. In the end, you’ll have two copies of the library.

    出于某种原因,当您拥有APK时,该应用会以压缩格式获取所需的所有本机库的副本。 下载后,设备将通过创建副本来解压缩这些库,因为如果不进行解压缩就无法使用它们。 最后,您将拥有该库的两个副本。

    When comparing Android App Bundle versus the APK, you’ll notice the AAB gets uncompressed native libraries by default, which will help you avoid having two copies in the end.

    比较Android App Bundle和APK时,您会注意到AAB默认情况下会获得未压缩的本机库,这将帮助您避免最终获得两个副本。

    You might be wondering why the APK keeps both a copy of the compressed version and another for the uncompressed. This, as the above-mentioned identifies, is because the libraries are sometimes device-specific. You may need a different one for each device, which the Play Store can send to the device on download time if you’re providing an AAB.

    您可能想知道为什么APK同时保留压缩版本的副本和未压缩版本的副本。 如上所述,这是因为这些库有时是特定于设备的。 您可能需要为每台设备使用不同的设备,如果您提供的是AAB,则Play商店可以在下载时将其发送到该设备。

    那DEX文件呢? (What About DEX Files?)

    Both APKs and AABs contain DEX files inside. Those files are the key to executing the code. These files are Dalvik EXecutable because inside the core of Android, there’s something called the Dalvik Virtual Machine. In simpler words, this VM executes the code of the apps in Android to make them available to you.

    APK和AAB都在其中包含DEX文件。 这些文件是执行代码的关键。 这些文件是Dalvik EXecutable的,因为在Android的核心内部有一个称为Dalvik虚拟机的东西。 简而言之,此VM执行Android中应用程序的代码,以使您可以使用它们。

    专业提示:DEX文件出错 (Pro tip: Error with DEX files)

    There’s a common error in Android Studio when building your project. This error is easy to fix but can be frustrating if you don’t know what it’s talking about. When trying to run the app, you’ll get a message like the following:

    建立专案时,Android Studio有一个常见错误。 该错误很容易修复,但是如果您不知道它在说什么,可能会令人沮丧。 尝试运行该应用程序时,您将收到如下消息:

    Cannot fit requested classes in a single dex file

    无法在单个dex文件中容纳请求的类

    If you’re also getting this error, go to build.gradle(Module: app), and inside the brackets of defaultConfig, add the following line:

    如果您也遇到此错误,请转到build.gradle(Module: app) ,并在defaultConfig括号内,添加以下行:

    multiDexEnabled true

    multiDexEnabled true

    Android Studio will request to sync the project, as it does every time you do a change in Gradle files. Do the Gradle sync, and run the app.

    Android Studio将请求同步项目,就像您每次更改Gradle文件一样。 执行Gradle同步,然后运行该应用程序。

    结论 (Conclusion)

    As you can see, comparing an Android App Bundle with an APK isn’t that complicated. App bundles have been around for almost two years, and they’re very useful to give users a better experience — so why not give them a try? I hope you add this to your next project.

    如您所见,将Android App Bundle与APK进行比较并不复杂。 应用程序捆绑已经存在了将近两年,它们对于给用户带来更好的体验非常有用-那么为什么不尝试一下呢? 希望您将此添加到下一个项目。

    Until next time!

    直到下一次!

    翻译自: https://medium.com/better-programming/android-app-bundles-vs-apks-8b0306b38436

    osgi bundles

    相关资源:jdk-8u281-windows-x64.exe
    Processed: 0.010, SQL: 8