縮減 ML Kit Android 應用程式('s APK) 的大小
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用 ML Kit 裝置端模型發布應用程式到正式版前,建議您參考本頁的建議,縮減應用程式的下載大小。
將應用程式建構為 Android App Bundle
將應用程式建構並部署為 Android App Bundle,讓 Google Play 自動為特定螢幕密度、CPU 架構和語言產生 APK。使用者只需下載與裝置設定相符的 APK,最重要的是,使用者只會下載與裝置架構相符的原生程式碼程式庫。
進階:將選用的機器學習功能移至動態功能模組
如果您在應用程式的某項功能中使用 ML Kit,但這並非應用程式的主要用途,建議您重構應用程式,將該功能及其 ML Kit 依附元件移至動態功能模組。
如要讓 ML Kit 功能在隨選功能模組中運作,請在基礎 APK 的 build.gradle
檔案中,加入 ML Kit Play 商店動態功能支援程式庫依附元件。
dependencies {
// ...
implementation 'com.google.mlkit:playstore-dynamic-feature-support:16.0.0-beta2'
}
這樣做可避免使用者不必要地下載應用程式的 ML 模型,因為這些模型可能很大。
進階:排除未使用的機器學習套件二進位檔
ML Kit 支援 32 位元和 64 位元架構。如果您的應用程式只支援 32 位元模式 (例如,您使用的程式庫只提供 32 位元二進位檔),可以從建構作業中排除未使用的 ML Kit 程式庫:
android {
defaultConfig {
ndk {
// Don't package arm64-v8a or x86_64
abiFilters 'armeabi-v7a', 'x86'
}
}
}
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-10 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-10 (世界標準時間)。"],[[["\u003cp\u003eReduce your app's download size by building it as an Android App Bundle, enabling Google Play to deliver optimized APKs to users based on their device configurations.\u003c/p\u003e\n"],["\u003cp\u003eFor non-core ML features, leverage dynamic feature modules to deliver them on demand, minimizing the initial download size by excluding optional ML models.\u003c/p\u003e\n"],["\u003cp\u003eIf your app only supports 32-bit mode, exclude unused 64-bit ML Kit libraries to further reduce the app's size.\u003c/p\u003e\n"],["\u003cp\u003eTo enable ML Kit features in on-demand modules, include the \u003ccode\u003eplaystore-dynamic-feature-support\u003c/code\u003e library in your base APK's dependencies.\u003c/p\u003e\n"]]],[],null,[]]