实现资源的云端分发
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
警告:Google Play 免安装体验将不再可用。自 2025 年 12 月起,将无法再通过 Google Play 发布免安装应用,并且所有 Google Play 服务免安装体验 API 将停止运行。Play 将不再通过任何机制向用户提供免安装应用。
自推出 Google Play Instant 以来,我们一直在不断投资改进生态系统,因此决定根据开发者的反馈做出此项变更。
若要继续优化以促进用户增长,我们建议开发者使用深层链接将用户引导至其常规应用或游戏,并在适当的时候将用户重定向到特定历程或功能。
在根据大小要求缩减应用时,请先尝试使用标准 APK 大小优化技巧。如果您需要进一步缩减大小,可能需要依靠资源的云端分发。本文档介绍了进行资源云端分发之前的准备工作以及各种游戏引擎提供的支持选项。尽管本页面上的指南侧重于游戏,但这些原则适用于包含大型资源的所有应用。
准备
在思考拆分应用以进行资源的云端分发时,应考虑如何根据需要将应用文件提供给用户的时间,将这些文件分割为多个部分。这样从时间上考虑往往将资源分为以下三个类别:始终需要、启动时需要和稍后需要的资源。
始终需要
有些资源很难拆分成较小的块,或者需要捆绑在基础 APK 中。游戏代码及其库或引擎依赖项就属于这类资源。尽管 Google Play 核心支持代码 app bundle,但许多引擎不支持稍后下载代码。
启动时需要
游戏启动后,用户应该能够立即开始玩游戏。Google Play 免安装体验要求使用 LTE 或 4G 连接的用户能够在 15 秒内开始玩您的游戏(请参阅 Google Play 免安装体验核对清单)。因此,您应将启动后的所有辅助下载限制为不超过支持初始体验所需的大小。例如,可在启动后立即快速下载的内容中包括第一个游戏关卡和位置资源,或运行游戏的前几分钟所需的全部代码。
稍后需要
可以稍后在后台根据需要下载的所有资源都属于此类别。此类别包含了玩的时间较长的游戏的大多数资源。稍后下载这些资源有助于尽可能地减小应用大小。
引擎支持
资源云端分发是使您的游戏突破免安装游戏的 15MB 大小限制的主要方式。是否支持下载资源因游戏引擎而异。下面给出了最常见的情况以及资源托管选项。
请注意,启动时所需的资源越少,用户进入游戏的速度就越快,这样可以降低游戏首次启动时的放弃率,提高玩家的留存率。
Play 功能分发(通过 App Bundle)
如果要将应用发布为 app bundle(这是首选方法),您可以使用功能模块获取基础 APK 以外的其他资源。对于免安装应用,每个功能模块都必须在清单中设置 dist:instant="true"
。不得使用 dist:on-demand
属性;该属性主要用于安装式应用 APK 中的按需模块。此外,无论模块是否包含代码,每个功能模块的大小都必须小于免安装应用 APK 的 15MB 大小限制。如果不能将每个模块的大小保持在此限制范围以内,将无法发布到 Alpha 版或发布轨道。正确配置后,您就可以使用 PlayCore 库在运行时获取功能模块。
Cocos Creator
Cocos 从 v2.0.4 版开始支持资源的云端分发。Cocos 会按需下载资源,如果未能及时下载资源,则显示占位符。由于 Cocos 本身不提供托管服务,因此由 Cocos 生成的资源文件必须由某种在线服务托管。
Unity
Unity 5.6、2017.4 或 2018.2 版的 Unity Google Play 免安装体验插件支持资源的云端分发。Unity 的更高版本对于进行引擎剥离更加有利,因此为了释放更多空间,最好迁移到更高版本。Unity 云端资源托管在 Unity 为您创建的 AssetBundle
文件中。将这些文件上传到云端服务器可实现资源的云端分发,因为 Unity 原本就支持下载 asset bundle。
其他引擎
无论您使用自定义引擎还是多种原生库的集合,您的选择都可以开箱即支持资源的云端下载。如果您有足够多的资源需要从云端下载,则需要编写代码或集成一种方法来按需下载游戏资源。最好从 Firebase Hosting 或 Firebase Cloud Storage API 入手。有些引擎提供简单的 HTTPS 文件获取功能,可能也能够满足您的需求。
托管资源
除非您使用 Google Play app bundle 通过 Play 下载资源,否则就需要将资源托管在其他位置。您可以按照自己的喜好使用任何服务来托管资源,只要能够提供合理的全球分布和可用性即可。Google Play 游戏应用的用户在世界各地玩游戏,因此必须快速地将云端托管的资源提供给他们,不管他们身在何处。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Implement cloud delivery of assets\n\n**Warning:** Google Play Instant will no longer be available. Starting December 2025,\nInstant Apps cannot be published through Google Play, and all\n[Google Play services Instant APIs](https://developers.google.com/android/reference/com/google/android/gms/instantapps/package-summary)\nwill no longer work. Users will no longer be served Instant Apps by Play using any\nmechanism.\n\nWe're making this change based on developer feedback and our continuous investments\nto improve the ecosystem since the introduction of Google Play Instant.\n\nTo continue optimizing for user growth, we encourage developers to refer users to\ntheir regular app or game, using [deeplinks](https://support.google.com/googleplay/android-developer/answer/12463044)\nto redirect them to specific journeys or features when relevant.\n\nWhen shrinking your app to fit the size requirements, first try the\n[standard APK size optimization techniques](/topic/google-play-instant/getting-started/game-instant-app#apk-size-reduction).\nIf you need to shrink the size down further, you might need to rely on cloud\ndelivery of assets. This document describes how to prepare assets for cloud\ndelivery and the support options from various game engines. While the guidance\non this page focuses on games, the principles apply to any app that contains\nlarge assets.\n\nPreparation\n-----------\n\nWhen thinking about breaking up your app for cloud delivery of assets, consider\nhow you can split your app files into sections based on *when* they need to be\navailable to the user. This timing tends to fall into the following three\ncategories: needed always, needed at launch, and needed later.\n\n### Needed always\n\nSome assets are difficult to separate into smaller blocks or are required to be bundled in the base APK.\nExamples include your game code and its library or engine dependencies. While\n[Google Play Core supports app bundles for code](/guide/app-bundle/playcore),\nmany engines don't support code downloaded later.\n\n### Needed at launch\n\nAfter the game starts, the user should be able to play immediately. Google Play Instant\nrequires that users can start playing your game in less than 15 seconds over an\nLTE or 4G connection (see the [Google Play Instant checklist](/topic/google-play-instant/tech-requirements#total-download-size)).\nTherefore, limit any secondary download after launch to be\nonly as large as necessary to support the initial experience. For example,\na fast-follow download immediately after launch might include the first game\nlevel and location assets, or any code required to run the first few minutes of gameplay.\n\n### Needed later\n\nAnything that you can afford to download later, in the background as needed,\nwill fall into this category. This category includes most assets for long-play\ngames. Downloading these assets later will help decrease the size of your app to\nas small as possible.\n\nEngine support\n--------------\n\nCloud asset delivery is the primary way to enable your game to go beyond the 15 MB limit for Instant play games.\nSupport for downloading assets will vary based on game engine. See the most\ncommon cases below, as well as options for hosting assets.\n\nNote that fewer needed-at-launch assets allow the user to get in the game\nfaster, which translates to lower drop-off and better player retention for that\nfirst launch.\n\n### Play Feature Delivery (through App Bundles)\n\nIf you publish your app as an app bundle (which is the preferred method), you\ncan use\n[feature modules](/guide/app-bundle/dynamic-delivery#customize_delivery)\nto fetch additional resources beyond the base APK. For your instant app, each\nfeature module must set `dist:instant=\"true\"` in the manifest. The\n`dist:on-demand` property should not be used; it is primarily used for on-demand\nmodules in installed APKs. Additionally, each feature module must be under\nthe instant APK limit of 15 MB, regardless of\nwhether or not the module contains code. Failure to keep each module under this\nlimit will prevent publishing to alpha or release tracks. Once properly\nconfigured, you can [fetch feature modules at runtime](/guide/playcore#request)\nusing the PlayCore library.\n\n### Cocos Creator\n\nCocos has supported cloud delivery of assets since\n[version v2.0.4](https://docs.cocos.com/creator/manual/en/publish/publish-android-instant.html).\nCocos downloads assets on demand, rendering placeholders if assets haven't been\ndownloaded in time. Cocos generates asset files that must be hosted with some\nonline service as Cocos does not provide one of its own.\n\n### Unity\n\nCloud delivery is supported in the\n[Unity Google Play Instant Plugin](https://github.com/google/play-instant-unity-plugin)\nfor Unity versions 5.6, 2017.4, or 2018.2. Later versions of Unity offer more\nbenefits for engine stripping, so they may be beneficial to migrate to in order\nto free more space. Unity cloud assets are hosted in `AssetBundle` files that\nUnity creates for you. Uploading these to a cloud server enables cloud delivery\nof assets, as Unity has innate support for\n[downloading asset bundles](https://docs.unity3d.com/540/Documentation/Manual/DownloadingAssetBundles.html).\n\n### Other engines\n\nWhether you use a custom engine or a\ncollection of native libraries, your choice might support cloud downloading of\nassets out of the box. If you have enough assets that you need to\ndownload them off of the cloud, then you'll need to code or integrate a way to\ndownload assets on demand for your game. The\n[Firebase Hosting](https://firebase.google.com/docs/hosting/) or\n[Firebase Cloud Storage APIs](https://firebase.google.com/docs/storage/) are\ngood places to start. Some engines offer simple HTTPS file fetching that might\nbe enough for your needs as well.\n\nHosting assets\n--------------\n\nUnless you're using Google Play [app bundles](/guide/app-bundle/playcore) to\ndownload your assets through Play, you'll need to host your assets elsewhere.\nYou're free to host them with any service you'd like as long as it has a\nreasonable global distribution and availability. Google Play Games app users play\naround the world, so cloud-hosted assets need to be served to them quickly in\nany location."]]