在添加ML套件以在Android上翻译API后,其应用程序尺寸却大大增加
添加MLKIT翻译API 实现'com.google.mlkit:翻译:17.0.0'
我的应用程序大小急剧增加。
我的主要应用程序尺寸是添加MLKIT后发行版本的12MB,现在是35MB。如何降低我的应用程序大小?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,并将该功能添加到我的应用程序中增加了我的应用程序大小约50%,尽管基于官方的Google文档,但不应该为应用程序大小做出贡献,因为Google ML Kit语言翻译API支持安装路径已在动态下载中分类,不必为应用程序大小做出贡献。但是看来这种应用程序的大小增加是由于基本库的大小而不是每个语言模型的单个。
但是,有多种方法可以减少应用程序大小,例如:
通过Google Play或任何其他支持应用程序捆绑包的商店构建应用程序为Android App Bundle特定的CPU体系结构)
将可选的ML功能移动到动态功能模块因此,Google Play可以使您的应用程序的某些功能有条件地交付或按需下载。
排除未使用的ML套件二进制文件
文件(App Bundle)可以大大降低您的应用程序大小,因为我们目前有4个主要的CPU架构和Google ML Kit Translation库每个体系结构使用约6 MB,因此您可以提供Google Play商店,因此可以提供您的应用程序的用户版本与他们的设备体系结构匹配,这减少了图书馆使用的额外空间,该空间约为3/4! ”
android studio apk Analyzer
它值得指出的是,在您的应用程序中,
进一步的文档链接:
https://developers.google.com/ml-kit/提示/安装路径
I ran into the same problem, and adding that functionality to my app increased my app size about 50%, although based on official google documentation, it wasn't supposed to be contributing to app size, because google ml kit language translation api supported installation path is categorized in dynamically downloaded and it doesn't have to be contributing to the app size; but it looks like that this app size increase is due to the base library size and not individual per language models.
However there are multiple ways to reduce app size such as :
Building your app as android app bundle, by that google play or any other store that support app bundles can provide users version of your application that matches their device specification (e.g. their specific CPU architecture)
Move optional ML features to dynamic feature modules so that google play can allow certain features of your app to be delivered conditionally or downloaded on demand.
Exclude unused ML Kit binaries
The first solution (building as app bundle) can reduce your app size significantly, because we currently have 4 major CPU architectures and google ml kit translation library uses about 6 MB per architecture, so you trough google play store can provide users version of your app that matches their device architecture and this reduces the extra space that is used by library about 3/4 !, i will post a screenshot for different elements that contributed to my app size below (note how much space is used for translation library per architecture):
Android studio APK analyzer
It worth noted that solutions above mostly requires your app to be release through google play store (or any other store that support this functionality).
Further document links:
https://developers.google.com/ml-kit/tips/installation-paths
https://developers.google.com/ml-kit/tips/reduce-app-size