شبیه ساز را از خط فرمان شروع کنید

کیت توسعه نرم‌افزار اندروید (SDK) شامل یک شبیه‌ساز دستگاه اندروید است - یک دستگاه مجازی که روی رایانه شما اجرا می‌شود. شبیه‌ساز اندروید به شما امکان می‌دهد برنامه‌های اندروید را بدون استفاده از یک دستگاه فیزیکی توسعه داده و آزمایش کنید.

این صفحه ویژگی‌های خط فرمانی را که می‌توانید با شبیه‌ساز اندروید استفاده کنید، شرح می‌دهد. برای اطلاعات بیشتر در مورد استفاده از رابط کاربری شبیه‌ساز اندروید، به بخش اجرای برنامه‌ها در شبیه‌ساز اندروید مراجعه کنید.

شبیه‌ساز را شروع کنید

برای شروع شبیه‌ساز، به عنوان جایگزینی برای اجرای پروژه یا شروع آن از طریق AVD Manager ، از دستور emulator استفاده کنید.

در اینجا سینتکس خط فرمان پایه برای شروع یک دستگاه مجازی از طریق اعلان ترمینال آمده است:

emulator -avd avd_name [ {-option [value]} … ]

یا

emulator @avd_name [ {-option [value]} … ]

برای مثال، اگر شبیه‌ساز را از داخل اندروید استودیو که روی مک اجرا می‌شود، اجرا کنید، خط فرمان پیش‌فرض مشابه زیر خواهد بود:

/Users/janedoe/Library/Android/sdk/emulator/emulator -avd Pixel8_API_34 -netdelay none -netspeed full -qt-hide-window -grpc-use-token -idle-grpc-timeout

لطفاً توجه داشته باشید که آرگومان‌های -qt-hide-window -grpc-use-token -idle-grpc-timeout ‎ فقط برای اجرای پنجره شبیه‌ساز در اندروید استودیو استفاده می‌شوند. اگر می‌خواهید شبیه‌ساز را در پنجره خودش اجرا کنید، نباید از این پارامترهای اضافی استفاده کنید.

شما می‌توانید گزینه‌های راه‌اندازی را هنگام شروع شبیه‌ساز مشخص کنید، اما نه پس از شروع آن.

برای مشاهده لیست نام‌های AVD، دستور زیر را وارد کنید:

emulator -list-avds

از این گزینه برای نمایش لیستی از نام‌های AVD از دایرکتوری خانگی اندروید خود استفاده کنید. می‌توانید با تنظیم متغیر محیطی ANDROID_SDK_HOME که ریشه دایرکتوری مخصوص کاربر را که تمام پیکربندی‌ها و محتوای AVD در آن ذخیره می‌شود، مشخص می‌کند، دایرکتوری خانگی پیش‌فرض را لغو کنید.

شما می‌توانید متغیر محیطی را در پنجره ترمینال قبل از راه‌اندازی یک دستگاه مجازی یا از طریق تنظیمات کاربری خود در سیستم عامل تنظیم کنید. به عنوان مثال، در فایل .bashrc خود در لینوکس.

برای متوقف کردن شبیه‌ساز اندروید، پنجره شبیه‌ساز را ببندید.

نصب یک برنامه

علاوه بر نصب برنامه از طریق اندروید استودیو یا رابط کاربری شبیه‌ساز ، می‌توانید برنامه خود را با استفاده از ابزار adb روی یک دستگاه مجازی نصب کنید.

برای استفاده از adb برای نصب، اجرا و آزمایش برنامه خود، این مراحل کلی را دنبال کنید:

  1. همانطور که در بخش «ساخت و اجرای برنامه» توضیح داده شده است، برنامه خود را در یک فایل APK بسازید و بسته‌بندی کنید.
  2. همانطور که در بخش قبل توضیح داده شد، شبیه‌ساز را از خط فرمان و با استفاده از هر گزینه راه‌اندازی لازم، اجرا کنید.
  3. برنامه خود را با استفاده از adb نصب کنید.
  4. برنامه خود را روی شبیه‌ساز اجرا و آزمایش کنید.
    در حالی که شبیه‌ساز در حال اجرا است، می‌توانید از کنسول شبیه‌ساز برای صدور دستورات مورد نیاز استفاده کنید.

برای حذف نصب یک برنامه، مانند حذف نصب آن در دستگاه‌های اندروید عمل کنید.

دستگاه مجازی، برنامه و داده‌های وضعیت آن را در طول راه‌اندازی‌های مجدد در یک پارتیشن دیسک داده‌های کاربر ( userdata-qemu.img ) حفظ می‌کند. برای پاک کردن این داده‌ها، شبیه‌ساز را با گزینه -wipe-data اجرا کنید یا داده‌ها را در AVD Manager پاک کنید. برای اطلاعات بیشتر در مورد پارتیشن داده‌های کاربر و سایر حافظه‌ها، به بخش زیر مراجعه کنید.

نکته: ابزار adb دستگاه مجازی را به عنوان یک دستگاه فیزیکی واقعی در نظر می‌گیرد. به همین دلیل، ممکن است مجبور شوید از پرچم -d با برخی از دستورات رایج adb ، مانند install استفاده کنید. پرچم -d به شما امکان می‌دهد مشخص کنید کدام یک از چندین دستگاه متصل به عنوان هدف یک دستور استفاده شود. اگر -d را مشخص نکنید، شبیه‌ساز اولین دستگاه موجود در لیست خود را هدف قرار می‌دهد.

آشنایی با دایرکتوری‌ها و فایل‌های پیش‌فرض

این شبیه‌ساز از فایل‌های مرتبط استفاده می‌کند که از بین آنها، دایرکتوری‌های سیستم و داده‌های AVD مهمترین هستند. درک ساختار دایرکتوری و فایل‌های شبیه‌ساز هنگام تعیین گزینه‌های خط فرمان مفید است، اگرچه معمولاً نیازی به تغییر دایرکتوری‌ها یا فایل‌های پیش‌فرض ندارید.

شبیه‌ساز اندروید از هایپروایزر ( QEMU ) استفاده می‌کند.

دایرکتوری سیستم AVD

دایرکتوری سیستم شامل تصاویر سیستم اندروید است که شبیه‌ساز برای شبیه‌سازی سیستم عامل از آنها استفاده می‌کند. این دایرکتوری حاوی فایل‌های فقط خواندنی و مختص پلتفرم است که توسط همه AVD های هم نوع، از جمله سطح API، معماری CPU و نوع اندروید، به اشتراک گذاشته می‌شود. مکان‌های پیش‌فرض به شرح زیر هستند:

  • macOS و لینوکس - ~/Library/Android/sdk/system-images/android- apiLevel / variant / arch /
  • ویندوز - C:\Users\ user \Library\Android\sdk\system-images\android- apiLevel \ variant \ arch \

کجا:

  • apiLevel یک سطح API عددی یا یک حرف برای نسخه‌های پیش‌نمایش است. برای مثال، android-V نشان‌دهنده پیش‌نمایش Android VanillaIceCream است. در زمان انتشار، به سطح API 35 تبدیل شد که با android-35 مشخص می‌شود.
  • variant نامی است که با ویژگی‌های خاصی که توسط تصویر سیستم پیاده‌سازی شده‌اند، مطابقت دارد. برای مثال، google_apis یا android-wear .
  • معماری پردازنده هدف، arch است. برای مثال، x86 .

از گزینه -sysdir برای مشخص کردن یک دایرکتوری سیستمی متفاوت برای AVD استفاده کنید.

شبیه‌ساز فایل‌های زیر را از دایرکتوری سیستم می‌خواند:

جدول 1. فایل‌های دایرکتوری سیستم که توسط شبیه‌ساز اندروید خوانده می‌شوند

فایل توضیحات گزینه‌ای برای مشخص کردن یک فایل متفاوت
kernel-qemu یا kernel-ranchu تصویر هسته دودویی برای AVD.kernel kernel-ranchu مبتنی بر شبیه‌ساز QEMU است. -kernel
ramdisk.img ایمیج پارتیشن بوت. این زیرمجموعه‌ای از system.img است که توسط هسته در ابتدا و قبل از نصب ایمیج سیستم بارگذاری می‌شود. این فایل معمولاً فقط شامل چند فایل باینری و اسکریپت‌های مقداردهی اولیه است. -ramdisk
system.img نسخه اولیه و فقط خواندنی از تصویر سیستم. به طور خاص، پارتیشنی که شامل کتابخانه‌های سیستم و داده‌های مربوط به سطح و نوع API است. -system
userdata.img نسخه اولیه پارتیشن داده، که در سیستم شبیه‌سازی شده به صورت data/ نمایش داده می‌شود و شامل تمام داده‌های قابل نوشتن برای AVD است. شبیه‌ساز هنگام ایجاد یک AVD جدید یا استفاده از گزینه ‑wipe-data از این فایل استفاده می‌کند. برای اطلاعات بیشتر، به توضیحات فایل userdata-qemu.img در بخش بعدی مراجعه کنید. -initdata
-init-data

دایرکتوری داده AVD

دایرکتوری داده AVD که دایرکتوری محتوا نیز نامیده می‌شود، مختص یک نمونه AVD واحد است و شامل تمام داده‌های قابل تغییر برای AVD می‌باشد.

مکان پیش‌فرض به صورت زیر است که در آن name همان نام AVD است:

  • macOS و لینوکس - ~/.android/avd/ name .avd/
  • ویندوز ۱۰ و بالاتر - C:\Users\ user \.android\ name .avd\

از گزینه -datadir برای مشخص کردن یک دایرکتوری داده AVD متفاوت استفاده کنید.

جدول زیر مهم‌ترین فایل‌های موجود در این دایرکتوری را فهرست می‌کند:

جدول ۲. فایل‌های مهم در دایرکتوری داده‌های AVD

فایل توضیحات گزینه‌ای برای مشخص کردن یک فایل متفاوت
userdata-qemu.img

محتوای پارتیشن داده، که در سیستم شبیه‌سازی شده به صورت data/ نمایش داده می‌شود. وقتی یک AVD جدید ایجاد می‌کنید یا وقتی از گزینه -wipe-data برای تنظیم مجدد AVD به تنظیمات کارخانه استفاده می‌کنید، شبیه‌ساز فایل userdata.img را در دایرکتوری سیستم کپی می‌کند تا این فایل را ایجاد کند.

هر نمونه دستگاه مجازی از یک تصویر داده کاربر قابل نوشتن برای ذخیره داده‌های خاص کاربر و جلسه استفاده می‌کند. به عنوان مثال، از این تصویر برای ذخیره داده‌های برنامه نصب شده، تنظیمات، پایگاه‌های داده و فایل‌های منحصر به فرد یک کاربر استفاده می‌کند. هر کاربر یک دایرکتوری ANDROID_SDK_HOME متفاوت دارد که دایرکتوری‌های داده را برای AVD های ایجاد شده توسط آن کاربر ذخیره می‌کند. هر AVD یک فایل userdata-qemu.img واحد دارد.

-data
cache.img تصویر پارتیشن کش، که در سیستم شبیه‌سازی شده به صورت cache/ نمایش داده می‌شود. وقتی برای اولین بار AVD ایجاد می‌کنید یا از گزینه -wipe-data استفاده می‌کنید، خالی است. این فایل‌ها، فایل‌های دانلود موقت را ذخیره می‌کنند و توسط مدیر دانلود و گاهی اوقات سیستم پر می‌شوند. به عنوان مثال، مرورگر از آن برای ذخیره صفحات وب و تصاویر دانلود شده در حین اجرای شبیه‌ساز استفاده می‌کند. وقتی دستگاه مجازی را خاموش می‌کنید، فایل حذف می‌شود. می‌توانید با استفاده از گزینه -cache ، فایل را حفظ کنید. -cache
sdcard.img

(اختیاری) یک تصویر پارتیشن کارت SD که به شما امکان می‌دهد یک کارت SD را روی یک دستگاه مجازی شبیه‌سازی کنید. می‌توانید یک فایل تصویر کارت SD را در AVD Manager یا با استفاده از ابزار mksdcard ایجاد کنید. این فایل در رایانه توسعه شما ذخیره می‌شود و باید در هنگام راه‌اندازی بارگیری شود.

هنگام تعریف AVD در AVD Manager، می‌توانید از یک فایل کارت SD که به طور خودکار مدیریت می‌شود یا فایلی که با ابزار mksdcard ایجاد کرده‌اید، استفاده کنید. می‌توانید فایل sdcard.img مرتبط با یک AVD را در AVD Manager مشاهده کنید. گزینه -sdcard فایل کارت SD مشخص شده در AVD را لغو می‌کند. توجه داشته باشید که این گزینه کارت SD در مک با Apple Silicon کار نخواهد کرد.

شما می‌توانید با استفاده از رابط کاربری شبیه‌ساز یا ابزار adb در حالی که دستگاه مجازی در حال اجرا است، به مرور فایل‌ها بپردازید، به آنها فایل ارسال کنید، فایل‌ها را از کارت SD شبیه‌سازی شده کپی و حذف کنید. شما نمی‌توانید یک کارت SD شبیه‌سازی شده را از یک دستگاه مجازی در حال اجرا خارج کنید.

برای کپی کردن فایل‌ها به کارت SD قبل از بارگذاری آن، فایل ایمیج را به عنوان یک دستگاه حلقه‌ای mount کنید و سپس فایل‌ها را کپی کنید. یا از ابزاری مانند بسته mtools برای کپی کردن مستقیم فایل‌ها به ایمیج استفاده کنید.

شبیه‌ساز با فایل به عنوان مجموعه‌ای از بایت‌ها رفتار می‌کند، بنابراین فرمت کارت SD اهمیتی ندارد.

گزینه -wipe-data روی این فایل تأثیری ندارد. اگر می‌خواهید فایل را پاک کنید، آن را حذف کرده و سپس با استفاده از AVD Manager یا ابزار mksdcard آن را دوباره ایجاد کنید. تغییر اندازه فایل نیز فایل را حذف کرده و یک فایل جدید ایجاد می‌کند.

-sdcard

فهرست دایرکتوری‌ها و فایل‌های استفاده شده توسط شبیه‌ساز

شما می‌توانید به دو روش محل قرارگیری فایل‌ها را پیدا کنید:

  • هنگام اجرای شبیه‌ساز از خط فرمان، از گزینه‌های -verbose یا -debug init استفاده کنید. به خروجی نگاه کنید.
  • از دستور emulator -help- option برای فهرست کردن دایرکتوری پیش‌فرض استفاده کنید. برای مثال:
    emulator -help-datadir
    Use '-datadir <dir>' to specify a directory where writable image files will be searched. On this system, the default directory is: /Users/me/.android See '-help-disk-images' for more information about disk image files.

گزینه‌های راه‌اندازی خط فرمان

این بخش گزینه‌هایی را که می‌توانید هنگام شروع شبیه‌ساز در خط فرمان ارائه دهید، فهرست می‌کند.

توجه: شبیه‌ساز اندروید به طور مداوم در حال توسعه است تا قابل اعتمادتر شود. برای اطلاع از وضعیت مشکلات گزارش شده در مورد گزینه‌های مختلف خط فرمان و گزارش اشکالات، به ردیاب مشکلات اندروید مراجعه کنید.

گزینه‌های پرکاربرد

جدول زیر گزینه‌های راه‌اندازی خط فرمان را که ممکن است بیشتر از آنها استفاده کنید، فهرست می‌کند:

جدول ۳. گزینه‌های خط فرمان پرکاربرد

گزینه خط فرمان توضیحات
بوت سریع
-no-snapshot-load بوت سرد را انجام می‌دهد و وضعیت شبیه‌ساز را در هنگام خروج ذخیره می‌کند.
-no-snapshot-save در صورت امکان، بوت سریع را انجام می‌دهد، اما وضعیت شبیه‌ساز را در هنگام خروج ذخیره نمی‌کند.
-no-snapshot قابلیت بوت سریع را به طور کامل غیرفعال می‌کند و حالت شبیه‌ساز را بارگذاری یا ذخیره نمی‌کند.
سخت‌افزار دستگاه
-camera-back mode
-camera-front mode
حالت شبیه‌سازی را برای دوربین رو به عقب یا جلو تنظیم می‌کند. این گزینه، هرگونه تنظیم دوربین در AVD را لغو می‌کند.

mode می‌تواند هر یک از مقادیر زیر باشد:

  • emulated - شبیه‌ساز، یک دوربین را در نرم‌افزار شبیه‌سازی می‌کند.
  • webcam n - شبیه‌ساز از یک وب‌کم متصل به رایانه توسعه شما استفاده می‌کند که با شماره مشخص شده است. برای مشاهده لیستی از وب‌کم‌ها، از گزینه -webcam-list استفاده کنید. به عنوان مثال، webcam0 .
  • none - دوربین را در دستگاه مجازی غیرفعال می‌کند.

برای مثال:

emulator @Pixel8_API_34 -camera-back webcam0
-webcam-list وب‌کم‌های موجود در رایانه توسعه شما را که برای شبیه‌سازی در دسترس هستند، فهرست می‌کند. برای مثال:
emulator @Pixel8_API_34 -webcam-list
        List of web cameras connected to the computer:
        Camera 'webcam0' is connected to device 'webcam0'
        on channel 0 using pixel format 'UYVY'

در این مثال، اولین webcam0 نامی است که شما در خط فرمان استفاده می‌کنید. دومین webcam0 نامی است که توسط سیستم عامل در رایانه توسعه استفاده می‌شود. نام دوم بسته به سیستم عامل متفاوت است.

از نسخه SDK Tools 25.2.4، نام AVD الزامی است.

تصاویر دیسک و حافظه
-memory size

اندازه رم فیزیکی را از ۱۵۳۶ تا ۸۱۹۲ مگابایت مشخص می‌کند. برای مثال:

emulator @Pixel8_API_34 -memory 2048

این مقدار، تنظیمات AVD را لغو می‌کند.

-sdcard filepath نام فایل و مسیر فایل ایمیج پارتیشن کارت SD را مشخص می‌کند. برای مثال:

emulator @Pixel8_API_34 -sdcard C:/sd/sdcard.img

اگر فایل پیدا نشود، شبیه‌ساز همچنان اجرا می‌شود، اما بدون کارت SD. این دستور هشدار « تصویر کارت SD وجود ندارد» را برمی‌گرداند.

اگر این گزینه را مشخص نکنید، پیش‌فرض sdcard.img در دایرکتوری داده است، مگر اینکه AVD چیز متفاوتی را مشخص کند. برای جزئیات بیشتر در مورد کارت‌های SD شبیه‌سازی شده، به دایرکتوری داده AVD مراجعه کنید.

-wipe-data داده‌های کاربر را حذف کرده و داده‌ها را از فایل داده اولیه کپی می‌کند. این گزینه داده‌ها را برای دستگاه مجازی پاک می‌کند و آن را به همان حالتی که برای اولین بار تعریف شده بود، برمی‌گرداند. تمام برنامه‌ها و تنظیمات نصب شده حذف می‌شوند. به عنوان مثال:

emulator @Pixel8_API_34 -wipe-data

به طور پیش‌فرض، فایل داده‌های کاربر userdata-qemu.img و فایل داده‌های اولیه userdata.img است. هر دوی این فایل‌ها در دایرکتوری داده‌ها قرار دارند. گزینه -wipe-data تاثیری بر فایل sdcard.img ندارد. برای اطلاعات بیشتر در مورد داده‌های کاربر، به بخشی با عنوان « درک دایرکتوری‌ها و فایل‌های پیش‌فرض» مراجعه کنید.

اشکال‌زدایی
-debug tags نمایش پیام‌های اشکال‌زدایی را برای یک یا چند برچسب فعال یا غیرفعال می‌کند. چندین برچسب را با فاصله، ویرگول یا ستون از هم جدا کنید. برای مثال:

$ emulator @Pixel8_API_34 -debug init,metrics

برای غیرفعال کردن یک برچسب، قبل از آن یک خط تیره (-) قرار دهید. برای مثال، گزینه زیر تمام پیام‌های اشکال‌زدایی را نمایش می‌دهد، به جز آنهایی که مربوط به سوکت‌های شبکه و معیارها هستند:

-debug all,-socket,-metrics

برای مشاهده‌ی فهرستی از برچسب‌ها و توضیحات، از گزینه‌ی -help-debug-tags استفاده کنید. برای مثال:

emulator -help-debug-tags

شما می‌توانید تگ‌های پیش‌فرض اشکال‌زدایی را در متغیر محیطی ANDROID_VERBOSE تعریف کنید. تگ‌هایی را که می‌خواهید استفاده کنید در یک لیست جدا شده با کاما تعریف کنید. در اینجا مثالی آورده شده است که نحوه مشخص کردن تگ‌های socket و gles را نشان می‌دهد:

ANDROID_VERBOSE=socket,gles

معادل استفاده از این است:

-debug-socket -debug-gles

یا

-debug socket,gles

-debug- tag
-debug-no- tag
یک نوع پیام اشکال‌زدایی خاص را فعال می‌کند. از فرم no برای غیرفعال کردن یک نوع پیام اشکال‌زدایی استفاده کنید. برای مثال:

emulator @Pixel8_API_34 -debug-all -debug-no-metrics

برای مشاهده لیست تگ‌ها، از دستور emulator -help-debug-tags استفاده کنید.

-logcat logtags نمایش پیام‌های Logcat را برای یک یا چند تگ فعال می‌کند و آنها را در پنجره ترمینال می‌نویسد. برای مثال، دستور زیر پیام‌های خطا را از همه اجزا فعال می‌کند:

emulator @Pixel8_API_34 -logcat *:e

logtags از همان قالب دستور adb logcat logtags استفاده می‌کند. برای اطلاعات بیشتر adb logcat -help را وارد کنید. این لیستی از فیلترهای گزارش است که با فاصله یا کاما از هم جدا شده‌اند و فرمت componentName : logLevel دارند. componentName می‌تواند یک ستاره ( * ) یا نام یک کامپوننت مانند ActivityManager ، SystemServer ، InputManager یا WindowManager باشد.

logLevel یکی از این مقادیر است:

  • v - مفصل
  • d - اشکال‌زدایی
  • i - آموزنده
  • w - سطح گزارش هشدار
  • خطای e
  • s - ساکت

مثال زیر پیام‌های مؤلفه GSM را در سطح گزارش اطلاعاتی نمایش می‌دهد:

emulator @Pixel8_API_34 -logcat '*:s GSM:i'

اگر گزینه -logcat در خط فرمان وارد نکنید، شبیه‌ساز به دنبال متغیر محیطی ANDROID_LOG_TAGS می‌گردد. اگر ANDROID_LOG_TAGS با مقدار logtags معتبر تعریف شده باشد و خالی نباشد، شبیه‌ساز از مقدار آن برای فعال کردن خروجی Logcat به ترمینال به طور پیش‌فرض استفاده می‌کند. همچنین می‌توانید همین پیام‌ها یا پیام‌های لاگ دیگر را از طریق adb به ترمینال هدایت کنید.

برای اطلاعات بیشتر در مورد Logcat و adb ، به ابزار خط فرمان Logcat ، مشاهده و نوشتن گزارش‌ها با Logcat ، کلاس Log و صدور دستورات adb مراجعه کنید.

-show-kernel پیام‌های اشکال‌زدایی هسته را در پنجره ترمینال نمایش می‌دهد. برای مثال:

emulator @Pixel8_API_34 -show-kernel

یکی از کاربردهای این گزینه، بررسی صحت عملکرد فرآیند بوت است.

-verbose پیام‌های مقداردهی اولیه شبیه‌ساز را در پنجره ترمینال چاپ می‌کند. برای مثال:

emulator @Pixel8_API_34 -verbose

این گزینه نمایش می‌دهد که هنگام شروع یک دستگاه مجازی تعریف شده در AVD، کدام فایل‌ها و تنظیمات در واقع انتخاب شده‌اند. این گزینه مشابه تعیین -debug-init است.

شبکه
-dns-server servers از سرورهای DNS مشخص شده استفاده می‌کند. servers لیستی از حداکثر چهار نام یا آدرس IP سرور DNS است که با کاما از هم جدا شده‌اند. برای مثال:
emulator @Pixel8_API_34 -dns-server 192.0.2.0,
192.0.2.255

به طور پیش‌فرض، شبیه‌ساز سعی می‌کند سرورهای DNS مورد استفاده شما را شناسایی کند و نام‌های مستعار خاصی را در شبکه فایروال شبیه‌سازی شده تنظیم می‌کند تا سیستم اندروید بتواند مستقیماً به سرورها متصل شود. از گزینه -dns-server برای مشخص کردن لیست متفاوتی از سرورهای DNS استفاده کنید.

-http-proxy proxy تمام اتصالات TCP را از طریق یک پروکسی HTTP/HTTPS مشخص شده برقرار می‌کند. اگر شبیه‌ساز شما باید از طریق یک سرور پروکسی به اینترنت دسترسی داشته باشد، می‌توانید از این گزینه یا متغیر محیطی http_proxy برای تنظیم تغییر مسیر مناسب استفاده کنید. به عنوان مثال:

emulator @Pixel8_API_34 -http-proxy myserver:1981

proxy می‌تواند یکی از موارد زیر باشد:

http:// server : port
http:// username : password @ server : port

پیشوند http:// را می‌توان حذف کرد.

اگر این گزینه ارائه نشود، شبیه‌ساز متغیر محیطی http_proxy را جستجو می‌کند و به‌طور خودکار از هر مقداری که با قالب proxy مطابقت دارد استفاده می‌کند. برای اطلاعات بیشتر، به استفاده از شبیه‌ساز با پروکسی مراجعه کنید.

-netdelay delay

شبیه‌سازی تأخیر شبکه را روی یکی از مقادیر delay زیر بر حسب میلی‌ثانیه تنظیم می‌کند:

  • gsm - GSM/CSD (حداقل ۱۵۰، حداکثر ۵۵۰).
  • hscsd - HSCSD (حداقل 80، حداکثر 400).
  • gprs - GPRS (حداقل ۳۵، حداکثر ۲۰۰).
  • edge - EDGE/EGPRS (حداقل ۸۰، حداکثر ۴۰۰).
  • umts - UMTS/3G (حداقل 35، حداکثر 200).
  • hsdpa - HSDPA (حداقل 0، حداکثر 0).
  • lte - LTE (حداقل 0، حداکثر 0).
  • evdo - ای‌وی‌دو (حداقل ۰، حداکثر ۰).
  • none - بدون تأخیر، پیش‌فرض (حداقل ۰، حداکثر ۰).
  • num - زمان تأخیر دقیق را مشخص می‌کند.
  • min : max - حداقل و حداکثر تأخیرهای جداگانه را مشخص می‌کند.

برای مثال:

emulator @Pixel8_API_34 -netdelay gsm

این شبیه‌ساز از تنظیم سرعت شبکه و همچنین تأخیر اتصال بالاتر پشتیبانی می‌کند. می‌توانید آن را یا از طریق پیکربندی پوسته یا با گزینه‌های ‑netspeed ‎ و -netdelay ‎ تعریف کنید.

-netfast تنظیم سرعت شبکه را غیرفعال می‌کند. برای مثال:

emulator @Pixel8_API_34 -netfast

این گزینه مشابه تعیین -netspeed full -netdelay none است. اینها مقادیر پیش‌فرض برای این گزینه‌ها هستند.

-netspeed speed

شبیه‌سازی سرعت شبکه را تنظیم می‌کند. حداکثر سرعت آپلود و دانلود شبکه را با یکی از مقادیر speed زیر بر حسب کیلوبیت بر ثانیه مشخص می‌کند:

  • gsm - GSM/CSD (افزایش: ۱۴.۴، کاهش: ۱۴.۴).
  • hscsd - HSCSD (افزایش: ۱۴.۴، کاهش: ۵۷.۶).
  • gprs - GPRS (افزایش: ۲۸.۸، کاهش: ۵۷.۶).
  • edge - EDGE/EGPRS (افزایش: ۴۷۳.۶، کاهش: ۴۷۳.۶).
  • umts - UMTS/3G (افزایش: ۳۸۴.۰، کاهش: ۳۸۴.۰).
  • hsdpa - HSDPA (افزایش: ۵۷۶۰٫۰، کاهش: ۱۳۹۸۰٫۰).
  • lte - LTE (افزایش: ۵۸۰۰۰، کاهش: ۱۷۳۰۰۰).
  • evdo - ای‌وی‌دو (افزایش: ۷۵۰۰۰، کاهش: ۲۸۰۰۰۰).
  • full - بدون محدودیت، پیش‌فرض (بالا: 0.0، پایین: 0.0).
  • num - سرعت آپلود و دانلود را مشخص می‌کند.
  • up : down - سرعت‌های بالا و پایین رفتن را به صورت جداگانه مشخص می‌کند.

برای مثال:

emulator @Pixel8_API_34 -netspeed edge

این شبیه‌ساز از تنظیم سرعت شبکه و همچنین تأخیر اتصال بالاتر پشتیبانی می‌کند. می‌توانید آن را یا از طریق پیکربندی پوسته یا با گزینه‌های ‑netspeed و -netdelay تعریف کنید.

-port port شماره پورت TCP مورد استفاده برای کنسول و adb را تنظیم می‌کند. برای مثال:

emulator @Pixel8_API_34 -port 5556

مقدار پیش‌فرض برای اولین نمونه دستگاه مجازی که روی دستگاه شما اجرا می‌شود، ۵۵۵۴ است. یک دستگاه مجازی معمولاً یک جفت پورت مجاور را اشغال می‌کند: یک پورت کنسول و یک پورت adb . کنسول اولین دستگاه مجازی که روی یک دستگاه خاص اجرا می‌شود، از پورت کنسول ۵۵۵۴ و پورت adb ۵۵۵۵ استفاده می‌کند. نمونه‌های بعدی از شماره پورت‌هایی استفاده می‌کنند که دو واحد افزایش می‌یابند. به عنوان مثال، ۵۵۵۶/۵۵۵۷، ۵۵۵۸/۵۵۵۹ و غیره. محدوده ۵۵۵۴ تا ۵۶۸۲ است که امکان ۶۴ دستگاه مجازی همزمان را فراهم می‌کند.

تخصیص پورت اغلب مشابه مشخص کردن -ports port ,{ port + 1} ‎ است. { port + 1} ‎ باید آزاد باشد و برای adb رزرو شده است. اگر هر یک از پورت‌های کنسول یا adb از قبل در حال استفاده باشند، شبیه‌ساز شروع به کار نخواهد کرد.

گزینه ‑port گزارش می‌دهد که دستگاه مجازی از کدام پورت‌ها و شماره سریال استفاده می‌کند و در صورت وجود هرگونه مشکل در مقادیر ارائه شده توسط شما، هشدار می‌دهد. در رابط کاربری شبیه‌ساز، می‌توانید شماره پورت کنسول را در عنوان پنجره مشاهده کنید و با انتخاب Help > About شماره پورت adb را مشاهده کنید.

توجه داشته باشید که اگر مقدار port زوج نباشد و در محدوده ۵۵۵۴ تا ۵۵۸۴ باشد، دستگاه مجازی هنگام استفاده از دستور adb devices شروع به کار می‌کند اما قابل مشاهده نیست، البته اگر adb server بعد از شبیه‌ساز شروع به کار کند. به همین دلیل، توصیه می‌کنیم از شماره پورت کنسول زوج استفاده کنید.

-ports
console-port , adb-port
پورت‌های TCP مورد استفاده برای کنسول و adb را تنظیم می‌کند. برای مثال:

emulator @Pixel8_API_34 -ports 5556,5559

محدوده پورت‌های معتبر بین ۵۵۵۴ تا ۵۶۸۲ است که امکان استفاده همزمان از ۶۴ دستگاه مجازی را فراهم می‌کند. گزینه -ports گزارش می‌دهد که نمونه شبیه‌ساز از کدام پورت‌ها و شماره سریال استفاده می‌کند و در صورت وجود هرگونه مشکل در مقادیر ارائه شده توسط شما، هشدار می‌دهد.

توصیه می‌کنیم در صورت امکان از گزینه -port استفاده کنید. گزینه -ports برای پیکربندی‌های شبکه‌ای که نیاز به تنظیمات ویژه دارند، در دسترس است.

برای اطلاعات بیشتر در مورد تنظیم پورت‌های کنسول و adb ، به گزینه -port ‎ مراجعه کنید.

-tcpdump filepath بسته‌های شبکه را ضبط کرده و آنها را در یک فایل ذخیره می‌کند. برای مثال:

emulator @Pixel8_API_34 -tcpdump /path/dumpfile.cap

از این گزینه برای شروع ضبط تمام بسته‌های شبکه‌ای که از طریق شبکه محلی مجازی اترنت شبیه‌ساز ارسال می‌شوند، استفاده کنید. پس از آن، می‌توانید از ابزاری مانند Wireshark برای تجزیه و تحلیل ترافیک استفاده کنید.

توجه داشته باشید که این گزینه تمام بسته‌های اترنت را ضبط می‌کند و محدود به اتصالات TCP نیست.

سیستم
-accel mode شتاب‌دهی ماشین مجازی شبیه‌ساز را پیکربندی می‌کند. برای مثال:

emulator @Pixel8_API_34 -accel auto

شبیه‌سازی شتاب‌یافته فقط برای ایمیج‌های سیستم x86 و x86_64 کار می‌کند. در لینوکس، به KVM متکی است. در ویندوز و مک، به پردازنده اینتل و درایور HAXM اینتل متکی است. اگر دستگاه x86 یا x86_64 را شبیه‌سازی نمی‌کنید، این گزینه نادیده گرفته می‌شود.

مقادیر معتبر برای mode عبارتند از:

  • auto - به طور خودکار تعیین می‌کند که آیا شتاب پشتیبانی می‌شود و در صورت امکان از آن استفاده می‌کند (پیش‌فرض).
  • off - شتاب را به طور کامل غیرفعال می‌کند، که در درجه اول برای اشکال‌زدایی مفید است.
  • on - شتاب را اجباری می‌کند. اگر KVM یا HAXM نصب یا قابل استفاده نباشند، شبیه‌ساز شروع به کار نمی‌کند و یک پیام خطا چاپ می‌کند.

برای اطلاعات بیشتر، به پیکربندی شتاب سخت‌افزاری برای شبیه‌ساز اندروید مراجعه کنید.

-accel-check بررسی می‌کند که آیا هایپروایزر مورد نیاز برای شتاب‌دهی ماشین مجازی شبیه‌ساز (HAXM یا KVM) نصب شده است یا خیر. برای مثال:

emulator -accel-check

برای اطلاعات بیشتر، به بررسی نصب بودن هایپروایزر مراجعه کنید.

-engine engine

موتور شبیه‌ساز را مشخص می‌کند:

  • auto - به طور خودکار یک موتور (پیش‌فرض) را انتخاب می‌کند.
  • classic - از موتور قدیمی‌تر QEMU 1 (منسوخ شده) استفاده می‌کند.
  • qemu2 - از موتور جدیدتر QEMU 2 استفاده می‌کند.

برای مثال:

emulator @Pixel8_API_34 -engine auto

تشخیص خودکار باید مقداری را انتخاب کند که هنگام شبیه‌سازی یک AVD خاص، بهترین عملکرد را ارائه دهد. از گزینه -engine فقط برای اشکال‌زدایی و مقایسه استفاده کنید.

-gpu mode حالت شبیه‌سازی GPU را انتخاب می‌کند. برای مثال:

emulator @Pixel8_API_34 -gpu swiftshader_indirect

برای اطلاعات بیشتر، به پیکربندی شتاب گرافیکی مراجعه کنید.

-no-accel شتاب‌دهی ماشین مجازی شبیه‌ساز را هنگام استفاده از تصویر سیستم x86 یا x86_64 غیرفعال می‌کند. این فقط برای اشکال‌زدایی مفید است و مانند تعیین -accel off عمل می‌کند. برای مثال:

emulator @Pixel8_API_34 -no-accel

برای اطلاعات بیشتر، به پیکربندی شتاب سخت‌افزاری برای شبیه‌ساز اندروید مراجعه کنید.

-nojni
-no-jni
بررسی‌های رابط بومی جاوا (JNI) را در Android Dalvik یا ART runtime غیرفعال می‌کند. برای مثال:

emulator @Pixel8_API_34 -nojni

وقتی یک دستگاه مجازی را راه‌اندازی می‌کنید، بررسی‌های JNI توسعه‌یافته به‌طور پیش‌فرض فعال می‌شوند. برای اطلاعات بیشتر، به نکات JNI مراجعه کنید.

-selinux {disabled|permissive} ماژول امنیتی SELinux (Security-Enhanced Linux) را در سیستم عامل لینوکس روی حالت disabled یا permissive تنظیم می‌کند. برای مثال:

me-linux$ emulator @Pixel8_API_34 -selinux permissive

به طور پیش‌فرض، SELinux در حالت enforcing mode) است، به این معنی که سیاست امنیتی اعمال می‌شود. حالت permissive mode) سیاست SELinux را بارگذاری می‌کند اما آن را اجرا نمی‌کند. این گزینه فقط موارد نقض سیاست را ثبت می‌کند. حالت disabled mode) پشتیبانی هسته از SELinux را غیرفعال می‌کند.

-timezone timezone

منطقه زمانی دستگاه مجازی را به جای منطقه زمانی میزبان، روی timezone تنظیم می‌کند. برای مثال:

emulator @Pixel8_API_34 -timezone Europe/Paris

به طور پیش‌فرض، شبیه‌ساز از منطقه زمانی رایانه توسعه‌دهنده شما استفاده می‌کند. از این گزینه برای تعیین منطقه زمانی متفاوت یا اگر تشخیص خودکار به درستی کار نمی‌کند، استفاده کنید. مقدار timezone باید در قالب zoneinfo باشد که به صورت area / location یا area / subarea / location است. برای مثال:

  • America/Los_Angeles
  • Europe/Paris
  • America/Argentina/Buenos_Aires

منطقه زمانی مشخص شده باید در پایگاه داده zoneinfo موجود باشد.

-version شماره نسخه شبیه‌ساز را نمایش می‌دهد. برای مثال:

emulator @Pixel8_API_34 -version

یا

emulator -version
رابط کاربری
-no-boot-anim انیمیشن بوت را در هنگام راه‌اندازی شبیه‌ساز غیرفعال می‌کند تا بوت سریع‌تر انجام شود. برای مثال:

emulator @Pixel8_API_34 -no-boot-anim

در رایانه‌های کندتر، این گزینه می‌تواند سرعت بوت شدن را به میزان قابل توجهی افزایش دهد.

-screen mode حالت صفحه لمسی شبیه‌سازی شده را تنظیم می‌کند. برای مثال:

emulator @Pixel8_API_34 -screen no-touch

mode می‌تواند هر یک از مقادیر زیر باشد:

  • touch - یک صفحه لمسی را شبیه‌سازی می‌کند (پیش‌فرض).
  • multi-touch - یک صفحه نمایش چند لمسی را شبیه‌سازی می‌کند.
  • no-touch - شبیه‌سازی صفحه لمسی و چند لمسی را غیرفعال می‌کند.

گزینه‌های پیشرفته

گزینه‌های راه‌اندازی خط فرمان در جدول زیر موجود هستند اما معمولاً توسط توسعه‌دهندگان برنامه‌ی معمولی استفاده نمی‌شوند.

در توضیحات، دایرکتوری کاری ، دایرکتوری فعلی در ترمینال است که در آن دستورات را وارد می‌کنید. برای اطلاعات مربوط به دایرکتوری سیستم AVD و دایرکتوری داده و فایل‌های ذخیره شده در آنها، به بخش مربوط به دایرکتوری‌ها و فایل‌های پیش‌فرض مراجعه کنید.

برخی از این گزینه‌ها برای توسعه‌دهندگان برنامه‌های خارجی مناسب هستند و برخی دیگر عمدتاً توسط توسعه‌دهندگان پلتفرم استفاده می‌شوند. توسعه‌دهندگان برنامه ، برنامه‌های اندروید را ایجاد کرده و آنها را روی AVD های خاص اجرا می‌کنند. توسعه‌دهندگان پلتفرم روی سیستم اندروید کار می‌کنند و آن را درون شبیه‌ساز و بدون AVD از پیش ایجاد شده اجرا می‌کنند.

جدول ۴. گزینه‌های پیشرفته خط فرمان

گزینه پیشرفته شرح مختصر
-bootchart timeout

فعال کردن بوت‌چارتینگ با زمان انقضا بر حسب ثانیه. برخی از تصاویر سیستم اندروید دارای یک سیستم init اصلاح‌شده هستند که امکان بوت‌چارتینگ را در خود جای داده است. می‌توانید با این گزینه، یک دوره زمانی انقضای بوت‌چارتینگ را به سیستم منتقل کنید. اگر بوت‌چارتینگ در سیستم init شما فعال نباشد، این گزینه هیچ کاری انجام نمی‌دهد. این گزینه در درجه اول برای توسعه‌دهندگان پلتفرم مفید است، نه توسعه‌دهندگان برنامه‌های خارجی.

برای مثال:

emulator @Pixel8_API_34 -bootchart 120
-cache filepath

یک فایل تصویر پارتیشن حافظه پنهان را مشخص می‌کند. یک نام فایل و یک مسیر مطلق یا یک مسیر نسبت به دایرکتوری داده برای تنظیم یک فایل حافظه پنهان پایدار ارائه می‌دهد. اگر فایل وجود نداشته باشد، شبیه‌ساز آن را به عنوان یک فایل خالی ایجاد می‌کند.

برای مثال:

emulator @Pixel8_API_34 -cache
   ~/.android/avd/Pixel8_API_34.avd/cache_persistent.img

اگر از این گزینه استفاده نکنید، پیش‌فرض یک فایل موقت با نام cache.img است. برای اطلاعات بیشتر، به فهرست داده‌های AVD مراجعه کنید.

-cache-size size

اندازه پارتیشن کش را بر حسب مگابایت تنظیم می‌کند.

برای مثال:

emulator @Pixel8_API_34 -cache-size 1000

اگر این گزینه را مشخص نکنید، پیش‌فرض ۶۶ مگابایت است. معمولاً، اکثر توسعه‌دهندگان برنامه به این گزینه نیاز ندارند، مگر اینکه نیاز به دانلود فایل‌های بسیار بزرگی داشته باشند که از حافظه پنهان پیش‌فرض بزرگتر باشند. برای اطلاعات بیشتر در مورد فایل حافظه پنهان، به فهرست داده‌های AVD مراجعه کنید.

-data filepath

فایل تصویر پارتیشن داده‌های کاربر را تنظیم می‌کند. یک نام فایل و یک مسیر مطلق یا یک مسیر نسبت به دایرکتوری کاری برای راه‌اندازی یک فایل داده کاربر دائمی ارائه می‌دهد. اگر فایل وجود نداشته باشد، شبیه‌ساز یک تصویر از فایل پیش‌فرض userdata.img ایجاد می‌کند، آن را در نام فایلی که شما مشخص کرده‌اید ذخیره می‌کند و داده‌های کاربر را در هنگام خاموش شدن در آن ذخیره می‌کند.

برای مثال:

emulator @Pixel8_API_34 -data
   ~/.android/avd/Pixel8_API_34.avd/userdata-test.img

اگر از این گزینه استفاده نکنید، فایل پیش‌فرض userdata-qemu.img است. برای اطلاعات بیشتر در مورد فایل داده‌های کاربر، به دایرکتوری داده‌های AVD مراجعه کنید.

-datadir dir

یک دایرکتوری داده را با استفاده از یک مسیر مطلق مشخص می‌کند. برای اطلاعات بیشتر، به دایرکتوری داده AVD مراجعه کنید.

برای مثال:

emulator @Pixel8_API_34 -datadir
   ~/.android/avd/Pixel8_API_34.avd/mytest
-force-32bit

از شبیه‌ساز ۳۲ بیتی روی پلتفرم‌های ۶۴ بیتی استفاده می‌کند. گاهی اوقات، این گزینه برای آزمایش یا اشکال‌زدایی مفید است. برای مثال، مشکلی وجود داشت که شبیه‌ساز گاهی اوقات روی ویندوز ۶۴ بیتی اجرا نمی‌شد، اما ۳۲ بیتی اجرا می‌شد. این گزینه برای انجام مقایسه‌ها برای اشکال‌زدایی مشکل مفید بود. در اینجا مثالی آورده شده است:

emulator @Pixel8_API_34 -force-32bit
-help-disk-images

در مورد تصاویر دیسک کمک می‌گیرد. این گزینه اطلاعاتی مرتبط با توسعه‌دهندگان برنامه و پلتفرم ارائه می‌دهد. برای مثال:

emulator -help-disk-images
-help-char-devices

در مورد مشخصات device کاراکتری کمک می‌گیرد. پارامتر device توسط برخی از گزینه‌های شبیه‌ساز مورد نیاز است. برای مثال:

emulator -help-char-devices
-help-sdk-images

در مورد تصاویر دیسک مربوط به توسعه‌دهندگان برنامه، راهنمایی دریافت می‌کند. این گزینه اطلاعاتی در مورد محل قرارگیری فایل‌های تصویر برای AVD ایجاد شده با ابزارهای SDK ارائه می‌دهد. برای مثال:

emulator -help-sdk-images
-help-build-images

در مورد تصاویر دیسک مربوط به توسعه‌دهندگان پلتفرم کمک می‌گیرد. برای مثال:

emulator -help-build-images
-initdata filepath
-init-data filepath

نسخه اولیه پارتیشن داده را مشخص می‌کند. پس از پاک کردن داده‌های کاربر، شبیه‌ساز به جای استفاده از فایل پیش‌فرض userdata.img به عنوان نسخه اولیه، محتویات فایل مشخص شده را در داده‌های کاربر (به طور پیش‌فرض، فایل userdata-qemu.img ) کپی می‌کند. نام فایل و یک مسیر مطلق یا یک مسیر نسبت به دایرکتوری کاری را مشخص می‌کند.

برای مثال:

emulator @Pixel8_API_34 -initdata
   ~/Library/Android/sdk/system-images/android-34/
   google_apis/x86_64/userdata-test.img

اگر مسیری مشخص نکنید، فایل را در دایرکتوری سیستم قرار می‌دهد. برای اطلاعات بیشتر، به دایرکتوری سیستم AVD مراجعه کنید.

-kernel filepath

از یک هسته شبیه‌سازی‌شده خاص استفاده می‌کند. اگر مسیری را مشخص نکنید، شبیه‌ساز در دایرکتوری سیستم جستجو می‌کند.

برای مشاهده پیام‌های اشکال‌زدایی هسته، از گزینه ‑show‑kernel استفاده کنید.

برای مثال:

emulator @Pixel8_API_34 -kernel
   ~/Library/Android/sdk/system-images/android-34/
   google_apis/x86_64/kernel-test.img -show-kernel

اگر این گزینه را مشخص نکنید، پیش‌فرض kernel-ranchu است. برای اطلاعات بیشتر، به دایرکتوری سیستم AVD مراجعه کنید.

-noaudio
-no-audio

پشتیبانی صوتی را برای این دستگاه مجازی غیرفعال می‌کند. برخی از رایانه‌های لینوکس و ویندوز درایورهای صوتی معیوبی دارند که باعث بروز علائم مختلفی مانند جلوگیری از شروع شبیه‌ساز می‌شوند. در این حالت، از این گزینه برای غلبه بر مشکل استفاده کنید. به عنوان یک جایگزین، می‌توانید از متغیر محیطی QEMU_AUDIO_DRV برای تغییر backend صوتی استفاده کنید.

برای مثال:

emulator @Pixel8_API_34 -noaudio
-nocache
-no-cache

شبیه‌ساز را بدون پارتیشن کش اجرا می‌کند. اگر از این گزینه استفاده نکنید، پیش‌فرض یک فایل موقت با نام cache.img است. این گزینه فقط برای توسعه‌دهندگان پلتفرم است. برای اطلاعات بیشتر، به دایرکتوری داده AVD مراجعه کنید.

برای مثال:

emulator @Pixel8_API_34 -nocache
-no-snapshot

مانع از اجرای خودکار عملیات بارگذاری و ذخیره می‌شود و باعث می‌شود شبیه‌ساز یک توالی بوت کامل را اجرا کند و هنگام بسته شدن، وضعیت خود را از دست بدهد. این گزینه -snapshot را لغو می‌کند.

برای مثال:

emulator @Pixel8_API_34 -no-snapshot
-no-snapshot-load

از بارگذاری وضعیت AVD از حافظه اسنپ‌شات توسط شبیه‌ساز جلوگیری می‌کند. بوت کامل را انجام می‌دهد.

برای مثال:

emulator @Pixel8_API_34 -no-snapshot-load
-no-snapshot-save

از ذخیره وضعیت AVD در حافظه اسنپ‌شات توسط شبیه‌ساز در هنگام خروج جلوگیری می‌کند، به این معنی که تمام تغییرات از بین خواهند رفت.

برای مثال:

emulator @Pixel8_API_34 -no-snapshot-save
-no-snapshot-update-time

سعی نمی‌کند زمان ساعت AVD را بلافاصله پس از بازیابی اسنپ‌شات اصلاح کند. این گزینه می‌تواند در حین آزمایش مفید باشد زیرا از پرش ناگهانی زمان جلوگیری می‌کند. به‌روزرسانی‌های زمان همچنان تقریباً هر ۱۵ ثانیه به AVD ارسال می‌شوند.

برای مثال:

emulator @Pixel8_API_34 -no-snapshot-update-time
-no-snapstorage

شبیه‌ساز را بدون نصب فایلی برای ذخیره یا بارگذاری اسنپ‌شات‌های وضعیت، راه‌اندازی می‌کند و بوت کامل را اجباری کرده و قابلیت اسنپ‌شات وضعیت را غیرفعال می‌کند. این گزینه، گزینه‌های -snapstorage و -snapshot را لغو می‌کند.

برای مثال:

emulator @Pixel8_API_34 -no-snapstorage
-no-window

نمایش پنجره گرافیکی را در شبیه‌ساز غیرفعال می‌کند. این گزینه هنگام اجرای شبیه‌ساز روی سرورهایی که نمایشگر ندارند مفید است. می‌توانید از طریق adb یا کنسول به شبیه‌ساز دسترسی داشته باشید. برای مثال:

emulator @Pixel8_API_34 -no-window
-partition-size size

اندازه پارتیشن داده سیستم را بر حسب مگابایت مشخص می‌کند. برای مثال:

emulator @Pixel8_API_34 -partition-size 1024
-prop name = value

هنگام بوت شدن شبیه‌ساز، یک ویژگی سیستم اندروید را در آن تنظیم می‌کند. name باید یک نام ویژگی با برچسب qemu_prop باشد که حداکثر ۳۲ کاراکتر و بدون هیچ فاصله‌ای داشته باشد و value باید رشته‌ای با حداکثر ۹۲ کاراکتر باشد. برای مثال، به فایل property_contexts مراجعه کنید. می‌توانید چندین گزینه ‑prop را در یک خط فرمان مشخص کنید. این گزینه می‌تواند برای اشکال‌زدایی مفید باشد. به عنوان مثال:

emulator @Pixel8_API_34 -prop qemu.name=value -prop qemu.abc=xyz
-qemu args آرگومان‌ها را به نرم‌افزار شبیه‌ساز QEMU ارسال می‌کند. هنگام استفاده از این گزینه، مطمئن شوید که آخرین گزینه مشخص شده باشد، زیرا تمام گزینه‌های بعد از آن به عنوان گزینه‌های مخصوص QEMU تفسیر می‌شوند. این گزینه کاملاً پیشرفته است و فقط باید توسط توسعه‌دهندگانی که با QEMU و شبیه‌سازی اندروید بسیار آشنا هستند، استفاده شود.
-qemu -h

-qemu ‎ را برای کمک نمایش می‌دهد. برای مثال:

emulator -qemu -h
-ramdisk filepath

یک تصویر بوت ramdisk را مشخص می‌کند. نام فایل و یک مسیر مطلق یا یک مسیر نسبت به دایرکتوری کاری را مشخص می‌کند.

برای مثال:

emulator @Pixel8_API_34 -ramdisk
   ~/Library/Android/sdk/system-images/android-34/
   google_apis/x86_64/ramdisk-test.img

اگر از این گزینه استفاده نکنید، فایل پیش‌فرض ramdisk.img در دایرکتوری سیستم است. برای اطلاعات بیشتر، به دایرکتوری سیستم AVD مراجعه کنید.

-report-console socket

قبل از شروع شبیه‌سازی، پورت کنسول را به یک شخص ثالث از راه دور گزارش می‌دهد. این می‌تواند برای یک اسکریپت تست خودکار مفید باشد. socket باید از یکی از این قالب‌ها استفاده کند:

  • tcp: port [,server][,max= seconds ][,ipv6]
  • unix: port [,server][,max= seconds ][,ipv6]

برای اطلاعات بیشتر، از گزینه -help-report-console همانطور که در بخش مربوط به کمک برای گزینه‌های خاص توضیح داده شده است، استفاده کنید.

-shell

یک کنسول پوسته ریشه در ترمینال فعلی ایجاد می‌کند. این گزینه با دستور adb shell از جهات زیر متفاوت است:

  • این یک پوسته ریشه ایجاد می‌کند که به شما امکان می‌دهد بسیاری از قسمت‌های سیستم را تغییر دهید.
  • حتی اگر adb daemon در سیستم شبیه‌سازی‌شده خراب باشد، این برنامه کار می‌کند.
  • برای متوقف کردن شبیه‌ساز به جای پوسته، کلیدهای Control+C (یا Command-C در macOS) را فشار دهید.

برای مثال:

emulator @Pixel8_API_34 -shell
-snapshot name

نام یک اسنپ‌شات را در فایل ذخیره‌سازی اسنپ‌شات برای عملیات شروع و ذخیره خودکار مشخص می‌کند.

به جای اجرای یک توالی بوت کامل، شبیه‌ساز می‌تواند اجرا را از یک اسنپ‌شات وضعیت قبلی از سر بگیرد، که معمولاً به طور قابل توجهی سریع‌تر است. وقتی این گزینه را فعال می‌کنید، شبیه‌ساز اسنپ‌شات آن نام را از تصویر اسنپ‌شات بارگذاری می‌کند و در هنگام خروج، آن را با همان نام ذخیره می‌کند.

اگر از این گزینه استفاده نکنید، پیش‌فرض یک توالی بوت کامل است. اگر snapshot مشخص شده وجود نداشته باشد، شبیه‌ساز به جای آن یک توالی بوت کامل را انجام می‌دهد و عملیات ذخیره را انجام می‌دهد.

برای اطلاعات بیشتر در مورد مشخص کردن فایل ذخیره‌سازی اسنپ‌شات و فایل پیش‌فرض، به گزینه -snapstorage مراجعه کنید.

emulator @Pixel8_API_34 -snapshot snapshot2

به یاد داشته باشید که در فرآیند بارگذاری یک اسنپ‌شات، تمام محتویات سیستم، داده‌های کاربر و تصاویر کارت SD با محتویاتی که هنگام تهیه اسنپ‌شات در اختیار داشتند، رونویسی می‌شوند. مگر اینکه این اطلاعات را در یک اسنپ‌شات دیگر ذخیره کنید، هرگونه تغییری از آن زمان از بین می‌رود.

همچنین می‌توانید با استفاده از دستور avd snapshot save name از کنسول شبیه‌ساز یک snapshot ایجاد کنید. برای اطلاعات بیشتر، به بخش «ارسال دستورات کنسول شبیه‌ساز» مراجعه کنید.

-snapshot-list

فهرستی از اسنپ‌شات‌های موجود را نمایش می‌دهد. این دستور جدولی از اسنپ‌شات‌هایی که در فایل ذخیره‌سازی اسنپ‌شات که شبیه‌ساز با آن شروع به کار کرده است ذخیره شده‌اند را چاپ می‌کند و سپس از آن خارج می‌شود. اگر -snapstorage file نیز مشخص کنید، این دستور جدولی از اسنپ‌شات‌های ذخیره شده در file را چاپ می‌کند.

برای مثال:

emulator @Pixel8_API_34 -snapshot-list -snapstorage
   ~/.android/avd/Pixel8_API_34.avd/snapshots-test.img

می‌توانید از مقادیر ستون‌های ID و TAG در خروجی به عنوان آرگومان برای گزینه -snapshot ‎ استفاده کنید.

-snapstorage filepath

یک فایل مخزن را مشخص می‌کند که شامل تمام اسنپ‌شات‌های وضعیت است. تمام اسنپ‌شات‌های ایجاد شده در حین اجرا در این فایل ذخیره می‌شوند. فقط اسنپ‌شات‌های موجود در این فایل می‌توانند در حین اجرای شبیه‌ساز بازیابی شوند.

برای مثال:

emulator @Pixel8_API_34 -snapstorage
   ~/.android/avd/Pixel8_API_34.avd/snapshots-test.img

اگر این گزینه را مشخص نکنید، پیش‌فرض snapshots.img در دایرکتوری داده است. اگر فایل مشخص شده وجود نداشته باشد، شبیه‌ساز شروع به کار می‌کند، اما بدون پشتیبانی از ذخیره یا بارگذاری snapshotهای وضعیت.

-sysdir dir

یک دایرکتوری سیستم را با استفاده از یک مسیر مطلق مشخص می‌کند. برای اطلاعات بیشتر، به دایرکتوری سیستم AVD مراجعه کنید. به عنوان مثال:

emulator @Pixel8_API_34 -sysdir
   ~/Library/Android/sdk/system-images/android-34/
   google_apis/x86_64/test
-system filepath

یک فایل سیستم اولیه را مشخص می‌کند. نام فایل و یک مسیر مطلق یا یک مسیر نسبت به دایرکتوری کاری را ارائه می‌دهد.

برای مثال:

emulator @Pixel8_API_34 -system
   ~/Library/Android/sdk/system-images/android-34/
   google_apis/x86_64/system-test.img

اگر از این گزینه استفاده نکنید، پیش‌فرض فایل system.img در دایرکتوری سیستم است. برای اطلاعات بیشتر، به دایرکتوری سیستم AVD مراجعه کنید.

-writable-system

از این گزینه برای داشتن یک تصویر سیستم قابل نوشتن در طول جلسه شبیه‌سازی خود استفاده کنید. برای انجام این کار:

  1. Start a virtual device with the -writable-system option.
  2. Enter the adb remount command from a command terminal to tell the emulator to remount system/ as read/write. By default, it's mounted as read-only.

Using this flag creates a temporary copy of the system image that can be very large, up to several hundred MBs, but will be destroyed when the emulator exits.

گزینه‌های منسوخ‌شده

The following command-line options are deprecated:

  • -audio-in
  • -audio-out
  • -charmap
  • -code-profile
  • -cpu-delay
  • -dpi-device
  • -dynamic_skin
  • -enable-kvm
  • -gps
  • -image
  • -keyset
  • -help-keys
  • -help-keyset-file
  • -nand-limits
  • -noskin
  • -no-skin
  • -onion
  • -onion-alpha
  • -onion-rotation
  • -radio
  • -ranchu
  • -raw-keys
  • -scale
  • -shared-net-id
  • -shell-serial
  • -skin
  • -skindir
  • -trace
  • -useaudio

Get help about command-line options

This section describes how to get help about the command-line options. It provides more in-depth information about the commonly used emulator command-line options that are available when you start the emulator.

List all emulator options

To print a list of all emulator options, including a short description, enter the following command:

emulator -help

Get detailed help for a specific option

To print help for a specific startup option, enter the following command:

emulator -help-option

برای مثال:

emulator -help-netspeed

This help is more detailed than the description provided by the -help option.

Get detailed help for all options

To get detailed help for all emulator options, enter the following command:

emulator -help-all

List emulator environment variables

To get a list of emulator environment variables, enter the following command:

emulator -help-environment

You can set environment variables in the terminal window before launching a virtual device, or you can set it through your user settings in the operating system. For example, set it in your .bashrc file on Linux.

List debug tags

To print a list of tags for the -debug options, enter the following command:

emulator -help-debug-tags

The -debug options let you enable or disable debug messages from specific emulator components, as specified by the tags.

،

The Android SDK includes an Android device emulator—a virtual device that runs on your computer. The Android Emulator lets you develop and test Android apps without using a physical device.

This page describes command-line features that you can use with the Android Emulator. For information about using the Android Emulator UI, see Run apps on the Android Emulator .

Start the emulator

Use the emulator command to start the emulator, as an alternative to running your project or starting it through the AVD Manager .

Here's the basic command-line syntax for starting a virtual device from a terminal prompt:

emulator -avd avd_name [ {-option [value]} … ]

یا

emulator @avd_name [ {-option [value]} … ]

For example, if you launch the emulator from within Android Studio running on a Mac, the default command line will be similar to the following:

/Users/janedoe/Library/Android/sdk/emulator/emulator -avd Pixel8_API_34 -netdelay none -netspeed full -qt-hide-window -grpc-use-token -idle-grpc-timeout

Please note that the arguments -qt-hide-window -grpc-use-token -idle-grpc-timeout are only used to run the emulator window within Android Studio. If you want to run the emulator on its own window, you should not use those extra parameters.

You can specify startup options when you start the emulator, but not after it has started.

For a list of AVD names, enter the following command:

emulator -list-avds

Use this option to display a list of AVD names from your Android home directory. You can override the default home directory by setting the ANDROID_SDK_HOME environment variable that specifies the root of the user-specific directory where all configuration and AVD content is stored.

You can set the environment variable in the terminal window before launching a virtual device or through your user settings in the operating system. For example, in your .bashrc file on Linux.

To stop the Android Emulator, close the emulator window.

نصب یک برنامه

In addition to installing an app through Android Studio or the emulator UI , you can install your app on a virtual device by using the adb utility.

To use adb to install, run, and test your app, follow these general steps:

  1. Build and package your app into an APK, as described in Build and run your app .
  2. Start the emulator from the command line, as described in the previous section, using any startup options necessary.
  3. Install your app using adb .
  4. Run and test your app on the emulator.
    While the emulator is running, you can use the Emulator console to issue commands as needed.

To uninstall an app, do so as you would on an Android device.

The virtual device preserves the app and its state data across restarts in a user data disk partition ( userdata-qemu.img ). To clear this data, start the emulator with the -wipe-data option or wipe the data in the AVD Manager. For more information about the user data partition and other storage, see the following section.

Note: The adb utility views the virtual device as an actual physical device. For this reason, you might have to use the -d flag with some common adb commands, such as install . The -d flag lets you specify which of several connected devices to use as the target of a command. If you don't specify -d , the emulator targets the first device in its list.

Understand the default directories and files

The emulator uses associated files, of which the AVD system and data directories are the most important. It's helpful to understand the emulator directory structure and files when specifying command-line options, although you typically don't need to modify the default directories or files.

The Android Emulator uses the ( QEMU ) hypervisor.

AVD system directory

The system directory contains the Android system images that the emulator uses to simulate the operating system. This directory has platform-specific, read-only files shared by all AVDs of the same type, including API level, CPU architecture, and Android variant. The default locations are the following:

  • macOS and Linux - ~/Library/Android/sdk/system-images/android- apiLevel / variant / arch /
  • Windows - C:\Users\ user \Library\Android\sdk\system-images\android- apiLevel \ variant \ arch \

کجا:

  • apiLevel is a numeric API level or a letter for preview releases. For example, android-V indicates the Android VanillaIceCream preview. On release, it became API level 35, designated by android-35 .
  • variant is a name corresponding to specific features implemented by the system image. For example, google_apis or android-wear .
  • arch is the target CPU architecture. For example, x86 .

Use the -sysdir option to specify a different system directory for the AVD.

The emulator reads the following files from the system directory:

Table 1. System directory files read by the Android Emulator

فایل توضیحات Option to specify a different file
kernel-qemu or kernel-ranchu The binary kernel image for the AVD. kernel-ranchu is based on the QEMU emulator. -kernel
ramdisk.img The boot partition image. This is a subset of system.img loaded by the kernel initially before the system image is mounted. It typically contains just a few binaries and initialization scripts. -ramdisk
system.img The read-only, initial version of the system image. Specifically, the partition containing the system libraries and data corresponding to the API level and variant. -system
userdata.img The initial version of the data partition, which appears as data/ in the emulated system and contains all writable data for the AVD. The emulator uses this file when you create a new AVD or use the ‑wipe-data option. For more information, see the userdata-qemu.img file description in the following section. -initdata
-init-data

AVD data directory

The AVD data directory, also called the content directory, is specific to a single AVD instance and contains all modifiable data for the AVD.

The default location is the following, where name is the AVD name:

  • macOS and Linux - ~/.android/avd/ name .avd/
  • Windows 10, and higher - C:\Users\ user \.android\ name .avd\

Use the -datadir option to specify a different AVD data directory.

The following table lists the most important files contained in this directory:

Table 2. Important files in the AVD data directory

فایل توضیحات Option to specify a different file
userdata-qemu.img

The content of the data partition, which appears as data/ in the emulated system. When you create a new AVD or when you use the -wipe-data option to reset the AVD to the factory defaults, the emulator copies the userdata.img file in the system directory to create this file.

Each virtual device instance uses a writable user-data image to store user and session-specific data. For example, it uses the image to store a unique user's installed app data, settings, databases, and files. Each user has a different ANDROID_SDK_HOME directory that stores the data directories for the AVDs created by that user. Each AVD has a single userdata-qemu.img file.

-data
cache.img The cache partition image, which appears as cache/ in the emulated system. It's empty when you first create an AVD or use the -wipe-data option. It stores temporary download files and is populated by the download manager and sometimes the system. For example, the browser uses it to cache downloaded web pages and images while the emulator is running. When you power off the virtual device, the file is deleted. You can persist the file by using the -cache option. -cache
sdcard.img

(Optional) An SD card partition image that lets you simulate an SD card on a virtual device. You can create an SD card image file in the AVD Manager or using the mksdcard tool. The file is stored on your development computer and must be loaded at startup.

When defining an AVD in the AVD Manager, you can choose to use an automatically managed SD card file or a file that you created with the mksdcard tool. You can view the sdcard.img file associated with an AVD in the AVD Manager. The -sdcard option overrides the SD card file specified in the AVD. Note that this SD Card option will not work on Mac with Apple Silicon.

You can browse, send files to, and copy and remove files from a simulated SD card by using the emulator UI or the adb utility while the virtual device is running. You can't remove a simulated SD card from a running virtual device.

To copy files to the SD card file before loading it, mount the image file as a loop device and then copy the files. Or, use a utility, such as the mtools package, to copy the files directly to the image.

The emulator treats the file as a pool of bytes, so the SD card format doesn't matter.

The -wipe-data option doesn't affect this file. If you want to clear the file, delete the file and then re-create it using the AVD Manager or the mksdcard tool. Changing the size of the file also deletes the file and creates a new file.

-sdcard

List directories and files used by the emulator

You can discover where files are located in two ways:

  • Use the -verbose or -debug init option when you start the emulator from the command line. Look at the output.
  • Use the emulator -help- option command to list a default directory. For example:
    emulator -help-datadir
    Use '-datadir <dir>' to specify a directory where writable image files will be searched. On this system, the default directory is: /Users/me/.android See '-help-disk-images' for more information about disk image files.

Command-line startup options

This section lists options you can supply on the command line when you start the emulator.

Note: The Android Emulator is continually under development to make it more reliable. For status on the issues reported against various command-line options and to report bugs, see the Android Issue Tracker .

Commonly used options

The following table lists command-line startup options that you might use more often:

Table 3. Commonly used command-line options

Command-line option توضیحات
Quick Boot
-no-snapshot-load Performs a cold boot and saves the emulator state on exit.
-no-snapshot-save Performs a quick boot if possible, but does not save the emulator state on exit.
-no-snapshot Disables the Quick Boot feature completely and doesn't load or save the emulator state.
Device Hardware
-camera-back mode
-camera-front mode
Sets the emulation mode for a camera facing back or front. This overrides any camera setting in the AVD.

mode can be any of the following values:

  • emulated - The emulator simulates a camera in the software.
  • webcam n - The emulator uses a webcam connected to your development computer, specified by number. For a list of webcams, use the -webcam-list option. For example, webcam0 .
  • none - Disables the camera in the virtual device.

برای مثال:

emulator @Pixel8_API_34 -camera-back webcam0
-webcam-list Lists the webcams on your development computer that are available for emulation. For example:
emulator @Pixel8_API_34 -webcam-list
        List of web cameras connected to the computer:
        Camera 'webcam0' is connected to device 'webcam0'
        on channel 0 using pixel format 'UYVY'

In the example, the first webcam0 is the name you use on the command line. The second webcam0 is the name used by the OS on the development computer. The second name varies depending on the OS.

As of SDK Tools 25.2.4, the AVD name is required.

Disk images and memory
-memory size

Specifies the physical RAM size, from 1536 to 8192 MBs. For example:

emulator @Pixel8_API_34 -memory 2048

This value overrides the AVD setting.

-sdcard filepath Specifies the filename and path to an SD card partition image file. For example:

emulator @Pixel8_API_34 -sdcard C:/sd/sdcard.img

If the file isn't found, the emulator still launches, but without an SD card. The command returns a No SD Card Image warning.

If you don't specify this option, the default is sdcard.img in the data directory unless the AVD specifies something different. For details about emulated SD cards, see AVD data directory .

-wipe-data Deletes user data and copies data from the initial data file. This option clears the data for the virtual device and returns it to the same state as when it was first defined. All installed apps and settings are removed. For example:

emulator @Pixel8_API_34 -wipe-data

By default, the user data file is userdata-qemu.img and the initial data file is userdata.img . Both of these files reside in the data directory. The -wipe-data option doesn't affect the sdcard.img file. For more information about user data, see the section called Understand the default directories and files .

اشکال‌زدایی
-debug tags Enables or disables the display of debug messages for one or more tags. Separate multiple tags by a space, comma, or column. For example:

$ emulator @Pixel8_API_34 -debug init,metrics

To disable a tag, place a dash (-) in front of it. For example, the following option displays all debug messages, except the ones related to network sockets and metrics:

-debug all,-socket,-metrics

For a list of tags and descriptions, use the -help-debug-tags option. For example:

emulator -help-debug-tags

You can define the default debug tags in the ANDROID_VERBOSE environment variable. Define the tags you want to use in a comma-delimited list. Here's an example that shows how to specify the socket and gles tags:

ANDROID_VERBOSE=socket,gles

It's equivalent to using:

-debug-socket -debug-gles

یا

-debug socket,gles

-debug- tag
-debug-no- tag
Enables a specific debug message type. Use the no form to disable a debug message type. For example:

emulator @Pixel8_API_34 -debug-all -debug-no-metrics

For a list of tags, use the emulator -help-debug-tags command.

-logcat logtags Enables the display of Logcat messages for one or more tags and writes them to the terminal window. For example, the following command enables error messages from all components:

emulator @Pixel8_API_34 -logcat *:e

logtags uses the same format as the adb logcat logtags command. Enter adb logcat -help for more information. It's a list of space- or comma-separated log filters of the format componentName : logLevel . componentName is either a wildcard asterisk ( * ) or a component name, such as ActivityManager , SystemServer , InputManager , or WindowManager .

logLevel is one of these values:

  • v - verbose
  • d - debug
  • i - informative
  • w - warning log level
  • e - error
  • s - silent

The following example displays GSM component messages at the informative log level:

emulator @Pixel8_API_34 -logcat '*:s GSM:i'

If you don't supply the -logcat option on the command line, the emulator looks for the ANDROID_LOG_TAGS environment variable. If ANDROID_LOG_TAGS is defined with a valid logtags value and isn't empty, the emulator uses its value to enable Logcat output to the terminal by default. You can also redirect the same or other log messages to the terminal through adb .

For more information about Logcat and adb , see Logcat command-line tool , View and write logs with Logcat , Log class, and Issue adb commands .

-show-kernel Displays kernel debug messages in the terminal window. For example:

emulator @Pixel8_API_34 -show-kernel

One use of this option is to check that the boot process works correctly.

-verbose Prints emulator initialization messages to the terminal window. For example:

emulator @Pixel8_API_34 -verbose

It displays which files and settings are actually selected when starting a virtual device defined in an AVD. This option is the same as specifying -debug-init .

شبکه
-dns-server servers Uses the specified DNS servers. servers is a comma-separated list of up to four DNS server names or IP addresses. For example:
emulator @Pixel8_API_34 -dns-server 192.0.2.0,
192.0.2.255

By default, the emulator tries to detect the DNS servers you're using and sets up special aliases in the emulated firewall network to allow the Android system to connect directly to the servers. Use the -dns-server option to specify a different list of DNS servers.

-http-proxy proxy Makes all TCP connections through a specified HTTP/HTTPS proxy. If your emulator must access the internet through a proxy server, you can use this option or the http_proxy environment variable to set up the appropriate redirection. For example:

emulator @Pixel8_API_34 -http-proxy myserver:1981

proxy can be one of the following:

http:// server : port
http:// username : password @ server : port

The http:// prefix can be omitted.

If this option isn't supplied, the emulator looks up the http_proxy environment variable and automatically uses any value matching the proxy format. For more information, see Using the emulator with a proxy .

-netdelay delay

Sets network latency emulation to one of the following delay values in milliseconds:

  • gsm - GSM/CSD (min 150, max 550).
  • hscsd - HSCSD (min 80, max 400).
  • gprs - GPRS (min 35, max 200).
  • edge - EDGE/EGPRS (min 80, max 400).
  • umts - UMTS/3G (min 35, max 200).
  • hsdpa - HSDPA (min 0, max 0).
  • lte - LTE (min 0, max 0).
  • evdo - EVDO (min 0, max 0).
  • none - No latency, the default (min 0, max 0).
  • num - Specifies exact latency.
  • min : max - Specifies individual minimum and maximum latencies.

برای مثال:

emulator @Pixel8_API_34 -netdelay gsm

The emulator supports network throttling as well as higher connection latencies. You can define it either through the skin configuration or with the ‑netspeed and -netdelay options.

-netfast Disables network throttling. For example:

emulator @Pixel8_API_34 -netfast

This option is the same as specifying -netspeed full -netdelay none . These are the default values for these options.

-netspeed speed

Sets the network speed emulation. Specifies the maximum network upload and download speeds with one of the following speed values in kbps:

  • gsm - GSM/CSD (up: 14.4, down: 14.4).
  • hscsd - HSCSD (up: 14.4, down: 57.6).
  • gprs - GPRS (up: 28.8, down: 57.6).
  • edge - EDGE/EGPRS (up: 473.6, down: 473.6).
  • umts - UMTS/3G (up: 384.0, down: 384.0).
  • hsdpa - HSDPA (up: 5760.0, down: 13,980.0).
  • lte - LTE (up: 58,000, down: 173,000).
  • evdo - EVDO (up: 75,000, down: 280,000).
  • full - No limit, the default (up: 0.0, down: 0.0).
  • num - Specifies both upload and download speed.
  • up : down - Specifies individual up and down speeds.

برای مثال:

emulator @Pixel8_API_34 -netspeed edge

The emulator supports network throttling as well as higher connection latencies. You can define it either through the skin configuration or with the ‑netspeed and -netdelay options.

-port port Sets the TCP port number that's used for the console and adb . For example:

emulator @Pixel8_API_34 -port 5556

The default value is 5554 for the first virtual device instance running on the your machine. A virtual device normally occupies a pair of adjacent ports: a console port and an adb port. The console of the first virtual device running on a particular machine uses console port 5554 and adb port 5555. Subsequent instances use port numbers increasing by two. For example, 5556/5557, 5558/5559, and so on. The range is 5554 to 5682, allowing for 64 concurrent virtual devices.

The port assignments are often the same as specifying -ports port ,{ port + 1} . { port + 1} must be free and is reserved for adb . If any of the console or adb ports are already in use, the emulator won't start.

The ‑port option reports which ports and serial number the virtual device is using and warns if there are any issues with the values you provided. In the emulator UI, you can see the console port number in the window title and view the adb port number by selecting Help > About .

Note that if the port value is not even and is in the range 5554 to 5584, the virtual device will start but not be visible when you use the adb devices command, if the adb server starts after the emulator. For this reason, we recommend using an even console port number.

-ports
console-port , adb-port
Sets the TCP ports used for the console and adb . For example:

emulator @Pixel8_API_34 -ports 5556,5559

The valid ports range is 5554 to 5682, allowing for 64 concurrent virtual devices. The -ports option reports which ports and serial number the emulator instance is using and warns if there are any issues with the values you provided.

We recommend using the -port option instead, where possible. The -ports option is available for network configurations that require special settings.

For more information about setting console and adb ports, see the -port option.

-tcpdump filepath Captures network packets and stores them in a file. For example:

emulator @Pixel8_API_34 -tcpdump /path/dumpfile.cap

Use this option to begin capturing all network packets that are sent through the virtual Ethernet LAN of the emulator. Afterward, you can use a tool like Wireshark to analyze the traffic.

Note that this option captures all ethernet packets and isn't limited to TCP connections.

سیستم
-accel mode Configures emulator VM acceleration. For example:

emulator @Pixel8_API_34 -accel auto

Accelerated emulation works for x86 and x86_64 system images only. On Linux, it relies on KVM. On Windows and Mac, it relies on an Intel CPU and Intel HAXM driver. This option is ignored if you're not emulating an x86 or x86_64 device.

Valid values for mode are:

  • auto - Determines automatically if acceleration is supported and uses it when possible (default).
  • off - Disables acceleration entirely, which is primarily useful for debugging.
  • on - Forces acceleration. If KVM or HAXM isn't installed or usable, the emulator won't start and prints an error message.

For more information, see Configure hardware acceleration for the Android Emulator .

-accel-check Checks whether a required hypervisor for emulator VM acceleration is installed (HAXM or KVM). For example:

emulator -accel-check

For more information, see Check if a hypervisor is installed .

-engine engine

Specifies the emulator engine:

  • auto - Automatically selects an engine (default).
  • classic - Uses the older QEMU 1 engine (deprecated).
  • qemu2 - Uses the newer QEMU 2 engine.

برای مثال:

emulator @Pixel8_API_34 -engine auto

Auto-detection should choose the value that provides the best performance when emulating a particular AVD. Use the -engine option for debugging and comparison purposes only.

-gpu mode Selects the GPU emulation mode. For example:

emulator @Pixel8_API_34 -gpu swiftshader_indirect

For more information, see Configure graphics acceleration .

-no-accel Disables emulator VM acceleration when using an x86 or x86_64 system image. It's useful for debugging only and is the same as specifying -accel off . For example:

emulator @Pixel8_API_34 -no-accel

For more information, see Configure hardware acceleration for the Android Emulator .

-nojni
-no-jni
Disables extended Java Native Interface (JNI) checks in the Android Dalvik or ART runtime. For example:

emulator @Pixel8_API_34 -nojni

When you start a virtual device, extended JNI checks are enabled by default. For more information, see JNI tips .

-selinux {disabled|permissive} Sets the Security-Enhanced Linux ( SELinux ) security module to either disabled or permissive mode on a Linux operating system. For example:

me-linux$ emulator @Pixel8_API_34 -selinux permissive

By default, SELinux is in enforcing mode, meaning the security policy is enforced. permissive mode loads the SELinux policy but doesn't enforce it. This option only logs policy violations. disabled mode disables kernel support for SELinux.

-timezone timezone

Sets the time zone for the virtual device to timezone instead of the host time zone. For example:

emulator @Pixel8_API_34 -timezone Europe/Paris

By default, the emulator uses the time zone of your development computer. Use this option to specify a different time zone or if the automatic detection isn't working correctly. The timezone value must be in zoneinfo format, which is area / location or area / subarea / location . For example:

  • America/Los_Angeles
  • Europe/Paris
  • America/Argentina/Buenos_Aires

The specified time zone must be in the zoneinfo database .

-version Displays the emulator version number. For example:

emulator @Pixel8_API_34 -version

یا

emulator -version
رابط کاربری
-no-boot-anim Disables the boot animation during emulator startup for faster booting. For example:

emulator @Pixel8_API_34 -no-boot-anim

On slower computers, this option can significantly speed up the boot sequence.

-screen mode Sets emulated touch screen mode. For example:

emulator @Pixel8_API_34 -screen no-touch

mode can be any of the following values:

  • touch - Emulates a touch screen (default).
  • multi-touch - Emulates a multi-touch screen.
  • no-touch - Disables touch and multi-touch screen emulation.

گزینه‌های پیشرفته

The command-line startup options in the following table are available but not commonly used by the average app developer.

In the descriptions, the working directory is the current directory in the terminal where you're entering commands. For information about the AVD system directory and data directory and the files stored within them, see the section about default directories and files .

Some of these options are appropriate for external app developers, and some of them are used primarily by platform developers. App developers create Android apps and run them on specific AVDs. Platform developers work on the Android system and run it inside the emulator with no pre-created AVD.

Table 4. Advanced command-line options

Advanced option شرح مختصر
-bootchart timeout

Enables bootcharting with a timeout in seconds. Some Android system images have a modified init system that integrates a bootcharting facility. You can pass a bootcharting timeout period to the system with this option. If your init system doesn't have bootcharting activated, the option does nothing. This option is primarily useful to platform developers, not external app developers.

برای مثال:

emulator @Pixel8_API_34 -bootchart 120
-cache filepath

Specifies a cache partition image file. Provides a filename and an absolute path or a path relative to the data directory to set up a persistent cache file. If the file doesn't exist, the emulator creates it as an empty file.

برای مثال:

emulator @Pixel8_API_34 -cache
   ~/.android/avd/Pixel8_API_34.avd/cache_persistent.img

If you don't use this option, the default is a temporary file named cache.img . For more information, see AVD data directory .

-cache-size size

Sets the cache partition size in MBs.

برای مثال:

emulator @Pixel8_API_34 -cache-size 1000

If you don't specify this option, the default is 66 MB. Normally, most app developers don't need this option, unless they need to download very large files that are larger than the default cache. For more information about the cache file, see AVD data directory .

-data filepath

Sets the user data partition image file. Provides a filename and an absolute path or a path relative to the working directory to set up a persistent user data file. If the file doesn't exist, the emulator creates an image from the default userdata.img file, stores it in the filename you specified, and persists user data to it at shutdown.

برای مثال:

emulator @Pixel8_API_34 -data
   ~/.android/avd/Pixel8_API_34.avd/userdata-test.img

If you don't use this option, the default is a file named userdata-qemu.img . For more information about the user data file, see AVD data directory .

-datadir dir

Specifies a data directory using an absolute path. For more information, see AVD data directory .

برای مثال:

emulator @Pixel8_API_34 -datadir
   ~/.android/avd/Pixel8_API_34.avd/mytest
-force-32bit

Uses the 32-bit emulator on 64-bit platforms. Occasionally, this option is useful for testing or debugging. For example, there was an issue where the emulator would sometimes not run on 64-bit Windows, but 32-bit did run. This option was helpful for performing comparisons to debug the issue. Here's an example:

emulator @Pixel8_API_34 -force-32bit
-help-disk-images

Gets help about about disk images. This option provides information relevant to both app and platform developers. For example:

emulator -help-disk-images
-help-char-devices

Gets help about character device specifications. A device parameter is required by some emulator options. For example:

emulator -help-char-devices
-help-sdk-images

Gets help about disk images relevant to app developers. This option gets information about where the image files are located for an AVD created with the SDK tools. For example:

emulator -help-sdk-images
-help-build-images

Gets help about disk images relevant to platform developers. For example:

emulator -help-build-images
-initdata filepath
-init-data filepath

Specifies the initial version of the data partition. After wiping user data, the emulator copies the contents of the specified file to user data (by default, the userdata-qemu.img file) instead of using the default userdata.img file as the initial version. Specifies the filename and an absolute path or a path relative to the working directory.

برای مثال:

emulator @Pixel8_API_34 -initdata
   ~/Library/Android/sdk/system-images/android-34/
   google_apis/x86_64/userdata-test.img

If you don't specify a path, it places the file in the system directory. For more information, see AVD system directory .

-kernel filepath

Uses a specific emulated kernel. If you don't specify a path, the emulator looks in the system directory.

Use the ‑show‑kernel option to view kernel debug messages.

برای مثال:

emulator @Pixel8_API_34 -kernel
   ~/Library/Android/sdk/system-images/android-34/
   google_apis/x86_64/kernel-test.img -show-kernel

If you don't specify this option, the default is kernel-ranchu . For more information, see AVD system directory .

-noaudio
-no-audio

Disables audio support for this virtual device. Some Linux and Windows computers have faulty audio drivers that cause different symptoms, such as preventing the emulator from starting. In this case, use this option to overcome the issue. Alternatively, you can use the QEMU_AUDIO_DRV environment variable to change the audio backend.

برای مثال:

emulator @Pixel8_API_34 -noaudio
-nocache
-no-cache

Starts the emulator without a cache partition. If you don't use this option, the default is a temporary file named cache.img . This option is for platform developers only. For more information, see AVD data directory .

برای مثال:

emulator @Pixel8_API_34 -nocache
-no-snapshot

Inhibits both the automatic load and save operations, causing the emulator to execute a full boot sequence and to lose its state when closed. It overrides the -snapshot option.

برای مثال:

emulator @Pixel8_API_34 -no-snapshot
-no-snapshot-load

Prevents the emulator from loading the AVD state from snapshot storage. Performs a full boot.

برای مثال:

emulator @Pixel8_API_34 -no-snapshot-load
-no-snapshot-save

Prevents the emulator from saving the AVD state to snapshot storage on exit, meaning that all changes will be lost.

برای مثال:

emulator @Pixel8_API_34 -no-snapshot-save
-no-snapshot-update-time

Doesn't try to correct the AVD clock time immediately on snapshot restore. This option can be useful during testing as it avoids a sudden time jump. Time updates are still sent to the AVD about every 15 seconds.

برای مثال:

emulator @Pixel8_API_34 -no-snapshot-update-time
-no-snapstorage

Starts the emulator without mounting a file to store or load state snapshots, forcing a full boot and disabling state snapshot functionality. This option overrides the -snapstorage and -snapshot options.

برای مثال:

emulator @Pixel8_API_34 -no-snapstorage
-no-window

Disables graphical window display on the emulator. This option is useful when running the emulator on servers that have no display. You can access the emulator through adb or the console. For example:

emulator @Pixel8_API_34 -no-window
-partition-size size

Specifies the system data partition size in MBs. For example:

emulator @Pixel8_API_34 -partition-size 1024
-prop name = value

Sets an Android system property in the emulator when it boots. name must be a property name labeled as qemu_prop of at most 32 characters, without any spaces, and value must be a string of at most 92 characters. For an example, see the property_contexts file . You can specify several ‑prop options on one command line. This option can be useful for debugging. For example:

emulator @Pixel8_API_34 -prop qemu.name=value -prop qemu.abc=xyz
-qemu args Passes arguments to the QEMU emulator software. When using this option, make sure it's the last option specified, as all options after it are interpreted as QEMU-specific options. This option is quite advanced and should be used only by developers who are very familiar with QEMU and Android emulation.
-qemu -h

Displays -qemu help. For example:

emulator -qemu -h
-ramdisk filepath

Specifies a ramdisk boot image. Specifies the filename and an absolute path or a path relative to the working directory.

برای مثال:

emulator @Pixel8_API_34 -ramdisk
   ~/Library/Android/sdk/system-images/android-34/
   google_apis/x86_64/ramdisk-test.img

If you don't use this option, the default is the ramdisk.img file in the system directory. For more information, see AVD system directory .

-report-console socket

Reports the console port to a remote third party before starting emulation. It can be useful for an automated testing script. socket must use one of these formats:

  • tcp: port [,server][,max= seconds ][,ipv6]
  • unix: port [,server][,max= seconds ][,ipv6]

For more information, use the -help-report-console option as described in the section about help for specific options .

-shell

Creates a root shell console on the current terminal. This option differs from the adb shell command in the following ways:

  • It creates a root shell that lets you modify many parts of the system.
  • It works even if the adb daemon in the emulated system is broken.
  • Press Control+C (or Command-C, on macOS) to stop the emulator instead of the shell.

برای مثال:

emulator @Pixel8_API_34 -shell
-snapshot name

Specifies the name of a snapshot within a snapshot storage file for automatic start and save operations.

Rather than executing a full boot sequence, the emulator can resume execution from an earlier state snapshot, which is usually significantly faster. When you supply this option, the emulator loads the snapshot of that name from the snapshot image and saves it back under the same name on exit.

If you don't use this option, the default is a full boot sequence. If the specified snapshot doesn't exist, the emulator performs a full boot sequence instead and performs a save operation.

See the -snapstorage option for information on specifying a snapshot storage file and the default file.

emulator @Pixel8_API_34 -snapshot snapshot2

Remember that in the process of loading a snapshot, all contents of the system, user data, and SD card images are overwritten with the contents they held when the snapshot was made. Unless you save this information in a different snapshot, any changes since then are lost.

You can also create a snapshot from the emulator console by using the avd snapshot save name command. For more information, see Send Emulator console commands .

-snapshot-list

Displays a list of available snapshots. This command prints a table of snapshots that are stored in the snapshot storage file that the emulator was started with, then exits. If you specify -snapstorage file as well, this command prints a table of the snapshots stored in file.

برای مثال:

emulator @Pixel8_API_34 -snapshot-list -snapstorage
   ~/.android/avd/Pixel8_API_34.avd/snapshots-test.img

You can use the ID and TAG column values in the output as arguments for the -snapshot option.

-snapstorage filepath

Specifies a repository file that contains all state snapshots. All snapshots made during execution are saved in this file. Only snapshots in this file can be restored during the emulator run.

برای مثال:

emulator @Pixel8_API_34 -snapstorage
   ~/.android/avd/Pixel8_API_34.avd/snapshots-test.img

If you don't specify this option, the default is snapshots.img in the data directory. If the specified file doesn't exist, the emulator will start, but without support for saving or loading state snapshots.

-sysdir dir

Specifies a system directory using an absolute path. For more information, see AVD system directory . For example:

emulator @Pixel8_API_34 -sysdir
   ~/Library/Android/sdk/system-images/android-34/
   google_apis/x86_64/test
-system filepath

Specifies an initial system file. Provides the filename and an absolute path or a path relative to the working directory.

برای مثال:

emulator @Pixel8_API_34 -system
   ~/Library/Android/sdk/system-images/android-34/
   google_apis/x86_64/system-test.img

If you don't use this option, the default is the system.img file in the system directory. For more information, see AVD system directory .

-writable-system

Use this option to have a writable system image during your emulation session. To do so:

  1. Start a virtual device with the -writable-system option.
  2. Enter the adb remount command from a command terminal to tell the emulator to remount system/ as read/write. By default, it's mounted as read-only.

Using this flag creates a temporary copy of the system image that can be very large, up to several hundred MBs, but will be destroyed when the emulator exits.

گزینه‌های منسوخ‌شده

The following command-line options are deprecated:

  • -audio-in
  • -audio-out
  • -charmap
  • -code-profile
  • -cpu-delay
  • -dpi-device
  • -dynamic_skin
  • -enable-kvm
  • -gps
  • -image
  • -keyset
  • -help-keys
  • -help-keyset-file
  • -nand-limits
  • -noskin
  • -no-skin
  • -onion
  • -onion-alpha
  • -onion-rotation
  • -radio
  • -ranchu
  • -raw-keys
  • -scale
  • -shared-net-id
  • -shell-serial
  • -skin
  • -skindir
  • -trace
  • -useaudio

Get help about command-line options

This section describes how to get help about the command-line options. It provides more in-depth information about the commonly used emulator command-line options that are available when you start the emulator.

List all emulator options

To print a list of all emulator options, including a short description, enter the following command:

emulator -help

Get detailed help for a specific option

To print help for a specific startup option, enter the following command:

emulator -help-option

برای مثال:

emulator -help-netspeed

This help is more detailed than the description provided by the -help option.

Get detailed help for all options

To get detailed help for all emulator options, enter the following command:

emulator -help-all

List emulator environment variables

To get a list of emulator environment variables, enter the following command:

emulator -help-environment

You can set environment variables in the terminal window before launching a virtual device, or you can set it through your user settings in the operating system. For example, set it in your .bashrc file on Linux.

List debug tags

To print a list of tags for the -debug options, enter the following command:

emulator -help-debug-tags

The -debug options let you enable or disable debug messages from specific emulator components, as specified by the tags.