הפחתת עלויות הנתונים למיליארדים
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
במדינות מסוימות, תוכניות נתונים יכולות לעלות יותר מ-10% מההכנסה החודשית הממוצעת של משתמש. המשמעות היא שצמצום גודל ההורדה של האפליקציה והאפשרות למשתמשים לשלוט באופן השימוש של האפליקציה בנתונים יכולים להניב תועלת גדולה ומוחשית למשתמשים רבים. הקטנת גודל ההורדה גם עוזרת לחסוך מקום באחסון הפנימי, שהוא משאב מוגבל במכשירים מסוימים.
ריכזנו כאן כמה אסטרטגיות שיעזרו לכם לבצע אופטימיזציה של כמות הנתונים שהאפליקציה משתמשת בהם, גם ברשת וגם באחסון הפנימי.
הקטנת גודל האפליקציה
הקטנת גודל האפליקציה היא אחת הדרכים הבסיסיות לעזור למשתמשים לצרוך פחות נתונים, גם נתונים ברשת וגם אחסון פנימי. בקטע הזה מתוארות כמה גישות להקטנת גודל האפליקציה.
הקטנת הגודל של נכסים גרפיים ב-APK
- נכסים גרפיים הם בדרך כלל המרכיב הכבד ביותר במשקל של קובץ ה-APK. אופטימיזציה של הנכסים האלה יכולה להקטין את גודל ההורדות וכך לקצר את זמני ההתקנה למשתמשים.
- לנכסים גרפיים כמו סמלים, צריך להשתמש בפורמט Scalable Vector Graphics (SVG).
הגודל של תמונות SVG קטן מאוד בהשוואה לגרפיקת מפת סיביות, ואפשר לעבד אותן בזמן ריצה בכל רזולוציה. ספריית התמיכה של Android מספקת הטמעה עם תאימות לאחור של משאבי וקטור ל-Android 2.1 (רמת API 7).
במאמר הזה ב-Medium מוסבר איך מתחילים להשתמש בווקטורים.
- לתמונות שאינן וקטוריות, כמו תמונות, כדאי להשתמש בפורמט WebP כדי לקצר את זמני הטעינה של התמונות ולחסוך ברוחב הפס של הרשת. הוכח שפורמט WebP יוצר קבצים קטנים יותר מאלה של PNG ו-JPG, עם איכות תמונה זהה לפחות. גם בהגדרות עם אובדן נתונים, WebP יכול ליצור תמונה כמעט זהה למקור. Android כולל תמיכה ב-WebP עם דחיסה אובדת נתונים מאז Android 4.0 (רמת API 14: Ice Cream Sandwich) ותמיכה ב-WebP ללא דחיסה אובדת נתונים ושקוף מאז Android 4.2 (רמת API 17: Jelly Bean).
- אם יש לכם הרבה תמונות גדולות בכמה צפיפויות, כדאי להשתמש בתמיכה בכמה חבילות APK כדי לפצל את חבילת ה-APK לפי צפיפות. כתוצאה מכך, נוצרים קובצי build שמיועדים לצפיפויות מסוימות, כך שמשתמשים עם מכשירים בצפיפות נמוכה לא יצטרכו לשלם את המחיר של הורדת נכסים בצפיפות גבוהה שלא נמצאים בשימוש.
- מידע נוסף על הקטנת גודל ה-APK זמין במאמרים הקטנת גודל ה-APK והקטנת הקוד והמשאבים. בנוסף,
בסדרת הפוסטים הזו ב-Medium יש מדריך מפורט לצמצום הגודל של קובץ APK.
הקטנת גודל הקוד
- כל ספרייה בפרויקט Android מוסיפה קוד שלא בשימוש לחבילת ה-APK. כדאי להיזהר במיוחד כשמשתמשים בספריות חיצוניות, כי לא כל הספריות מיועדות לשימוש באפליקציות לנייד. מוודאים שהספריות שבהן האפליקציה משתמשת מותאמות לשימוש בנייד.
- כדאי לבצע אופטימיזציה של הקוד המהודר באמצעות כלי כמו ProGuard. ProGuard מזהה קוד שלא נמצא בשימוש ומסיר אותו מחבילת ה-APK. בנוסף,
מפעילים כיווץ משאבים בזמן ה-build על ידי הגדרת
minifyEnabled=true
, shrinkResources=true
ב-build.gradle
– כך המערכת מסירה אוטומטית משאבים שלא נמצאים בשימוש מה-APK.
- כשמשתמשים בשירותי Google Play, צריך
לכלול באופן סלקטיבי רק את ממשקי ה-API הדרושים ב-APK.
- מידע נוסף על צמצום גודל הקוד בחבילת ה-APK זמין בהדרכה בנושא Android איך להימנע משימוש במסגרות להזרקת תלות.
אפשר להעביר את האפליקציה לאחסון חיצוני (SD)
- במכשירים זולים יש לרוב נפח אחסון קטן. המשתמשים יכולים להרחיב את האחסון באמצעות כרטיסי SD, אבל האפליקציות צריכות להצהיר במפורש שהן תומכות בהתקנה באחסון חיצוני לפני שהמשתמשים יוכלו להעביר אותן.
- כדי לאפשר התקנה של האפליקציה באחסון חיצוני, צריך להשתמש בדגל
android:installLocation
בקובץ AndroidManifest.xml. מידע נוסף על הפעלת האפשרות להעברת האפליקציה לאחסון חיצוני זמין במדריך Android בנושא מיקום התקנת האפליקציה.
הפחתת השימוש בדיסק של האפליקציה אחרי ההתקנה
- אם האפליקציה שלכם לא תתפוס הרבה מקום בדיסק, יש סיכוי נמוך יותר שהמשתמשים יסירו אותה כשהמכשיר שלהם יתמלא. חשוב להגדיר גבולות למטמון כדי למנוע את הגדלת השימוש בדיסק של האפליקציה ללא הגבלה. חשוב להקפיד להכניס את הנתונים שבמטמון לתיקייה
getCacheDir()
– המערכת יכולה למחוק קבצים שמוצבים כאן לפי הצורך, כך שהם לא יופיעו כנתונים שנשמרו באפליקציה.
הצעת שימוש ברשת שניתן להגדרה
פלטפורמת Android כוללת מספר דרכים שבהן אפשר לתת למשתמשים שליטה על השימוש ברשת של האפליקציה, ולבצע אופטימיזציה של השימוש הזה בהתאם לצרכים שלהם. לדוגמה,
בשימוש הראשון, האפליקציה יכולה להציג למשתמש מגוון הגדרות שקשורות לרשת.
אפשר גם לספק מסך העדפות רשת מחוץ לאפליקציה.
יצירת חוויות הצטרפות לרשתות של המשתמשים
- אפליקציות שמאפשרות למשתמשים לצמצם את השימוש בנתונים מתקבלות בברכה, גם אם יש להן דרישות גבוהות לנתונים. אם האפליקציה שלכם משתמשת ברוחב פס משמעותי (לדוגמה, אפליקציות להזרמת וידאו), אתם יכולים לספק למשתמשים חוויה של התחלת שימוש שתאפשר להם להגדיר את השימוש ברשת. לדוגמה,
אתם יכולים לאפשר למשתמש להפעיל בכוח סטרימינג של סרטונים עם קצב העברת נתונים נמוך יותר ברשתות סלולריות.
- הגדרות נוספות שמאפשרות למשתמשים לשלוט בסנכרון הנתונים, באחזור מראש ובאופן השימוש ברשת (למשל, אחזור מראש של כל קטגוריות החדשות המסומנות בכוכב רק ב-Wi-Fi) עוזרות למשתמשים להתאים את אופן הפעולה של האפליקציה לצרכים שלהם.
- מידע נוסף על ניהול השימוש ברשת זמין בהדרכה בנושא Android ניהול השימוש ברשת.
הצגת מסך העדפות רשת
- אפשר לעבור להגדרות הרשת של האפליקציה מחוץ לאפליקציה באמצעות מסך העדפות הרשת. אפשר להציג את המסך הזה מהמסך של הגדרות המערכת או מהמסך של השימוש בנתונים של המערכת.
- כדי לספק מסך העדפות רשת שהמשתמשים יכולים לגשת אליו מתוך האפליקציה וגם מהגדרות המערכת, צריך לכלול באפליקציה פעילות שתומכת בפעולה
ACTION_MANAGE_NETWORK_USAGE
.
- מידע נוסף על הוספת מסך הגדרות רשת זמין בהדרכה בנושא Android בנושא
הטמעה של פעילות הגדרות.
מקורות מידע נוספים
כדי לקבל מידע נוסף על הנושא הזה, אפשר לעיין במקורות המידע הנוספים הבאים:
פוסטים בבלוג
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[null,null,["עדכון אחרון: 2025-07-27 (שעון UTC)."],[],[],null,["# Reduced data cost for billions\n\n\u003cbr /\u003e\n\n\nData plans in some countries can cost upwards of 10% of a typical user's monthly income. This\nmeans that minimizing your app's download size and letting the user control how your app uses\ndata can have a large, tangible benefit to many users. Minimizing download size also helps\nconserve space in internal storage, which is a scarce resource in some devices.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\nHere you can find some strategies to help optimize the amount of data your app uses, both over\nthe network and in internal storage.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nReduce app size\n---------------\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\nReducing app size is one of the fundamental ways you can help your user consume less data, in\nterms of both network data and internal storage. This section describes several approaches to\nreducing app size.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Reduce APK graphical asset size\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n- Graphical assets are often the largest contributor to the size of the APK. Optimizing these can result in smaller downloads and thus faster installation times for users.\n- For graphical assets such as icons, use the Scalable Vector Graphics (SVG) format. SVG images are tiny in size compared to bitmap graphics and can be rendered at runtime to any resolution. The [Android Support Library](/tools/support-library) provides a backward-compatible implementation for vector resources to Android 2.1 (API level 7). Get started with vectors with [this Medium post](https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88).\n- For non-vector images, such as photos, use [WebP](https://developers.google.com/speed/webp/) to reduce image load times and save network bandwidth. WebP is proven to result in smaller file sizes than its PNG and JPG counterparts, with at least the same image quality. Even at lossy settings, WebP can produce a nearly identical image to the original. Android has included lossy WebP support since Android 4.0 (API level 14: Ice Cream Sandwich) and support for lossless, transparent WebP since Android 4.2 (API level 17: Jelly Bean).\n- If you have many large images across multiple densities, consider using [Multiple\n APK support](/google/play/publishing/multiple-apks) to split your APK by density. This results in builds targeted for specific densities, meaning users with low-density devices won't have to incur the penalty of downloading unused high-density assets.\n- For more information about reducing APK size, see [Reduce APK Size](/topic/performance/reduce-apk-size) and [Shrink Your Code and Resources](/studio/build/shrink-code). In addition, you can find a detailed guide on reducing APK size in this [series of Medium posts](https://medium.com/@wkalicinski/smallerapk-part-4-multi-apk-through-abi-and-density-splits-477083989006).\n\n### Reduce code size\n\n- Every library in your Android project is adding potentially unused code to the APK. Be particularly careful about using external libraries because not all libraries are designed for use in mobile apps. Ensure that the libraries your app is using are optimized for mobile use.\n- Consider optimizing your compiled code using a tool such as [ProGuard](/tools/help/proguard). ProGuard identifies code that isn't being used and removes it from your APK. Also [enable resource shrinking](http://tools.android.com/tech-docs/new-build-system/resource-shrinking) at build time by setting `minifyEnabled=true`, `shrinkResources=true` in `build.gradle`---this automatically removes unused resources from your APK.\n- When using Google Play services, you should [selectively include](/google/play-services/setup#add_google_play_services_to_your_project) only the necessary APIs into your APK.\n- For more information on reducing code size in your APK, see the Android training on how to [Avoid\n dependency injection frameworks](/training/articles/memory#DependencyInjection).\n\n### Allow app to be moved to external (SD) storage\n\n- Low-cost devices often come with little on-device storage. Users can extend this with SD cards; however, apps need to explicitly declare that they support being installed to external storage before users can move them.\n- Allow your app to be installed to external storage using the [`\n android:installLocation`](/guide/topics/manifest/manifest-element#install) flag in your AndroidManifest.xml. For more information on enabling your app to be moved to external storage, see the Android guide on [App Install\n Location](/guide/topics/data/install-location).\n\n\u003cbr /\u003e\n\n### Reduce post-install app disk use\n\n\u003cbr /\u003e\n\n- Keeping your app's disk use low means that users are less likely to uninstall your app when the device is low on free space. It's important to apply bounds around your caches---this prevents your app's disk use from growing indefinitely. Be sure you put your cached data in [getCacheDir()](/reference/android/content/Context#getCacheDir())---the system can delete files placed here as needed, so they won't show up as storage committed to the app.\n\n\u003cbr /\u003e\n\nOffer configurable network use\n------------------------------\n\n\nThe Android platform includes a number of ways you can give the user control\nover your app's network use, optimizing it for their own needs. For example,\non first use, your app can walk the user through a variety of network-related settings.\nYou can also provide a network preferences screen from outside the app.\n\n### Provide onboarding experiences for users' network\nchoices\n\n\u003cbr /\u003e\n\n- Apps that allow users to reduce data use are well received, even if they have heavy data requirements. If your app uses a considerable amount of bandwidth (for example, video streaming apps), you can provide an onboarding experience for users to configure network use. For example, you could allow the user to force lower-bitrate video streams on cellular networks.\n- Additional settings for users to control data syncing, prefetching, and network use behavior (for example, prefetch all starred news categories on Wi-Fi only), also help users tailor your app's behavior to their needs.\n- For more information on managing network use, see the Android training on [Managing\n Network Usage](/training/basics/network-ops/managing).\n\n### Provide a network preferences\nscreen\n\n- You can navigate to the app's network settings from outside the app by means of a network preferences screen. You can invoke this screen from either the system settings screen or the system data usage screen.\n- To provide a network preferences screen that users can access from within your app as well as from the system settings, in your app include an activity that supports the [ACTION_MANAGE_NETWORK_USAGE](/reference/android/content/Intent#ACTION_MANAGE_NETWORK_USAGE) action.\n- For further information on adding a network preferences screen, see the Android training on [Implementing a Preferences Activity](/training/basics/network-ops/managing#prefs).\n\n\u003cbr /\u003e\n\nAdditional resources\n--------------------\n\nTo learn more about this topic, view the following additional resources:\n\n### Blog posts\n\n- [Nurture trust through cost transparency](https://medium.com/google-design/nurture-trust-through-cost-transparency-b61a5947d2fc)"]]