ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
ใช้อุปกรณ์เสมือนของ Android Emulator
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
คุณสามารถใช้โปรแกรมจำลอง Android เพื่อสร้างการจําลองอุปกรณ์ Android ที่เรียกใช้อิมเมจระบบ Android ที่กําหนดเอง นอกจากนี้ คุณยังเพิ่มการรองรับหลายจอแสดงผลในการจําลองของ Android Emulator ได้อีกด้วย
สถาปัตยกรรมของโปรแกรมจำลอง Android
โปรแกรมจำลอง Android จะเรียกใช้ระบบปฏิบัติการ Android ในเครื่องเสมือนที่เรียกว่า Android Virtual Device (AVD) AVD แต่ละรายการจะมีสแต็กซอฟต์แวร์ Android ทั้งหมด และทำงานราวกับอยู่ในอุปกรณ์จริง รูปที่ 1 แสดงสถาปัตยกรรมระดับสูงของโปรแกรมจำลอง Android ดูข้อมูลเพิ่มเติมเกี่ยวกับโปรแกรมจำลองได้ที่เรียกใช้แอปในโปรแกรมจำลอง Android
รูปที่ 1 สถาปัตยกรรมของโปรแกรมจำลอง Android
สร้างอิมเมจ AVD
AVD แต่ละรายการจะมีอิมเมจระบบ Android ซึ่งจะทำงานใน AVD นั้น เครื่องมือจัดการ AVD มีภาพระบบบางส่วน และคุณยังสร้างอิมเมจระบบ AVD ที่กําหนดเองจากซอร์สโค้ด รวมถึงสร้างการจําลองอุปกรณ์เพื่อเรียกใช้อิมเมจเหล่านั้นได้ด้วย
วิธีสร้างและเรียกใช้อิมเมจระบบ AVD
ดาวน์โหลดซอร์สโค้ด Android
mkdir aosp-android-latest-release; cd aosp-android-latest-release
repo init -u
repo sync -j24
หากต้องการสร้าง Android เวอร์ชันอื่นๆ ให้ค้นหาชื่อสาขาในที่เก็บข้อมูล Android สาธารณะ
ซึ่งจะแมปกับชื่อเวอร์ชัน แท็ก และหมายเลขบิลด์ของ Android
สร้างอิมเมจระบบ AVD ซึ่งเป็นกระบวนการเดียวกับการสร้างภาพระบบของอุปกรณ์ Android เช่น หากต้องการสร้าง AVD 64 บิต x86 ให้ทำดังนี้
source ./build/envsetup.sh
lunch sdk_phone_x86_64
make -j32
เรียกใช้อิมเมจระบบ AVD ในโปรแกรมจำลอง Android โดยทำดังนี้
emulator
ดูรายละเอียดเพิ่มเติมเกี่ยวกับการเรียกใช้โปรแกรมจำลองได้ที่ตัวเลือกการเริ่มต้นบรรทัดคำสั่ง รูปที่ 2 แสดงตัวอย่างโปรแกรมจําลอง Android ที่เรียกใช้ AVD
รูปที่ 2 โปรแกรมจำลอง Android ที่เรียกใช้ AVD
แชร์ภาพระบบ AVD ให้ผู้อื่นใช้กับ Android Studio
ทำตามวิธีการต่อไปนี้เพื่อแชร์ภาพระบบ AVD กับผู้อื่น โดยสามารถใช้อิมเมจระบบ AVD กับ Android Studio เพื่อพัฒนาและทดสอบแอปได้
สร้างแพ็กเกจ sdk
และ sdk_repo
เพิ่มเติม
สำหรับ Android 13 ขึ้นไป ให้ใช้คำสั่ง emu_img_zip
ดังนี้
$ make emu_img_zip
ซึ่งจะสร้างไฟล์ sdk-repo-linux-system-images-eng.[username]].zip
สำหรับ Android 12 และต่ำกว่า ให้ใช้คำสั่ง sdk_repo
ดังนี้
$ make -j32 sdk sdk_repo
คำสั่ง make sdk sdk_repo
จะสร้างไฟล์ 2 ไฟล์ภายใต้ aosp-android-latest-release/out/host/linux-x86/sdk/sdk_phone_x86
ดังนี้
sdk-repo-linux-system-images-eng.[username].zip
repo-sys-img.xml
โฮสต์ไฟล์ sdk-repo-linux-system-images-eng.[username].zip
ไว้ในตำแหน่งที่ผู้ใช้เข้าถึงได้ แล้วรับ URL ของไฟล์เพื่อใช้เป็น AVD
URL ของภาพระบบ
สำหรับ Android 12 และต่ำกว่า ให้แก้ไข repo-sys-img.xml
ดังนี้
- อัปเดต
<sdk:url>
เป็น URL รูปภาพระบบ AVD
- ดูข้อมูลการอัปเดตอื่นๆ ของไฟล์ได้ที่ sdk-sys-img-03.xsd
- โฮสต์
repo-sys-img.xml
ไว้ที่ผู้ใช้เข้าถึงได้ แล้วรับ URL ของไฟล์เพื่อใช้เป็นURL เว็บไซต์อัปเดตที่กำหนดเอง
หากต้องการใช้รูปภาพ AVD ที่กําหนดเอง ให้ทําดังนี้ในเครื่องมือจัดการ SDK
เพิ่ม URL เว็บไซต์อัปเดตที่กำหนดเองเป็นเว็บไซต์อัปเดต SDK
ซึ่งจะเพิ่มภาพระบบ AVD ที่กําหนดเองลงในหน้า "ภาพระบบ"
สร้าง AVD โดยดาวน์โหลดและเลือกภาพระบบ AVD ที่กําหนดเอง
เพิ่มการรองรับหลายจอภาพ
Android 10
ปรับปรุงการแสดงผลหลายหน้าจอเพื่อรองรับกรณีการใช้งานเพิ่มเติม เช่น โหมดอัตโนมัติและโหมดเดสก์ท็อปได้ดียิ่งขึ้น โปรแกรมจำลอง Android ยังรองรับการจําลองหลายจอภาพด้วย คุณจึงสร้างสภาพแวดล้อมแบบหลายจอแสดงผลที่เฉพาะเจาะจงได้โดยไม่ต้องตั้งค่าฮาร์ดแวร์จริง
คุณสามารถเพิ่มการรองรับจอแสดงผลหลายจอลงใน AVD ได้โดยทำการเปลี่ยนแปลงต่อไปนี้ หรือคัดเลือกจาก CL เหล่านี้
เพิ่มผู้ให้บริการหลายจอแสดงผลลงในบิลด์โดยเพิ่มบรรทัดต่อไปนี้ลงในไฟล์
build/target/product/sdk_phone_x86.mk
PRODUCT_ARTIFACT_PATH_REQUIREMENT_WHITELIST := \
system/lib/libemulator_multidisplay_jni.so \
system/lib64/libemulator_multidisplay_jni.so \
system/priv-app/MultiDisplayProvider/MultiDisplayProvider.apk \
PRODUCT_PACKAGES += MultiDisplayProvider
เปิดใช้ Flag ฟีเจอร์หลายจอแสดงผลโดยเพิ่มบรรทัดนี้ลงในไฟล์
device/generic/goldfish/data/etc/advancedFeatures.ini
MultiDisplay = on
คุณดูฟีเจอร์และข้อมูลรุ่นล่าสุดของโปรแกรมจำลองได้จากแหล่งที่มาต่อไปนี้
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา 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,["# Use Android Emulator virtual devices\n\nYou can use Android Emulator to create emulations of Android devices\nthat run your own custom Android system images. In\naddition, you can add multi-display support to Android Emulator\nemulations.\n\nAndroid Emulator architecture\n-----------------------------\n\nAndroid Emulator runs the Android operating\nsystem in a virtual machine called an Android Virtual Device (AVD). Each AVD\ncontains the full\n[Android software stack](/docs/core/architecture), and it runs as if it\nwere on a physical device. Figure 1 illustrates Android Emulator's\nhigh-level architecture. For more information about the emulator, see\n[Run apps on the Android Emulator](https://developer.android.com/studio/run/emulator).\n\n**Figure 1.** Android Emulator architecture.\n\nBuild AVD images\n----------------\n\nEach AVD includes an Android system image, which runs in\nthat AVD. The AVD Manager includes some system images. And you can build custom\nAVD system images from your source code and create device emulations to run\nthem.\n| **Note:** You need to [establish a build environment](/docs/setup/start/initializing) before building AVD system images.\n\nTo build and run an AVD system image:\n\n1. Download the Android source:\n\n mkdir aosp-android-latest-release; cd aosp-android-latest-release\n repo init -u\n repo sync -j24\n\nIf you want to build other Android versions, you can find their branch names in\nthe [public Android repository](https://android.googlesource.com/platform/manifest/+refs).\nThey map to\n[Android Codenames, Tags, and Build Numbers](/docs/setup/reference/build-numbers#source-code-tags-and-builds).\n\n1. Build an AVD system image. This is the same process as [building an\n Android](/docs/setup/build/building) device system\n image. For example, to build a x86 64-bit AVD:\n\n source ./build/envsetup.sh\n lunch sdk_phone_x86_64\n make -j32\n\n2. Run the AVD system image in the Android Emulator:\n\n emulator\n\nSee\n[Command-line startup options](https://developer.android.com/studio/run/emulator-commandline#startup-options)\nfor more details about running the emulator. Figure 2 shows an example of the\nAndroid Emulator running an AVD:\n\n**Figure 2.** Android Emulator running an AVD.\n\nShare AVD system images for others to use with Android Studio\n-------------------------------------------------------------\n\nFollow these instructions to share your AVD system images with others. They can\nuse your AVD system images with [Android\nStudio](https://developer.android.com/studio) to develop and test apps.\n\n1. Make additional `sdk` and `sdk_repo` packages:\n\n For Android 13 and higher, use the `emu_img_zip`\n command: \n\n $ make emu_img_zip\n\n This generates an `sdk-repo-linux-system-images-eng.[username]].zip` file.\n\n For Android 12 and lower, use the `sdk_repo`\n command: \n\n $ make -j32 sdk sdk_repo\n\n The `make sdk sdk_repo` command creates two files under\n `aosp-android-latest-release/out/host/linux-x86/sdk/sdk_phone_x86`:\n - `sdk-repo-linux-system-images-eng.[username].zip`\n - `repo-sys-img.xml`\n2. Host the file `sdk-repo-linux-system-images-eng.[username].zip`\n somewhere accessible to your users, and get its URL to use as the **AVD\n System Image URL**.\n\n3. For Android 12 and lower, edit `repo-sys-img.xml` accordingly:\n\n - Update `\u003csdk:url\u003e` to your **AVD System Image URL**.\n - See [sdk-sys-img-03.xsd](https://android.googlesource.com/platform/prebuilts/devtools/+/refs/heads/android16-release/repository/sdk-sys-img-03.xsd) to learn about other updates to the file.\n - Host `repo-sys-img.xml` somewhere accessible to your users, and get its URL to use as the **Custom Update Site URL**.\n\nTo use a custom AVD image, do the following in the SDK Manager:\n\n1. Add the **Custom Update Site URL** as an\n [SDK Update Site](https://developer.android.com/studio/intro/update#adding-sites).\n\n This adds your custom AVD system image to the System Images page.\n2. [Create an AVD](https://developer.android.com/studio/run/managing-avds#createavd)\n by downloading and selecting the custom AVD system image.\n\nAdd multi-display support\n-------------------------\n\nAndroid 10\n[enhances multi-display](/docs/core/display/multi_display)\nto better support more use cases, such as auto and desktop mode. Android\nEmulator also supports multi-display emulation. So you can create a specific\nmulti-display environment without setting up the real hardware.\n\nYou can add multi-display support to an AVD by making the following changes, or\nby cherry picking from\n[these CLs](https://android-review.googlesource.com/q/topic:%22AVD+Multi-display%22+(status:open%20OR%20status:merged)).\n\n- Add the multi-display provider to the build by adding these lines to file\n `build/target/product/sdk_phone_x86.mk`:\n\n PRODUCT_ARTIFACT_PATH_REQUIREMENT_WHITELIST := \\\n system/lib/libemulator_multidisplay_jni.so \\\n system/lib64/libemulator_multidisplay_jni.so \\\n system/priv-app/MultiDisplayProvider/MultiDisplayProvider.apk \\\n PRODUCT_PACKAGES += MultiDisplayProvider\n\n- Enable the Multi-Display feature flag by adding this line to file\n `device/generic/goldfish/data/etc/advancedFeatures.ini`:\n\n MultiDisplay = on\n\nYou can find the latest emulator features and release information from\nthe following sources:\n\n- [Run apps on Android Emulator](https://developer.android.com/studio/run/emulator)\n- [Android Emulator release notes](https://developer.android.com/studio/releases/emulator)"]]