กําหนดค่าโมดูลฐาน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
App Bundle ต่างจาก APK ตรงที่คุณไม่สามารถทำให้ APK ใช้งานได้
อุปกรณ์ แต่จะเป็นรูปแบบการเผยแพร่ที่รวมแอปทั้งหมดของคุณ
โค้ดและทรัพยากรในอาร์ติแฟกต์บิลด์เดียว ดังนั้น หลังจากที่คุณอัปโหลด
App Bundle ที่รับรองแล้ว, Google Play มีทุกอย่างที่ต้องใช้ในการสร้างและรับรอง
APK ของแอป และเผยแพร่แก่ผู้ใช้
เริ่มต้นใช้งาน
โปรเจ็กต์แอปส่วนใหญ่ไม่จำเป็นต้องใช้ความพยายามอย่างมากในการรองรับ Android App Bundle
เนื่องจากโมดูลที่มีโค้ดและทรัพยากรสำหรับฐานแอปของคุณ
APK เป็นโมดูลแอปมาตรฐาน ซึ่งคุณจะได้รับโดยค่าเริ่มต้นเมื่อ
สร้างโปรเจ็กต์แอปใหม่ใน Android Studio
นั่นคือโมดูลที่ใช้ปลั๊กอิน application
ด้านล่างกับปลั๊กอิน
ไฟล์ build.gradle
มีโค้ดและทรัพยากรสำหรับฟังก์ชันการทำงานพื้นฐาน
ของแอปของคุณ
ดึงดูด
// The standard application plugin creates your app's base module.
plugins {
id 'com.android.application'
}
Kotlin
plugins {
// The standard application plugin creates your app's base module.
id("com.android.application")
}
นอกเหนือจากการให้ฟังก์ชันหลักสำหรับแอปแล้ว โมดูลฐาน
ยังมีการกำหนดค่าบิลด์และรายการ Manifest มากมายที่
จะส่งผลต่อทั้งโปรเจ็กต์แอปของคุณ
การกำหนดค่าบิลด์ของโมดูลฐาน
สำหรับโปรเจ็กต์แอปส่วนใหญ่ที่มีอยู่ คุณไม่จำเป็นต้องทำการเปลี่ยนแปลงใดๆ ในฐาน
การกำหนดค่าบิลด์ของโมดูล แต่ถ้าคุณคิดจะเพิ่ม
โมดูลฟีเจอร์ลงในโปรเจ็กต์แอปของคุณ หรือหากคุณได้เผยแพร่แอปก่อนหน้านี้โดยใช้
APK หลายรายการ การกำหนดค่าบิลด์ของโมดูลฐานมีด้านต่างๆ บางส่วน
ที่คุณควรคำนึงถึง
รหัสเวอร์ชันและการอัปเดตแอป
เมื่อใช้ Android App Bundle คุณจะไม่ต้องจัดการอีกต่อไป
รหัสเวอร์ชันสำหรับ 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"
}
}
หลังจากที่คุณอัปโหลด App Bundle แล้ว Google Play จะใช้รหัสเวอร์ชันใน
โมดูลฐานสำหรับกำหนดรหัสเวอร์ชันเดียวกันให้กับ APK ทั้งหมดที่ APK สร้างขึ้น
แพ็กเกจนั้น กล่าวคือ เมื่ออุปกรณ์ดาวน์โหลดและติดตั้งแอปของคุณ ทุกอย่างจะแยกออกเป็น
APK ของแอปนั้นใช้รหัสเวอร์ชันเดียวกัน
เมื่อต้องการอัปเดตแอปด้วยโค้ดหรือทรัพยากรใหม่ คุณต้องอัปเดต
รหัสเวอร์ชันในโมดูลฐานของแอป และสร้าง App Bundle ที่สมบูรณ์ใหม่
เมื่อคุณอัปโหลด App Bundle นั้นไปยัง Google Play ระบบจะสร้าง APK ชุดใหม่
ตามรหัสเวอร์ชันที่โมดูลฐานระบุไว้ จากนั้น เมื่อผู้ใช้
อัปเดตแอปของคุณ Google Play จะแสดง APK เวอร์ชันที่อัปเดตแล้วทั้งหมด
ที่ติดตั้งบนอุปกรณ์ในปัจจุบัน กล่าวคือ APK ที่ติดตั้งทั้งหมดได้รับการอัปเดตเป็น
รหัสเวอร์ชันใหม่
ปัจจัยพิจารณาอื่นๆ
- การลงนามแอป: หากคุณใส่ข้อมูลการลงนามในไฟล์บิลด์
คุณควรรวมไว้ในไฟล์การกำหนดค่าบิลด์ของโมดูลฐานเท่านั้น
สำหรับข้อมูลเพิ่มเติม โปรดดู
กำหนดค่า Gradle เพื่อรับรองแอป
- การย่อโค้ด: หากคุณต้องการ
เปิดใช้การย่อโค้ดสำหรับ
โปรเจ็กต์แอปทั้งหมด (รวมถึงโมดูลฟีเจอร์) คุณต้องดำเนินการ
จากไฟล์ create.gradle ของโมดูลฐาน กล่าวคือ คุณสามารถ
รวมกฎ ProGuard ที่กำหนดเอง
ไว้ในโมดูลฟีเจอร์
แต่พร็อพเพอร์ตี้
minifyEnabled
ในฟีเจอร์
ระบบจะไม่พิจารณาการกำหนดค่าบิลด์โมดูล
- ระบบจะไม่สนใจบล็อก
splits
: เมื่อสร้าง App Bundle ทาง Gradle
ไม่พิจารณาคุณสมบัติในบล็อก android.splits
หากคุณต้องการควบคุม
ประเภทการกำหนดค่า APK ที่ App Bundle รองรับ ให้ใช้
android.bundle
ถึง
ปิดใช้ประเภทของ APK การกำหนดค่า
- การกำหนดเวอร์ชันของแอป: โมดูลฐานจะเป็นตัวกำหนดรหัสเวอร์ชันและเวอร์ชัน
สำหรับทั้งโปรเจ็กต์แอปของคุณ ดูข้อมูลเพิ่มเติมได้ในส่วน
เกี่ยวกับวิธีจัดการการอัปเดตแอป
เปิดหรือปิดใช้ประเภทของ APK การกำหนดค่าอีกครั้ง
โดยค่าเริ่มต้น เมื่อสร้าง App Bundle แอปจะรองรับการสร้างการกำหนดค่า
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
}
}
}
Kotlin
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
ตามที่อธิบายไว้ในดาวน์โหลดแหล่งข้อมูลเกี่ยวกับภาษาเพิ่มเติม
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","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-07-27 UTC"],[],[],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)"]]