ماژول پایه را پیکربندی کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
بسته نرم افزاری با APK متفاوت است، زیرا نمی توانید آن را در دستگاهی نصب کنید. در عوض، این یک قالب انتشار است که شامل تمام کدها و منابع کامپایل شده برنامه شما در یک آرتیفکت بیلد است. بنابراین، پس از اینکه بسته برنامه امضا شده خود را آپلود کردید، Google Play همه چیزهایی را که برای ساخت و امضای فایلهای APK برنامهتان نیاز دارد، و ارائه آنها به کاربران را دارد.
شروع کنید
اکثر پروژه های برنامه برای پشتیبانی از Android App Bundles به تلاش زیادی نیاز ندارند. دلیل آن این است که ماژول شامل کد و منابع برای APK پایه برنامه شما، ماژول استاندارد برنامه است که به طور پیشفرض هنگام ایجاد یک پروژه برنامه جدید در Android Studio دریافت میکنید. یعنی ماژولی که افزونه application
زیر را در فایل build.gradle
خود اعمال می کند، کد و منابع را برای عملکرد پایه برنامه شما ارائه می دهد.
شیار
// The standard application plugin creates your app's base module.
plugins {
id 'com.android.application'
}
کاتلین
plugins {
// The standard application plugin creates your app's base module.
id("com.android.application")
}
علاوه بر ارائه عملکرد اصلی برای برنامه شما، ماژول پایه همچنین بسیاری از پیکربندی های ساخت و ورودی های مانیفست را ارائه می دهد که بر کل پروژه برنامه شما تأثیر می گذارد.
پیکربندی ساخت ماژول پایه
برای اکثر پروژه های برنامه موجود، نیازی به تغییر چیزی در پیکربندی ساخت ماژول پایه خود ندارید. با این حال، اگر در نظر دارید ماژولهای ویژگی را به پروژه برنامه خود اضافه کنید یا اگر قبلاً برنامه خود را با استفاده از چندین APK منتشر کردهاید، برخی جنبهها در پیکربندی ساخت ماژول پایه وجود دارد که باید در نظر داشته باشید.
کد نسخه و به روز رسانی برنامه
با Android App Bundles، دیگر لازم نیست کدهای نسخه چندین APK را که در Google Play آپلود میکنید، مدیریت کنید. در عوض، همانطور که در زیر نشان داده شده است، فقط یک کد نسخه را در ماژول پایه برنامه خود مدیریت می کنید:
// In your base module build.gradle file
android {
defaultConfig {
…
// You specify your app’s version code only in the base module.
versionCode 5
versionName "1.0"
}
}
پس از آپلود بسته برنامه خود، Google Play از کد نسخه در ماژول پایه شما استفاده میکند تا کد نسخه یکسانی را به همه APKهایی که از آن بسته تولید میکند اختصاص دهد. یعنی وقتی دستگاهی برنامه شما را دانلود و نصب میکند، همه فایلهای APK تقسیمشده برای آن برنامه یک کد نسخه را به اشتراک میگذارند.
هنگامی که می خواهید برنامه خود را با کد یا منابع جدید به روز کنید، باید کد نسخه را در ماژول پایه برنامه خود به روز کنید و یک بسته نرم افزاری جدید و کامل بسازید. وقتی آن بسته برنامه را در Google Play آپلود میکنید، مجموعه جدیدی از APK بر اساس کد نسخهای که ماژول پایه مشخص میکند تولید میکند. متعاقباً، وقتی کاربران برنامه شما را بهروزرسانی میکنند، Google Play نسخههای بهروزرسانیشده همه فایلهای APK را که در حال حاضر در دستگاه نصب شدهاند، به آنها ارائه میکند. یعنی تمام APK های نصب شده به کد نسخه جدید به روز می شوند.
ملاحظات دیگر
- امضای برنامه: اگر اطلاعات امضا را در فایل های ساخت خود قرار دهید، فقط باید آن را در فایل پیکربندی ساخت ماژول پایه قرار دهید. برای اطلاعات بیشتر، به پیکربندی Gradle برای امضای برنامه خود مراجعه کنید.
- کوچک کردن کد: اگر می خواهید کوچک کردن کد را برای کل پروژه برنامه خود (از جمله ماژول های ویژگی آن) فعال کنید ، باید این کار را از فایل build.gradle ماژول پایه انجام دهید. یعنی میتوانید قوانین سفارشی ProGuard را در یک ماژول ویژگی قرار دهید، اما ویژگی
minifyEnabled
در پیکربندیهای ساخت ماژول ویژگی نادیده گرفته میشود. - بلوک
splits
نادیده گرفته می شود: هنگام ساخت یک بسته برنامه، Gradle ویژگی های بلوک android.splits
را نادیده می گیرد. اگر میخواهید نوع APK پیکربندی را کنترل کنید که بسته برنامه شما از کدام نوع پیکربندی پشتیبانی میکند، در عوض از android.bundle
برای غیرفعال کردن انواع APK پیکربندی استفاده کنید. - نسخهسازی برنامه: ماژول پایه کد نسخه و نام نسخه را برای کل پروژه برنامه شما تعیین میکند. برای اطلاعات بیشتر، به بخش نحوه مدیریت بهروزرسانیهای برنامه بروید.
انواع APKهای پیکربندی را دوباره فعال یا غیرفعال کنید
بهطور پیشفرض، وقتی یک بسته برنامه میسازید، از ایجاد APK پیکربندی برای هر مجموعه از منابع زبان، منابع تراکم صفحه و کتابخانههای ABI پشتیبانی میکند. با استفاده از بلوک android.bundle
در فایل build.gradle
ماژول پایه خود، همانطور که در زیر نشان داده شده است، می توانید پشتیبانی از یک یا چند نوع APK پیکربندی را غیرفعال کنید:
شیار
android {
// When building Android App Bundles, the splits block is ignored.
// You can remove it, unless you're going to continue to build multiple
// APKs in parallel with the app bundle
splits {...}
// Instead, use the bundle block to control which types of configuration APKs
// you want your app bundle to support.
bundle {
language {
// This property is set to true by default.
// You can specify `false` to turn off
// generating configuration APKs for language resources.
// These resources are instead packaged with each base and
// feature APK.
// Continue reading below to learn about situations when an app
// might change setting to `false`, otherwise consider leaving
// the default on for more optimized downloads.
enableSplit = false
}
density {
// This property is set to true by default.
enableSplit = true
}
abi {
// This property is set to true by default.
enableSplit = true
}
}
}
کاتلین
android {
// When building Android App Bundles, the splits block is ignored.
// You can remove it, unless you're going to continue to build multiple
// APKs in parallel with the app bundle
splits {...}
// Instead, use the bundle block to control which types of configuration APKs
// you want your app bundle to support.
bundle {
language {
// This property is set to true by default.
// You can specify `false` to turn off
// generating configuration APKs for language resources.
// These resources are instead packaged with each base and
// feature APK.
// Continue reading below to learn about situations when an app
// might change setting to `false`, otherwise consider leaving
// the default on for more optimized downloads.
enableSplit = false
}
density {
// This property is set to true by default.
enableSplit = true
}
abi {
// This property is set to true by default.
enableSplit = true
}
}
}
مدیریت تغییرات زبان
Google Play بر اساس انتخاب زبان در تنظیمات دستگاه کاربر، تعیین میکند که کدام منابع زبان را با برنامه نصب کند. کاربری را در نظر بگیرید که پس از دانلود برنامه شما، زبان سیستم پیش فرض خود را تغییر می دهد. اگر برنامه شما از آن زبان پشتیبانی میکند، دستگاه فایلهای APK پیکربندی اضافی را برای آن منابع زبان از Google Play درخواست و دانلود میکند.
برای برنامههایی که انتخابگر زبان را در داخل برنامه ارائه میکنند و به صورت پویا زبان برنامه را تغییر میدهند، مستقل از تنظیمات زبان سطح سیستم، باید تغییراتی را برای جلوگیری از خرابیها به دلیل کمبود منابع ایجاد کنید. یا ویژگی android.bundle.language.enableSplit
را روی false
تنظیم کنید، یا دانلودهای زبان درخواستی را با استفاده از کتابخانه Play Core اجرا کنید، همانطور که در دانلود منابع زبان اضافی توضیح داده شده است.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Configure the base module\n\nAn app bundle is different from an APK in that you can't deploy one to a\ndevice. Rather, it's a publishing format that includes all your app's compiled\ncode and resources in a single build artifact. So, after you upload your\nsigned app bundle, Google Play has everything it needs to build and sign your\napp's APKs, and serve them to users.\n\nGet started\n-----------\n\nMost app projects won't require much effort to support Android App Bundles.\nThat's because the module that includes code and resources for your app's base\nAPK is the standard app module, which you get by default when you\n[create a new app project in Android Studio](/studio/projects/create-project).\nThat is, the module that applies the `application` plugin below to its\n`build.gradle` file provides the code and resources for the base functionality\nof your app. \n\n### Groovy\n\n```groovy\n// The standard application plugin creates your app's base module.\nplugins {\n id 'com.android.application'\n}\n```\n\n### Kotlin\n\n```kotlin\nplugins {\n // The standard application plugin creates your app's base module.\n id(\"com.android.application\")\n}\n```\n\nIn addition to providing the core functionality for your app, the base module\nalso provides many of the build configurations and manifest entries that\naffect your entire app project.\n\nThe base module build configuration\n-----------------------------------\n\nFor most existing app projects, you don't need to change anything in your base\nmodule's build configuration. However, if you are considering adding\nfeature modules to your app project or if you previously released your app using\nmultiple APKs, there are some aspects to the base module's build configuration\nthat you should keep in mind.\n\n### Version code and app updates\n\nWith Android App Bundles, you no longer have to manage\nversion codes for multiple APKs that you upload to Google Play. Instead, you\nmanage only one version code in the base module of your app, as shown below: \n\n // In your base module build.gradle file\n android {\n defaultConfig {\n ...\n // You specify your app's version code only in the base module.\n versionCode 5\n versionName \"1.0\"\n }\n }\n\nAfter you upload your app bundle, Google Play uses the version code in your\nbase module to assign the same version code to all the APKs it generates from\nthat bundle. That is, when a device downloads and installs your app, all split\nAPKs for that app share the same version code.\n\nWhen you want to update your app with new code or resources, you must update\nthe version code in your app's base module, and build a new, full app bundle.\nWhen you upload that app bundle to Google Play, it generates a new set of APKs\nbased on the version code the base module specifies. Subsequently, when users\nupdate your app, Google Play serves them updated versions of all APKs\ncurrently installed on the device. That is, all installed APKs are updated to\nthe new version code.\n\n### Other considerations\n\n- **App signing:** If you include signing information in your build files, you should only include it in the base module's build configuration file. For more information, see [Configure Gradle to sign your app](/studio/publish/app-signing#gradle-sign).\n- **Code shrinking:** If you want to [enable code shrinking](/studio/build/shrink-code#shrink-code) for your entire app project (including its feature modules), you must do so from the base module's build.gradle file. That is, you can include custom ProGuard rules in a feature module, but the `minifyEnabled` property in feature module build configurations is ignored.\n- **The `splits` block is ignored:** When building an app bundle, Gradle ignores properties in the `android.splits` block. If you want to control which types of configuration APKs your app bundle supports, instead use `android.bundle` to [disable types of configuration APKs](#disable_config_apks).\n- **App versioning:** The base module determines the version code and version name for your entire app project. For more information, go to the section about how to [Manage app updates](#manage_app_updates).\n\n### Re-enable or disable types of configuration APKs\n\nBy default, when you build an app bundle, it supports generating configuration\nAPKs for each set of language resources, screen density resources, and ABI\nlibraries. Using the `android.bundle` block in your base module's\n`build.gradle` file, as shown below, you can disable support for one or more\ntypes of configuration APKs: \n\n### Groovy\n\n```groovy\nandroid {\n // When building Android App Bundles, the splits block is ignored.\n // You can remove it, unless you're going to continue to build multiple\n // APKs in parallel with the app bundle\n splits {...}\n\n // Instead, use the bundle block to control which types of configuration APKs\n // you want your app bundle to support.\n bundle {\n language {\n // This property is set to true by default.\n // You can specify `false` to turn off\n // generating configuration APKs for language resources.\n // These resources are instead packaged with each base and\n // feature APK.\n // Continue reading below to learn about situations when an app\n // might change setting to `false`, otherwise consider leaving\n // the default on for more optimized downloads.\n enableSplit = false\n }\n density {\n // This property is set to true by default.\n enableSplit = true\n }\n abi {\n // This property is set to true by default.\n enableSplit = true\n }\n }\n}\n```\n\n### Kotlin\n\n```kotlin\nandroid {\n // When building Android App Bundles, the splits block is ignored.\n // You can remove it, unless you're going to continue to build multiple\n // APKs in parallel with the app bundle\n splits {...}\n\n // Instead, use the bundle block to control which types of configuration APKs\n // you want your app bundle to support.\n bundle {\n language {\n // This property is set to true by default.\n // You can specify `false` to turn off\n // generating configuration APKs for language resources.\n // These resources are instead packaged with each base and\n // feature APK.\n // Continue reading below to learn about situations when an app\n // might change setting to `false`, otherwise consider leaving\n // the default on for more optimized downloads.\n enableSplit = false\n }\n density {\n // This property is set to true by default.\n enableSplit = true\n }\n abi {\n // This property is set to true by default.\n enableSplit = true\n }\n }\n}\n```\n\n### Handling language changes\n\nGoogle Play determines which language resources to install with the app based\non the language selection in the user's device settings. Consider a user who\nchanges their default system language after already downloading your app.\nIf your app supports that language, the device requests and downloads additional\nconfiguration APKs for those language resources from Google Play.\n\nFor apps that offer a language picker inside the application and dynamically\nchange the app's language, independent of the system level language setting,\nyou must make some changes to prevent crashes due to missing resources. Either\nset the `android.bundle.language.enableSplit` property to `false`, or consider\nimplementing on-demand language downloads using the Play Core library as\ndescribed in [Download additional language resources](/guide/playcore/feature-delivery/on-demand#lang_resources)"]]