Android Debug Bridge (adb)، Android Debug Bridge (adb)

Android Debug Bridge ( adb ) یک ابزار خط فرمان همه کاره است که به شما امکان می دهد با یک دستگاه ارتباط برقرار کنید. دستور adb انواع اعمال دستگاه مانند نصب و اشکال زدایی برنامه ها را تسهیل می کند. adb دسترسی به پوسته یونیکس را فراهم می کند که می توانید از آن برای ا��ر��ی انواع دستورات روی دستگاه استفاده کنید. این یک برنامه مشتری-سرور است که شامل سه جزء است:

  • یک کلاینت که دستورات را ارسال می کند. مشتری روی ماشین توسعه شما اجرا می شود. با صدور دستور adb می توانید یک کلاینت را از ترمینال خط فرمان فراخوانی کنید.
  • یک دیمون (adbd) که دستورات را روی دستگاه اجرا می کند. دیمون به عنوان یک فرآیند پس زمینه در هر دستگاه اجرا می شود.
  • سروری که ارتباط بین کلاینت و دیمون را مدیریت می کند. سرور به عنوان یک فرآیند پس زمینه در ماشین توسعه شما اجرا می شود.

adb در بسته Android SDK Platform Tools گنجانده شده است. این بسته را با مدیر SDK دانلود کنید، که آن را در android_sdk /platform-tools/ نصب می‌کند. اگر بسته مستقل Android SDK Platform Tools را می‌خواهید، آن را از اینجا دانلود کنید .

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

adb چگونه کار می کند

هنگامی که یک کلاینت adb راه اندازی می کنید، مشتری ابتدا بررسی می کند که آیا یک فرآیند سرور adb قبلاً در حال اجرا است یا خیر. اگر وجود نداشته باشد، فرآیند سرور را شروع می کند. هنگامی که سرور راه اندازی می شود، به پورت TCP محلی 5037 متصل می شود و به دستورات ارسال شده از مشتریان adb گوش می دهد.

توجه: همه کلاینت های adb برای ارتباط با سرور adb از پورت 5037 استفاده می کنند.

سپس سرور اتصالات را به تمام دستگاه های در حال اجرا تنظیم می کند. شبیه سازها را با اسکن پورت های فرد در محدوده 5555 تا 5585، که محدوده ای است که توسط 16 شبیه ساز اول استفاده می شود، مکان یابی می کند. در جایی که سرور یک دیمون adb (adbd) پیدا می کند، یک اتصال به آن پورت برقرار می کند.

هر شبیه ساز از یک جفت پورت متوالی استفاده می کند - یک پورت با شماره زوج برای اتصالات کنسول و یک پورت با شماره فرد برای اتصالات adb . به عنوان مثال:

شبیه ساز 1، کنسول: 5554
شبیه ساز 1، adb : 5555
شبیه ساز 2، کنسول: 5556
شبیه ساز 2، adb : 5557
و غیره

همانطور که نشان داده شده است، شبیه ساز متصل به adb در پورت 5555 مشابه شبیه سازی است که کنسول آن در پورت 5554 گوش می دهد.

هنگامی که سرور اتصالات را به همه دستگاه ها تنظیم کرد، می توانید از دستورات adb برای دسترسی به آن دستگاه ها استفاده کنید. از آنجایی که سرور اتصالات به دستگاه ها را مدیریت می کند و دستورات چندین کلاینت adb را مدیریت می کند، می توانید هر دستگاهی را از هر کلاینت یا از یک اسکریپت کنترل کنید.

اشکال زدایی adb را در دستگاه خود فعال کنید

برای استفاده از adb با دستگاهی که از طریق USB متصل است، باید اشکال زدایی USB را در تنظیمات سیستم دستگاه، در قسمت گزینه های برنامه نویس فعال کنید. در اندروید 4.2 (سطح API 17) و بالاتر، صفحه Developer options به طور پیش فرض پنهان است. برای قابل مشاهده کردن، گزینه های برنامه نویس را فعال کنید.

اکنون می توانید دستگاه خود را با USB وصل کنید. می‌توانید با اجرای adb devices از پوشه android_sdk /platform-tools/ تأیید کنید که دستگاه شما متصل است. در صورت اتصال، نام دستگاه را می‌بینید که به���عنوان «دستگاه» فهرست شده است.

توجه: هنگامی که دستگاهی را که دارای Android نسخه 4.2.2 (سطح API 17) یا بالاتر است وصل می‌کنید، سیستم گفتگویی را نشان می‌دهد که از شما می‌پرسد آیا کلید RSA را می‌پذیرد که امکان اشکال‌زدایی را از طریق این رایانه فراهم می‌کند یا خیر. این مکانیسم امنیتی از دستگاه های کاربر محافظت می کند زیرا تضمین می کند که اشکال زدایی USB و سایر دستورات adb نمی توانند اجرا شوند مگر اینکه بتوانید قفل دستگاه را باز کنید و گفتگو را تأیید کنید.

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

از طریق Wi-Fi به دستگاه متصل شوید

توجه: دستورالعمل‌های زیر برای دستگاه‌های Wear دارای Android 11 (سطح API 30) اعمال نمی‌شود. برای اطلاعات بیشتر به راهنمای اشکال زدایی برنامه Wear OS مراجعه کنید.

Android 11 (سطح API 30) و بالاتر از استقرار و اشکال زدایی برنامه شما به صورت بی سیم از ایستگاه کاری خود با استفاده از Android Debug Bridge (adb) پشتیبانی می کند. به عنوان مثال، می توانید برنامه قابل اشکال زدایی خود را در چندین دستگاه راه دور بدون نیاز به اتصال فیزیکی دستگاه خود از طریق USB، مستقر کنید. این امر نیاز به پرداختن به مشکلات رایج اتصال USB، مانند نصب درایور را از بین می برد.

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

  • مطمئن شوید که ایستگاه کاری و دستگاه شما به یک شبکه بی سیم متصل هستند.

  • مطمئن شوید که دستگاه شما دارای Android 11 (سطح API 30) یا بالاتر برای تلفن یا Android 13 (سطح API 33) یا بالاتر برای تلویزیون و WearOS است. برای اطلاعات بیشتر، نسخه Android خود را بررسی و به‌روزرسانی کنید.

  • اگر از IDE استفاده می کنید، مطمئن شوید که آخرین نسخه اندروید استودیو را نصب کرده اید. می توانید آن را از اینجا دانلود کنید.

  • در ایستگاه کاری خود، به آخرین نسخه SDK Platform Tools را به‌روزرسانی کنید.

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

  1. گزینه های توسعه دهنده را در دستگاه خود فعال کنید .

  2. اندروید استودیو را باز کنید و از منوی تنظیمات اجرا شده ، گزینه Pair Devices Using Wi-Fi را انتخاب کنید.

    منوی کشویی تنظیمات را اجرا کنید
    شکل 1. منوی تنظیمات را اجرا کنید.

    همانطور که در شکل 2 نشان داده شده است، پنجره جفت کردن دستگاه ها از طریق Wi-Fi ظاهر می شود.

    تصویر صفحه‌نمایش جفت دستگاه‌ها از طریق پنجره بازشو Wi-Fi
    شکل 2. پنجره بازشو برای جفت کردن دستگاه ها با استفاده از کد QR یا کد جفت.
  3. در دستگاه خود، روی Wireless debugging ضربه بزنید و دستگاه خود را جفت کنید:

    عکس صفحه‌نمایش تلفن پیکسلی که تنظیمات سیستم‌های اشکال‌زدایی بی‌سیم را نشان می‌دهد.
    شکل 3. تصویری از تنظیمات اشکال زدایی بی سیم در تلفن Google Pixel.
    1. برای جفت کردن دستگاه خود با یک کد QR، جفت کردن دستگاه با کد QR را انتخاب کنید و کد QR به دست آمده از دستگاه های جفت از طریق Wi-Fi را که در شکل 2 نشان داده شده است اسکن کنید.

    2. برای جفت کردن دستگاه خود با کد جفت‌سازی، از پنجره بازشو جفت کردن دستگاه‌ها از طریق Wi-Fi، جفت کردن دستگاه با کد جفت‌سازی را انتخاب کنید. در دستگاه خود، جفت کردن با استفاده از کد جفت سازی را انتخاب کنید و کد شش رقمی ارائه شده را یادداشت کنید. هنگامی که دستگاه شما در پنجره جفت کردن دستگاه ها از طریق Wi-Fi ظاهر شد، می توانید جفت شدن را انتخاب کنید و کد شش رقمی نشان داده شده در دستگاه خود را وارد کنید.

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

    برای جفت کردن دستگاه دیگری یا فراموش کردن دستگاه فعلی در ایستگاه کاری خود، به «اشکال‌زدایی بی‌سیم» در دستگاه خود بروید. روی نام ایستگاه کاری خود در قسمت Paired devices ضربه بزنید و Forget را انتخاب کنید.

  5. اگر می‌خواهید به سرعت اشکال‌زدایی بی‌سیم را روشن و خاموش کنید، می‌توانید از کاشی‌های برنامه‌نویس تنظیمات سریع برای اشکال‌زدایی بی‌سیم استفاده کنید، که در گزینه‌های برنامه‌نویس > کاشی‌های توسعه تنظیمات سریع یافت می‌شود.

    نماگرفت کاشی‌های برنامه‌نویس تنظیمات سریع از تلفن Google Pixel.
    شکل 5. تنظیمات Quick Setting developer tiles به شما امکان می دهد به سرعت اشکال زدایی بی سیم را روشن و خاموش کنید.

اتصال Wi-Fi با استفاده از خط فرمان

از طرف دیگر، برای اتصال به دستگاه خود با استفاده از خط فرمان بدون Android Studio، این مراحل را دنبال کنید:

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

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

  3. در ایستگاه کاری خود، یک پنجره ترمینال را باز کنید و به android_sdk/platform-tools بروید.

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

  5. در ترمینال ایستگاه کاری خود، adb pair ipaddr:port اجرا کنید. از آدرس IP و شماره پورت بالا استفاده کنید.

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

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

مشکلات اتصال بی سیم را حل کنید

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

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

بررسی کنید که ایستگاه کاری و دستگاه دارای پیش نیازهای ذکر شده در ابتدای این بخش باشند.

سایر مسائل شناخته شده را بررسی کنید

در زیر لیستی از مشکلات شناخته شده فعلی در مورد اشکال زدایی بی سیم (با adb یا Android Studio) و نحوه حل آنها آمده است:

  • Wi-Fi متصل نمی شود : شبکه های Wi-Fi ایمن، مانند شبکه های Wi-Fi شرکتی، ممکن است اتصالات p2p را مسدود کنند و به شما اجازه اتصال از طریق Wi-Fi را ندهند. سعی کنید با کابل یا شبکه Wi-Fi دیگر (غیر شرکتی) وصل شوید. اتصال بی‌سیم با استفاده از adb connect ip : port روی tcp/ip (به دنبال اتصال USB اولیه) گزینه دیگری است، در صورتی که توسل به یک شبکه غیر شرکتی یک گزینه باشد.

  • adb از طریق Wi-Fi گاهی اوقات به طور خودکار خاموش می شود : اگر دستگاه شبکه های Wi-Fi را تغییر دهد یا از شبکه جدا شود، این اتفاق می افتد. برای حل، دوباره به شبکه متصل شوید.

  • دستگاه پس از جفت شدن با موفقیت وصل نمی شود : adb برای کشف و اتصال خودکار به دستگاه های جفت شده به mDNS متکی است. اگر پیکربندی شبکه یا دستگاه شما از mDNS پشتیبان�� نمی‌کند یا آن را غیرفعال کرده است، باید با استفاده از adb connect ip : port به صورت دستی به دستگاه متصل شوید.

پس از اتصال USB اولیه به صورت بی سیم با دستگاهی متصل شوید (فقط گزینه موجود در Android 10 و پایین تر)

توجه: این گردش کار برای اندروید 11 (و بالاتر) نیز قابل اجرا است، نکته مهم این است که شامل یک اتصال *اولیه* از طریق USB فیزیکی نیز می شود.

توجه: دستورالعمل‌های زیر برای دستگاه‌های Wear دارای Android 10 (سطح API 29) یا پایین‌تر اعمال نمی‌شود. برای اطلاعات بیشتر به راهنمای اشکال زدایی برنامه Wear OS مراجعه کنید.

adb معمولا از طریق USB با دستگاه ارتباط برقرار می کند، اما می توانید از adb از طریق Wi-Fi نیز استفاده کنید. برای اتصال دستگاهی که دارای Android 10 (سطح API 29) یا پایین‌تر است، این مراحل اولیه را از طریق USB دنبال کنید:

  1. دستگاه Android و رایانه میزبان adb خود را به یک شبکه Wi-Fi مشترک وصل کنید.
  2. توجه: مراقب باشید که همه نقاط دسترسی مناسب نیستند. ممکن است لازم باشد از یک نقطه دسترسی استفاده کنید که فایروال آن برای پشتیبانی از adb به درستی پیکربندی شده است.

  3. دستگاه را با کابل USB به کامپیوتر میزبان وصل کنید.
  4. دستگاه مورد نظر را برای گوش دادن به اتصال TCP/IP در پورت 5555 تنظیم کنید:
    adb tcpip 5555
    
  5. کابل USB را از دستگاه مورد نظر جدا کنید.
  6. آدرس IP دستگاه Android را پیدا کنید. برای مثال، در یک دستگاه Nexus، می‌توانید آدرس IP را در تنظیمات > درباره رایانه لوحی (یا درباره تلفن ) > وضعیت > آدرس IP پیدا کنید.
  7. با آدرس IP آن به دستگاه متصل شوید:
    adb connect device_ip_address:5555
    
  8. تأیید کنید که رایانه میزبان شما به دستگاه مورد نظر متصل است:
    $ adb devices
    List of devices attached
    device_ip_address:5555 device
    

دستگاه شما اکنون به adb متصل است.

اگر اتصال adb به دستگاه شما قطع شد:

  • مطمئن شوید که هاست شما همچنان به همان شبکه Wi-Fi دستگاه Android شما متصل است.
  • با اجرای مجدد مرحله adb connect دوباره وصل شوید.
  • اگر کار نکرد، میزبان adb خود را بازنشانی کنید:
    adb kill-server
    

    سپس از اول شروع کنید.

پرس و جو برای دستگاه ها

قبل از صدور دستورات adb ، دانستن اینکه چه دستگاه هایی به سرور adb متصل هستند مفید است. لیستی از دستگاه های متصل را با استفاده از دستور devices ایجاد کنید:

  adb devices -l
  

در پاسخ، adb این اطلاعات وضعیت را برای هر دستگاه چاپ می کند:

  • شماره سریال: adb رشته ای ایجاد می کند تا دستگاه را با شماره پورت آن به طور منحصر به فرد شناسایی کند. در اینجا یک مثال شماره سریال آمده است: emulator-5554
  • وضعیت: وضعیت اتصال دستگاه می تواند یکی از موارد زیر باشد:
    • offline : دستگاه به adb متصل نیست یا پاسخ نمی دهد.
    • device : دستگاه به سرور adb متصل است. توجه داشته باشید که این حالت به این معنی نیست که سیستم اندروید به طور کامل بوت شده و عملیاتی شده است، زیرا دستگاه در حالی که سیستم هنوز در حال بوت شدن است به adb متصل می شود. پس از راه‌اندازی، این وضعیت عملکرد عادی یک دستگاه است.
    • no device : هیچ دستگاهی متصل نیست.
  • توضیحات: اگر گزینه -l وارد کنید، دستور devices به شما می گوید که دستگاه چیست. این اطلاعات زمانی مفید است که چندین دستگاه متصل شده باشید تا بتوانید آنها را از هم جدا کنید.

مثال زیر فرمان devices و خروجی آن را نشان می دهد. سه دستگاه در حال اجرا هستند. دو خط اول در لیست شبیه ساز هستند و خط سوم یک دستگاه سخت افزاری است که به رایانه متصل است.

$ adb devices
List of devices attached
emulator-5556 device product:sdk_google_phone_x86_64 model:Android_SDK_built_for_x86_64 device:generic_x86_64
emulator-5554 device product:sdk_google_phone_x86 model:Android_SDK_built_for_x86 device:generic_x86
0a388e93      device usb:1-1 product:razor model:Nexus_7 device:flo

شبیه ساز لیست نشده است

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

  • سرور adb در حال اجرا نیست.
  • شما از دستور emulator با گزینه -port یا -ports با مقدار پورت فرد بین 5554 و 5584 استفاده می کنید.
  • پورت فرد با شماره انتخابی شما اشغال نیست، بنابراین اتصال پورت را می توان با شماره پورت مشخص شده برقرار کرد - یا اگر مشغول باشد، شبیه ساز به پورت دیگری سوئیچ می کند که الزامات 2 را برآورده می کند.
  • سرور adb را بعد از راه اندازی شبیه ساز راه اندازی می کنید.

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

مثال 1: در دنباله دستور زیر، دستور adb devices سرور adb را راه اندازی می کند، اما لیست دستگاه ها ظاهر نمی شود.

سرور adb را متوقف کنید و دستورات زیر را به ترتیب نشان داده شده وارد کنید. برای نام AVD، یک نام AVD معتبر از سیستم خود ارائه دهید. برای دریافت لیستی از نام های AVD، emulator -list-avds را تایپ کنید. دستور emulator در دایرکتوری android_sdk /tools قرار دارد.

$ adb kill-server
$ emulator -avd Nexus_6_API_25 -port 5555
$ adb devices

List of devices attached
* daemon not running. starting it now on port 5037 *
* daemon started successfully *

مثال 2: در دستور زیر، adb devices لیستی از دستگاه‌ها را نشان می‌دهند زیرا ابتدا سرور adb راه‌اندازی شده است.

برای مشاهده شبیه ساز در خروجی adb devices ، سرور adb را متوقف کرده و پس از استفاده از دستور emulator و قبل از استفاده از دستور adb devices ، دوباره آن را راه اندازی کنید.

$ adb kill-server
$ emulator -avd Nexus_6_API_25 -port 5557
$ adb start-server
$ adb devices

List of devices attached
emulator-5557 device

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

دستورات را به یک دستگاه خاص ارسال کنید

اگر چندین دستگاه در حال اجرا هستند، هنگام صدور دستور adb باید دستگاه مورد نظر را مش��ص کنید. برای تعیین هدف، مراحل زیر را دنبال کنید:

  1. برای بدست آوردن شماره سریال هدف از دستور devices استفاده کنید.
  2. پس از بدست آوردن شماره سریال، از گزینه -s با دستورات adb برای تعیین شماره سریال استفاده کنید.
    1. اگر می‌خواهید دستورات adb زیادی صادر کنید، می‌توانید متغیر محیطی $ANDROID_SERIAL را طوری تنظیم کنید که شامل شماره سریال باشد.
    2. اگر از -s و $ANDROID_SERIAL استفاده می‌کنید، -s $ANDROID_SERIAL را لغو می‌کند.

در مثال زیر، لیست دستگاه های متصل به دست می آید و سپس از شماره سریال یکی از دستگاه ها برای نصب helloWorld.apk بر روی آن دستگاه استفاده می شود:

$ adb devices
List of devices attached
emulator-5554 device
emulator-5555 device
0.0.0.0:6520  device

# To install on emulator-5555
$ adb -s emulator-5555 install helloWorld.apk
# To install on 0.0.0.0:6520
$ adb -s 0.0.0.0:6520 install helloWorld.apk

توجه: ا��ر فرمانی را بدون تعیین دستگاه مورد نظر در زمانی که چندین دستگاه در دسترس هستند صادر کنید، adb خطای «adb: بیش از یک دستگاه/شبیه‌ساز» را نمایش می‌دهد.

اگر چندین دستگاه در دسترس دارید اما تنها یکی شبیه ساز است، از گزینه -e برای ارسال دستورات به شبیه ساز استفاده کنید. اگر چندین دستگاه وجود دارد اما فقط یک دستگاه سخت افزاری متصل است، از گزینه -d برای ارسال دستورات به دستگاه سخت افزاری استفاده کنید.

یک برنامه نصب کنید

می‌توانید adb برای نصب یک APK روی شبیه‌ساز یا دستگاه متصل با دستور install استفاده کنید:

adb install path_to_apk

هنگام نصب یک APK آزمایشی باید از گزینه -t با دستور install استفاده کنید. برای اطلاعات بیشتر، -t ببینید.

برای نصب چندین APK از install-multiple استفاده کنید. اگر همه فایل‌های APK را برای یک دستگاه خاص برای برنامه خود از کنسول Play دانلود کنید و بخواهید آنها را روی یک شبیه‌ساز یا دستگاه فیزیکی نصب کنید، مفید است.

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

توجه: اگر از اندروید استودیو استفاده می کنید، نیازی به استفاده مستقیم از adb برای نصب برنامه خود بر روی شبیه ساز یا دستگاه ندارید. در عوض، Android Studio بسته بندی و نصب برنامه را برای شما انجام می دهد.

راه اندازی پورت فوروارد

از دستور forward برای راه‌اندازی ارسال پورت دلخواه استفاده کنید، که درخواست‌های یک پورت میزبان خاص را به پورت دیگری در دستگاه ارسال می‌کند. مثال زیر ارسال پورت میزبان 6100 به پورت دستگاه 7100 را تنظیم می کند:

adb forward tcp:6100 tcp:7100

مثال زیر ارسال پورت میزبان 6100 را به local:logd تنظیم می کند:

adb forward tcp:6100 local:logd

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

فایل‌ها را به و از دستگاه کپی کنید

از دستورات pull و push برای کپی کردن فایل ها به و از دستگاه استفاده کنید. بر خلاف دستور install که فقط یک فایل APK را در یک مکان خاص کپی می کند، دستورات pull و push به شما امکان می دهد فهرست ها و فایل های دلخواه را در هر مکانی در دستگاه کپی کنید.

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

adb pull remote local

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

adb push local remote

مسیرهای دسترسی به فایل‌ها/دایرکتوری هدف را در دستگاه توسعه خود (محلی) و روی دستگاه (ریموت) جایگزین local و remote کنید. به عنوان مثال:

adb push myfile.txt /sdcard/myfile.txt

سرور adb را متوقف کنید

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

برای متوقف کردن سرور adb ، از دستور adb kill-server استفاده کنید. سپس می توانید با صدور هر دستور adb دیگری سرور را راه اندازی مجدد کنید.

دستورات adb را صادر کنید

دستورات adb را از یک خط فرمان در ماشین توسعه خود یا از یک اسکریپت با استفاده از موارد زیر صادر کنید:

adb [-d | -e | -s serial_number] command

اگر فقط یک شبیه ساز در حال اجرا باشد یا فقط یک دستگاه متصل باشد، دستور adb به طور پیش فرض به آن دستگاه ارسال می شود. اگر چندین شبیه‌ساز در حال اجرا هستند و/یا چندین دستگاه متصل هستند، باید از گزینه -d ، -e ، یا -s استفاده کنید تا دستگاه هدفی را که دستور باید به آن هدایت شود، مشخص کنید.

با استفاده از دستور زیر می توانید لیستی دقیق از تمام دستورات adb پشتیبانی شده را مشاهده کنید:

adb --help

دستورات پوسته را صادر کنید

می توانید از دستور shell برای صدور دستورات دستگاه از طریق adb یا برای راه اندازی یک پوسته تعاملی استفاده کنید. برای صدور یک فرمان واحد، از دستور shell به صورت زیر استفاده کنید:

adb [-d |-e | -s serial_number] shell shell_command

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

adb [-d | -e | -s serial_number] shell

برای خروج از پوسته تعاملی، Control+D را فشار دهید یا exit را تایپ کنید.

اندروید اکثر ابزارهای معمول خط فرمان یونیکس را ارائه می دهد. برای لیستی از ابزارهای موجود، از دستور زیر استفاده کنید:

adb shell ls /system/bin

راهنما برای اکثر دستورات از طریق آرگومان --help در دسترس است. بسیاری از دستورات پوسته توسط جعبه اسباب بازی ارائه می شود. راهنمای عمومی قابل اجرا برای همه دستورات جعبه اسباب بازی از طریق toybox --help در دسترس است.

با Android Platform Tools 23 و بالاتر، adb آرگومان ها را به همان روشی که دستور ssh(1) انجام می دهد، مدیریت می کند. این تغییر بسیاری از مشکلات مربوط به تزریق دستور را برطرف کرده است و امکان اجرای ایمن دستوراتی را که حاوی متاکاراکترهای پوسته هستند، مانند adb install Let\'sGo.apk را ممکن می سازد. این تغییر به این معنی است که تفسیر هر دستوری که حاوی متاکاراکترهای پوسته باشد نیز تغییر کرده است.

به عنوان مثال، adb shell setprop key ' two words ' اکنون یک خطا است، زیرا نقل قول ها توسط پوسته محلی بلعیده می شوند و دستگاه adb shell setprop key two words را می بیند. برای اینکه دستور کار کند، دو بار نقل قول کنید، یک بار برای پوسته محلی و یک بار برای پوسته راه دور، همانطور که با ssh(1) انجام می دهید. برای مثال، adb shell setprop key "' two words '" کار می کند زیرا پوسته محلی سطح بیرونی نقل قول را می گیرد و دستگاه همچنان سطح داخلی نقل قول را می بیند: setprop key 'two words' . فرار نیز یک گزینه است، اما دو بار نقل قول معمولا آسان تر است.

ابزار خط فرمان Logcat را نیز ببینید که برای نظارت بر گزارش سیستم مفید است.

با مدیر فعالیت تماس بگیرید

در یک پوسته adb ، می‌توانید با ابزار Activity manager ( am ) دستوراتی را برای انجام اقدامات مختلف سیستم مانند شروع یک فعالیت، توقف اجباری یک فرآیند، پخش یک هدف، اصلاح ویژگی‌های صفحه نمایش دستگاه و موار�� دیگر صادر کنید.

در حالی که در یک پوسته، دستور am به صورت زیر است:

am command

همچنین می‌توانید دستور مدیریت فعالیت را مستقیماً از adb بدون وارد کردن پوسته راه دور صادر کنید. به عنوان مثال:

adb shell am start -a android.intent.action.VIEW

جدول 1. دستورات مدیر فعالیت موجود

فرمان توضیحات
start [ options ] intent یک Activity مشخص شده توسط intent را شروع کنید.

برای آرگومان های قصد، مشخصات را ببینید.

گزینه ها عبارتند از:

  • -D : اشکال زدایی را فعال کنید.
  • -W : منتظر بمانید تا راه اندازی کامل شود.
  • --start-profiler file : نمایه ساز را شروع کرده و نتایج را به file ارسال کنید.
  • -P file : مانند --start-profiler است، اما وقتی برنامه بیکار می شود، نمایه سازی متوقف می شود.
  • -R count : count دفعات راه اندازی فعالیت را تکرار کنید. قبل از هر تکرار، فعالیت برتر به پایان می رسد.
  • -S : قبل از شروع فعالیت، برنامه هدف را اجباری متوقف کنید.
  • --opengl-trace : ردیابی توابع OpenGL را فعال کنید.
  • --user user_id | current : مشخص کنید که کدام کاربر به عنوان اجرا شود. اگر مشخص نشده است، به عنوان کاربر فعلی اجرا کنید.
startservice [ options ] intent Service مشخص شده توسط intent را شروع کنید.

برای آرگومان های قصد، مشخصات را ببینید.

گزینه ها عبارتند از:

  • --user user_id | current : مشخص کنید که به عنوان کدام کاربر اجرا شود. اگر مشخص نشده است، به عنوان کاربر فعلی اجرا کنید.
force-stop package تمام موارد مرتبط با package اجباری متوقف کنید.
kill [ options ] package تمام فرآیندهای مرتبط با package را از بین ببرید. این دستور فقط فرآیندهایی را می‌کشد که از بین بردن آنها بی‌خطر بوده و بر تجربه کاربر تأثیری نخواهد داشت.

گزینه ها عبارتند از:

  • --user user_id | all | current : مشخص کنید که کدام فرآیند کاربر را بکشد. اگر مشخص نیست، تمام فرآیندهای کاربران را بکشید.
kill-all تمام فرآیندهای پس زمینه را بکشید.
broadcast [ options ] intent یک قصد پخش صادر کنید.

برای آرگومان های قصد، مشخصات را ببینید.

گزینه ها عبارتند از:

  • [--user user_id | all | current] : مشخص کنید که به کدام کاربر ارسال شود. اگر مشخص نیست، برای همه کاربران ارسال کنید.
instrument [ options ] component نظارت را با یک نمونه Instrumentation شروع کنید. معمولاً component هدف فرم test_package / runner_class است.

گزینه ها عبارتند از:

  • -r : نتایج خام را چاپ کنید (در غیر این صورت report_key_streamresult را رمزگشایی کنید). از [-e perf true] برای تولید خروجی خام برای اندازه‌گیری عملکرد استفاده کنید.
  • -e name value : name آرگومان را روی value قرار دهید. برای دونده های آزمایشی، یک فرم رایج -e testrunner_flag value [, value ...] است.
  • -p file : داده های پروفایل را در file بنویسید.
  • -w : قبل از بازگشت منتظر بمانید تا ابزار دقیق تمام شود. برای دوندگان آزمون مورد نیاز است.
  • --no-window-animation : انیمیشن های پنجره را هنگام اجرا خاموش کنید.
  • --user user_id | current : تعیین کنید که ابزار دقیق کاربر در کدام دستگاه اجرا شود. اگر مشخص نیست، در کاربر فعلی اجرا شود.
profile start process file نمایه ساز را در process شروع کنید، نتایج را در file بنویسید.
profile stop process پروفیلر process متوقف کنید.
dumpheap [ options ] process file انباشته از process ، نوشتن در file .

گزینه ها عبارتند از:

  • --user [ user_id | current] : هنگام ارائه یک نام فرآیند، کاربر فرآیند مورد نظر را مشخص کنید. اگر مشخص نشده باشد، کاربر فعلی استفاده می شود.
  • -b [| png | jpg | webp] : نقشه های بیت را از حافظه گرافیکی (سطح API 35 و بالاتر) حذف کنید. به صورت اختیاری فرمت مورد نظر را برای ریختن (به طور پیش فرض PNG) مشخص کنید.
  • -n : به جای پشته مدیریت شده، توده بومی را تخلیه کنید.
set-debug-app [ options ] package package برنامه را روی اشکال زدایی تنظیم کنید.

گزینه ها عبارتند از:

  • -w : زمانی که برنامه شروع به کار کرد، منتظر دیباگر باشید.
  • --persistent : این مقدار را حفظ کنید.
clear-debug-app بسته مجموعه قبلی را برای رفع اشکال با set-debug-app پاک کنید.
monitor [ options ] نظارت را برای خرابی یا ANR شروع کنید.

گزینه ها عبارتند از:

  • --gdb : gdbserv در پورت داده شده در crash/ANR شروع کنید.
screen-compat {on | off} package حالت سازگاری صفحه package را کنترل کنید.
display-size [reset | width x height ] نادیده گرفتن اندازه نمایش دستگاه. این دستور برای آزمایش برنامه شما در اندازه های مختلف صفحه با تقلید وضوح صفحه نمایش کوچک با استفاده از دستگاهی با صفحه نمایش بزرگ مفید است و بالعکس.

مثال:
am display-size 1280x800

display-density dpi نادیده گرفتن تراکم نمایش دستگاه این دستور برای آزمایش برنامه شما در تراکم ��ای مختلف صفحه با تقلید از م��یط صفحه نمایش با چ��الی ��الا با استفاده از صفحه نمایش کم تراکم مفید است و بالعکس.

مثال:
am display-density 480

to-uri intent مشخصات intent داده شده را به عنوان URI چاپ کنید.

برای آرگومان های قصد، مشخصات را ببینید.

to-intent-uri intent مشخصات intent داده شده را به عنوان یک intent: URI.

برای آرگومان های قصد، مشخصات را ببینید.

مشخصات برای استدلال های قصد

برای دستورات اکتیویتی منیجر که آرگومان intent می گیرند، می توانید intent را با گزینه های زیر مشخص کنید:

تماس با مدیر بسته ( pm )

در یک پوسته adb ، می‌توانید با ابزار مدیریت بسته ( pm ) دستوراتی را برای انجام اقدامات و پرس و جوها در بسته‌های برنامه نصب شده در دستگاه صادر کنید.

در حالی که در یک پوسته، نحو pm به صورت زیر است:

pm command

همچنین می توانید دستور مدیریت بسته را مستقیماً از adb بدون وارد کردن پوسته راه دور صادر کنید. به عنوان مثال:

adb shell pm uninstall com.example.MyApp

جدول 2. دستورات مدیریت بسته موجود

فرمان توضیحات
list packages [ options ] filter چاپ همه بسته ها، به صورت اختیاری فقط بسته هایی که نام بسته حاوی متن در filter است.

گزینه ها:

  • -f : فایل مرتبط را ببینید.
  • -d : فیلتر کنید تا فقط بسته‌های غیرفعال را نشان دهد.
  • -e : فیلتر کنید تا فقط بسته های فعال را نشان دهد.
  • -s : فیلتر کنید تا فقط بسته های سیستم را نشان دهد.
  • -3 : فیلتر کنید تا فقط بسته های شخص ثالث نمایش داده شود.
  • -i : برای بسته ها به نصب کننده مراجعه کنید.
  • -u : شامل بسته های نصب نشده است.
  • --user user_id : فضای کاربر برای پرس و جو.
list permission-groups چاپ همه گروه های مجوز شناخته شده.
list permissions [ options ] group چاپ تمام مجوزهای شناخته شده، به صورت اختیاری فقط مجوزهای موجود در group .

گزینه ها:

  • -g : سازماندهی بر اساس گروه.
  • -f : تمام اطلاعات را چاپ کنید.
  • -s : خلاصه کوتاه.
  • -d : فقط مجوزهای خطرناک را فهرست کنید.
  • -u : فقط مجوزهایی را که کاربران می بینند فهرست کنید.
list instrumentation [ options ] لیست تمام بسته های آزمایشی

گزینه ها:

  • -f : فایل APK را برای بسته آزمایشی فهرست کنید.
  • target_package : بسته های آزمایشی را فقط برای این برنامه فهرست کنید.
list features تمام ویژگی های سیستم را چاپ کنید.
list libraries تمام کتابخانه های پشتیبانی شده توسط دستگاه فعلی را چاپ کنید.
list users همه کاربران روی سیستم را چاپ کنید.
path package مسیر APK package داده شده را چاپ کنید.
install [ options ] path بسته ای را که توسط path مشخص شده در سیستم نصب کنید.

گزینه ها:

  • -r : یک برنامه موجود را مجدداً نصب کنید و اطلاعات آن را حفظ کنید.
  • -t : اجازه نصب APKهای آزمایشی را می دهد. Gradle زمانی یک APK آزمایشی تولید می‌کند که فقط برنامه خود را اجرا یا اشکال زدایی کرده باشید یا از دستور Android Studio Build > Build APK استفاده کرده باشید. اگر APK با استفاده از یک SDK پیش‌نمایش توسعه‌دهنده ساخته شده است، اگر در حال نصب یک APK آزمایشی هستید، باید گزینه -t را با دستور install اضافه کنید.
  • -i installer_package_name : نام بسته نصب کننده را مشخص کنید.
  • --install-location location : مکان نصب را با استفاده از یکی از مقادیر زیر تنظیم کنید:
    • 0 : از محل نصب پیش فرض استفاده کنید.
    • 1 : روی حافظه داخلی دستگاه نصب کنید.
    • 2 : روی رسانه خارجی نصب کنید.
  • -f : بسته را روی حافظه داخلی سیستم نصب کنید.
  • -d : اجازه کاهش کد نسخه را می دهد.
  • -g : همه مجوزهای فهرست شده در مانیفست برنامه را اعطا کنید.
  • --fastdeploy : به سرعت یک بسته نصب شده را فقط با به روز رسانی بخش هایی از APK که تغییر کرده ��ند به ��وز کنید.
  • --incremental : به اندازه کافی APK را نصب می کند تا برنامه را راه اندازی کند در حالی که داده های باقی مانده را در پس زمینه پخش می کند. برای استفاده از این ویژگی، باید APK را امضا کنید، یک فایل APK Signature Scheme v4 ایجاد کنید، و این فایل را در همان فهرست APK قرار دهید. این ویژگی فقط در دستگاه های خاصی پشتیبانی می شود. این گزینه adb مجبور می‌کند تا از این ویژگی استفاده کند یا اگر پشتیبانی نمی‌شود، با اطلاعات دقیق درباره علت شکست آن، شکست می‌خورد. گزینه --wait را اضافه کنید تا قبل از دادن دسترسی به APK منتظر بمانید تا APK به طور کامل نصب شود.

    --no-incremental مانع از استفاده adb از این ویژگی می شود.

uninstall [ options ] package بسته ای را از سیستم حذف می کند.

گزینه ها:

  • -k : پس از حذف بسته، دایرکتوری های داده و کش را نگه دارید.
  • --user user_id : کاربری را مشخص می کند که بسته برای او حذف شده است.
  • --versionCode version_code : فقط در صورتی حذف نصب می شود که برنامه کد نسخه داده شده را داشته باشد.
clear package تمام داده های مرتبط با یک بسته را حذف کنید.
enable package_or_component بسته یا جزء داده شده را فعال کنید (نوشته شده به عنوان "package/class").
disable package_or_component بسته یا جزء داده شده را غیرفعال کنید (نوشته شده به عنوان "package/class").
disable-user [ options ] package_or_component

گزینه ها:

  • --user user_id : کاربری که باید غیرفعال شود.
grant package_name permission به یک برنامه مجوز بدهید. در دستگاه‌های دارای Android نسخه 6.0 (سطح API 23) و بالاتر، این مجوز می‌تواند هر مجوزی باشد که در مانیفست برنامه اعلام شده است. در دستگاه‌های دارای Android نسخه 5.1 (سطح API 22) و پایین‌تر، باید مجوز اختیاری تعریف شده توسط برنامه باشد.
revoke package_name permission لغو مجوز از یک برنامه در دستگاه‌های دارای Android نسخه 6.0 (سطح API 23) و بالاتر، این مجوز می‌تواند هر مجوزی باشد که در مانیفست برنامه اعلام شده است. در دستگاه‌های دارای Android نسخه 5.1 (سطح API 22) و پایین‌تر، باید مجوز اختیاری تعریف شده توسط برنامه باشد.
set-install-location location محل نصب پیش فرض را تغییر دهید. مقادیر مکان:
  • 0 : خودکار: به سیستم اجازه دهید بهترین مکان را تعیین کند.
  • 1 : داخلی: روی حافظه داخلی دستگاه نصب کنید.
  • 2 : خارجی: نصب بر روی رسانه خارجی.

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

get-install-location مکان نصب فعلی را برمی‌گرداند. مقادیر برگشتی:
  • 0 [auto] : به ​​سیستم اجازه دهید بهترین مکان را تعیین کند
  • 1 [internal] : روی حافظه داخلی دستگاه نصب کنید
  • 2 [external] : روی رسانه خارجی نصب کنید
set-permission-enforced permission [true | false] مشخص کنید که آیا مجوز داده شده باید اجرا شود یا خیر.
trim-caches desired_free_space برای رسیدن به فضای خالی داده شده، فایل های کش را کوتاه کنید.
create-user user_name یک کاربر جدید با user_name ایجاد کنید و شناسه کاربری جدید کاربر را چاپ کنید.
remove-user user_id کاربر با user_id داده شده را حذف کنید و تمام داده های مرتبط با آن کاربر را حذف کنید
get-max-users حداکثر تعداد کاربران پشتیبانی شده توسط دستگاه را چاپ کنید.
get-app-links [ options ] [ package ]

وضعیت تأیید دامنه را برای package داده شده یا برای همه بسته‌ها در صورتی که هیچ کدام مشخص نشده است چاپ کنید. کدهای ایالتی به صورت زیر تعریف می شوند:

  • none : چیزی برای این دامنه ثبت نشده است
  • verified : دامنه با موفقیت تایید شد
  • approved : مورد تایید زور، معمولا از طریق پوسته
  • denied : به زور انکار می شود، معمولاً از طریق پوسته
  • migrated : تأیید صحت از یک پاسخ قدیمی
  • restored : تأیید صحت از بازیابی اطلاعات کاربر
  • legacy_failure : توسط یک تایید کننده قدیمی رد شد، دلیل نامعلوم
  • system_configured : به طور خودکار توسط پیکربندی دستگاه تأیید می شود
  • >= 1024 : کد خطای سفارشی که مخصوص تأیید کننده دستگاه است

گزینه ها عبارتند از:

  • --user user_id : شامل انتخاب های کاربر. همه دامنه‌ها را شامل شود، نه فقط خودکار تأیید.
reset-app-links [ options ] [ package ]

وضعیت تأیید دامنه را برای بسته داده شده بازنشانی کنید، یا برای همه بسته ها اگر هیچ کدام مشخص نشده باشد.

  • package : بسته برای بازنشانی یا "همه" برای بازنشانی همه بسته ها

گزینه ها عبارتند از:

  • --user user_id : شامل انتخاب های کاربر. شامل همه دامنه‌ها، نه فقط تأیید خودکار.
verify-app-links [ --re-verify ] [ package ]

یک درخواست تأیید برای package داده شده، یا برای همه بسته‌ها در صورتی که هیچ کدام مشخص نشده است، پخش کنید. فقط در صورتی ارسال می شود که بسته قبلاً پاسخی ثبت نکرده باشد.

  • --re-verify : ارسال حتی اگر بسته پاسخی را ثبت کرده باشد
set-app-links [--package package ] state domains

به صورت دستی وضعیت یک دامنه را برای یک بسته تنظیم کنید. دامنه باید توسط بسته به عنوان autoVerify اعلام شود تا این کار کار کند. این دستور برای دامنه هایی که نمی توانند اعمال شوند، خرابی ��ا گزارش نمی کند.

  • --package package : بسته ای که باید تنظیم شود یا "همه" برای تنظیم همه بسته ها
  • state : کدی که دامنه ها را روی آن تنظیم کنید. مقادیر معتبر عبارتند از:
    • STATE_NO_RESPONSE (0) : تنظیم مجدد به گونه ای که گویی هرگز پاسخی ثبت نشده است.
    • STATE_SUCCESS (1) : دامنه را به عنوان تأیید شده با موفقیت توسط عامل تأیید دامنه در نظر بگیرید. توجه داشته باشید که عامل تأیید دامنه می تواند این مورد را لغو کند.
    • STATE_APPROVED (2) : با دامنه مانند همیشه تأیید شده رفتار کنید، از تغییر آن توسط عامل تأیید دامنه جلوگیری کنید.
    • STATE_DENIED (3) : با دامنه مانند همیشه رد شده رفتار کنید و از تغییر آن توسط عامل تأیید دامنه جلوگیری کنید.
  • domains : فهرستی از دامنه‌هایی که با فاصله از هم جدا می‌شوند، یا «همه» برای تغییر هر دامنه.
set-app-links-user-selection --user user_id [--package package ] enabled domains

به صورت دستی وضعیت انتخاب کاربر میزبان را برای یک بسته تنظیم کنید. دامنه باید توسط بسته برای این کار اعلام شود. این دستور عدم موفقیت دامنه هایی را که قابل استفاده نیستند گزارش نمی کند.

  • --user user_id : کاربر برای تغییر انتخاب برای
  • --package package : بسته تنظیم شده
  • enabled : آیا دامنه را تصویب کنید
  • domains : لیست جدا شده از فضا از دامنه ها برای تغییر ، یا "همه" برای تغییر هر دامنه
set-app-links-user-selection --user user_id [--package package ] enabled domains

به صورت دستی وضعیت انتخاب کاربر میزبان را برای یک بسته تنظیم کنید. دامنه باید توسط بسته برای این کار اعلام شود. این دستور عدم موفقیت دامنه هایی را که قابل استفاده نیستند گزارش نمی کند.

  • --user user_id : کاربر برای تغییر انتخ��ب برای
  • --package package : بسته تنظیم شده
  • enabled : آیا دامنه را تصویب کنید
  • domains : لیست جدا شده از فضا از دامنه ها برای تغییر ، یا "همه" برای تغییر هر دامنه
set-app-links-allowed --user user_id [--package package ] allowed

تنظیم خودکار پیوند خودکار را برای یک بسته بندی کنید.

  • --user user_id : کاربر برای تغییر انتخاب برای
  • --package package : بسته ای برای تنظیم یا "همه" برای تنظیم همه بسته ها. در صورت عدم مشخص شدن بسته ها ، بسته ها دوباره تنظیم می شوند
  • allowed : درست است که به بسته اجازه دهید پیوندهای تأیید شده خودکار ، False To Disable باز شود
get-app-link-owners --user user_id [--package package ] domains

صاحبان را برای یک دامنه خاص برای یک کاربر خاص به ترتیب کم ارزش و بالا چاپ کنید.

  • --user user_id : کاربر برای پرس و جو برای
  • --package package : به صورت اختیاری برای کلیه دامنه های وب اعلام شده توسط یک بسته یا "All" برای چاپ همه بسته ها نیز چاپ می شود
  • domains : لیست جدا شده از فضا از دامنه ها برای پرس و جو برای

مدیر خط مشی دستگاه تماس ( dpm )

برای کمک به شما در توسعه و آزمایش برنامه های مدیریت دستگاه خود ، دستورات مربوط به ابزار مدیر خط مشی دستگاه ( dpm ) را صادر کنید. از ابزار برای کنترل برنامه Active Admin یا تغییر داده های وضعیت یک خط مشی در دستگاه استفاده کنید.

در حالی که در یک پوسته است ، نحو dpm :

dpm command

همچنین می توانید بدون وارد کردن یک پوسته از راه دور ، یک دستور مدیر خط مشی دستگاه را مستقیماً از adb صادر کنید:

adb shell dpm command

جدول 3. دستورات مدیر خط مشی دستگاه موجود

فرمان توضیحات
set-active-admin [ options ] component component به عنوان مدیر فعال تنظیم می کند.

گزینه ها عبارتند از:

  • --user user_id : کاربر هدف را مشخص کنید. همچنین می توانید برای انتخاب کاربر فعلی ، از --user current عبور کنید.
set-profile-owner [ options ] component component به عنوان مدیر فعال و بسته آن به عنوان صاحب پروفایل برای یک کاربر موجود تنظیم کنید.

گزینه ها عبارتند از:

  • --user user_id : کاربر هدف را مشخص کنید. همچنین می توانید برای انتخاب کاربر فعلی ، از --user current عبور کنید.
  • --name name : نام سازمان قابل خواندن انسانی را مشخص کنید.
set-device-owner [ options ] component component به عنوان مدیر فعال و بسته آن به عنوان صاحب دستگاه تنظیم کنید.

گزینه ها عبارتند از:

  • --user user_id : کاربر هدف را مشخص کنید. همچنین می توانید برای انتخاب کاربر فعلی ، از --user current عبور کنید.
  • --name name : نام سازمان قابل خواندن انسانی را مشخص کنید.
remove-active-admin [ options ] component یک مدیر فعال را غیرفعال کنید. برنامه باید android:testOnly در مانیفست. این دستور همچنین صاحبان دستگاه و پروفایل را حذف می کند.

گزینه ها عبارتند از:

  • --user user_id : کاربر هدف را مشخص کنید. همچنین می توانید برای انتخاب کاربر فعلی ، از --user current عبور کنید.
clear-freeze-period-record سوابق دستگاه از دوره های فریز شده قبلی را برای به روزرسانی های سیستم OTA پاک کنید. این برای جلوگیری از محدودیت برنامه ریزی دستگاه هنگام تهیه برنامه هایی که دوره های یخ زدگی را مدیریت می کنند ، مفید است. به به روزرسانی های مدیریت سیستم مراجعه کنید.

پشتیبانی شده از دستگاه های دارای Android 9.0 (API سطح 28) و بالاتر.

force-network-logs سیستم را مجبور کنید تا هرگونه سیاهه شبکه موجود را برای بازیابی توسط DPC آماده کند. اگر اتصال یا گزارش های DNS در دسترس باشد ، DPC پاسخ به تماس onNetworkLogsAvailable() را دریافت می کند. به ورود به سیستم فعالیت شبکه مراجعه کنید.

این دستور محدود به نرخ است. پشتیبانی شده از دستگاه های دارای Android 9.0 (API سطح 28) و بالاتر.

force-security-logs سیستم را مجبور کنید تا هرگونه سیاهه امنیتی موجود را در دسترس DPC قرار دهد. اگر سیاهههای موجود در دسترس باشد ، DPC پاسخ تماس با onSecurityLogsAvailable() دریافت می کند. به فعالیت دستگاه ورود به سیستم مراجعه کنید.

این دستور محدود به نرخ است. پشتیبانی شده از دستگاه های دارای Android 9.0 (API سطح 28) و بالاتر.

اسکرین شات بگیرید

دستور screencap یک ابزار پوسته برای گرفتن تصویر از صفحه نمایش دستگاه است.

در حالی که در یک پوسته ، نحو screencap است:

screencap filename

برای استفاده از screencap از خط فرمان ، موارد زیر را وارد کنید:

adb shell screencap /sdcard/screen.png

در اینجا یک جلسه تصویر به عنوان مثال ، با استفاده از پوسته adb برای ضبط تصویر و دستور pull برای بارگیری فایل از دستگاه وجود دارد:

$ adb shell
shell@ $ screencap /sdcard/screen.png
shell@ $ exit
$ adb pull /sdcard/screen.png

یک ویدیو ضبط کنید

فرمان screenrecord یک ابزار پوسته برای ضبط نمایش دستگاه هایی است که Android 4.4 (API سطح 19) و بالاتر را اجرا می کنند. ابزار برنامه فعالیت صفحه را به یک فایل MPEG-4 ثبت می کند. می توانید از این فایل برای ایجاد فیلم های تبلیغاتی یا آموزشی یا برای اشکال زدایی و آزمایش استفاده کنید.

در یک پوسته از نحو زیر استفاده کنید:

screenrecord [options] filename

برای استفاده از screenrecord از خط فرمان ، موارد زیر را وارد کنید:

adb shell screenrecord /sdcard/demo.mp4

ضبط صفحه را با فشار دادن کنترل+c متوقف کنید. در غیر این صورت ، ضبط به طور خودکار در سه دقیقه یا محدودیت زمانی تعیین شده توسط- --time-limit Time متوقف می شود.

برای شروع ضبط صفحه دستگاه خود ، دستور screenrecord را برای ضبط فیلم اجرا کنید. سپس دستور pull را اجرا کنید تا ویدیو را از دستگاه به رایانه میزبان بارگیری کنید. در اینجا یک جلسه ضبط مثال وجود دارد:

$ adb shell
shell@ $ screenrecord --verbose /sdcard/demo.mp4
(press Control + C to stop)
shell@ $ exit
$ adb pull /sdcard/demo.mp4

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

محدودیت های ابزار screenrecord :

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

جدول 4. گزینه های screenrecord

گزینه ها توضیحات
--help نمایش نحو و گزینه های فرمان
--size width x height اندازه فیلم را تنظیم کنید: 1280x720 . مقدار پیش فرض وضوح صفحه نمایش بومی دستگاه (در صورت پشتیبانی) ، در صورت عدم پشتیبانی 1280x720 است. برای بهترین نتیجه ، از اندازه ای پشتیبانی شده توسط رمزگذار برنامه نویسی ویدیویی پیشرفته ��ستگاه خود (AVC) استفاده کنید.
--bit-rate rate نرخ بیت ویدیو را برای این فیلم ، در مگابیت در ثانیه تنظیم کنید. مقدار پیش فرض 20Mbps است. شما می توانید نرخ بیت را برای بهبود کیفیت فیلم افزایش دهید ، اما انجام این کار منجر به پرونده های بزرگتر فیلم می شود. مثال زیر نرخ بیت ضبط را به 6Mbps تنظیم می کند:
screenrecord --bit-rate 6000000 /sdcard/demo.mp4
--time-limit time حداکثر زمان ضبط را در چند ثانیه تنظیم کنید. مقدار پیش فرض و حداکثر 180 (3 دقیقه) است.
--rotate خروجی 90 درجه را بچرخانید. این ویژگی تجربی است.
--verbose اطلاعات ورود به سیستم را در صفحه Command-Line نمایش دهید. اگر این گزینه را تنظیم نکنید ، ابزار در هنگام اجرا هیچ اطلاعاتی را نشان نمی دهد.

پروفایل های هنری را برای برنامه ها بخوانید

با شروع Android 7.0 (API سطح 24) ، Android Runtime (ART) پروفایل های اجرای برنامه های نصب شده را جمع می کند ، که برای بهینه سازی عملکرد برنامه استفاده می شود. پروفایل های جمع آوری شده را بررسی کنید تا بفهمید کدام روش ها به طور مکرر اجرا می شوند و از کدام کلاس ها در هنگام راه اندازی برنامه استفاده می شوند.

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

برای تولید فرم متنی از اطلاعات پروفایل ، از دستور زیر استفاده کنید:

adb shell cmd package dump-profiles package

برای بازیابی پرونده تولید شده ، از:

adb pull /data/misc/profman/package.prof.txt

تنظیم مجدد دستگاه های تست

اگر برنامه خود را در چندین دستگاه تست آزمایش کنید ، ممکن است تنظیم مجدد دستگاه خود بین تست ها مفید باشد ، به عنوان مثال ، حذف داده های کاربر و تنظیم مجدد محیط آزمایش. شما می توانید با استفاده از دستور testharness adb shell ، یک دستگاه آزمایشی را که در حال اجرا Android 10 (سطح API 29) یا بالاتر است ، انجام دهید ، همانطور که نشان داده شده است:

adb shell cmd testharness enable

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

علاوه بر این ، برای کمک به آسان��ر و ایمن تر کردن آزمایش برنامه خود ، با استفاده از testharness برای بازگرداندن یک دستگاه همچنین تنظیمات دستگاه زیر را تغییر می دهد:

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

اگر برنامه شما نیاز به تشخیص و تطبیق با تنظیمات پیش فرض دستور testharness دارد ، از ActivityManager.isRunningInUserTestHarness() استفاده کنید.

ساق پا

sqlite3 برنامه خط فرمان sqlite را برای بررسی پایگاه داده های SQLite شروع می کند. این شامل دستوراتی مانند .dump برای چاپ محتویات یک جدول و .schema برای چاپ SQL CREATE بیانیه ای برای یک جدول موجود است. همچنین می توانید دستورات SQLite را از خط فرمان اجرا کنید ، همانطور که نشان داده شده است:

$ adb -s emulator-5554 shell
$ sqlite3 /data/data/com.example.app/databases/rssitems.db
SQLite version 3.3.12
Enter ".help" for instructions

توجه: در صورت دسترسی ریشه ای به سیستم فایل ، به عنوان مثال ، به عنوان مثال ، در یک شبیه ساز ، دسترسی به یک پایگاه داده SQLite امکان پذیر است.

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

Backends USB ADB

سرور ADB می تواند از طریق دو باکتری با پشته USB ارتباط برقرار کند. این یا می تواند از پس زمینه بومی سیستم عامل (ویندوز ، لینوکس یا MACOS) استفاده کند یا می تواند از Backend libusb استفاده کند. برخی از ویژگی ها ، مانند attach ، detach و تشخیص سرعت USB ، فقط در هنگام استفاده از باطن libusb در دسترس هستند.

با استفاده از متغیر محیط ADB_LIBUSB می توانید یک باطن را انتخاب کنید. اگر تنظیم نشده باشد ، ADB از باطن پیش فرض خود استفاده می کند. رفتار پیش فرض در بین سیستم عامل مت��اوت است. با شروع با ADB V34 ، از Backend liubusb به طور پیش فرض در همه سیستم عامل ها به جز ویندوز استفاده می شود ، جایی که از پس زمینه بومی به طور پیش فرض استفاده می شود. اگر ADB_LIBUSB تنظیم شده باشد ، تعیین می کند که آیا از پس زمینه بومی یا libusb استفاده می شود. برای اطلاعات بیشتر در مورد متغیرهای محیط ADB ، به صفحه دستی ADB مراجعه کنید.

Backends ADB MDNS

ADB می تواند از پروتکل Multicast DNS برای اتصال خودکار سرور و دستگاه ها استفاده کند. سرور ADB با دو پشتیبان ، Bonjour (MDNSresponder اپل) و OpenScreen ارسال می شود.

Bonjour Backend برای اجرای دستگاه میزبان به یک Daemon نیاز دارد. در Daemon داخلی MacOS Apple همیشه در حال اجرا است ، اما در ویندوز و لینوکس ، کاربر باید اطمینان حاصل کند که Daemon mdnsd در حال اجرا است. اگر دستور adb mdns check خطایی را بازگرداند ، به احتمال زیاد ADB از Bonjour Backend استفاده می کند اما هیچ Daemon Bonjour در حال اجرا نیست.

Backend OpenScreen نیازی به Daemon برای اجرای دستگاه ندارد. پشتیبانی از باطن OpenScreen در MACOS از ADB V35 شروع می شود. ویندوز و لینوکس از ADB V34 پشتیبانی می شوند.

به طور پیش فرض ADB از Bonjour Backend استفاده می کند. این رفتار را می توان با استفاده از متغیر محیط ADB_MDNS_OPENSCREEN تغییر داد (تنظیم 1 یا 0 ). برای جزئیات بیشتر به صفحه دستی ADB مراجعه کنید.

،

Android Debug Bridge ( adb ) یک ابزار خط فرمان همه کاره است که به شما امکان می دهد با یک دستگاه ارتباط برقرار کنید. دستور adb انواع اعمال دستگاه مانند نصب و اشکال زدایی برنامه ها را تسهیل می کند. adb دسترسی به پوسته یونیکس را فراهم می کند که می توانید از آن برای اجرای انواع دستورات روی دستگاه استفاده کنید. این یک برنامه سرور مشتری است که شامل سه مؤلفه است:

  • مشتری ، که دستورات را ارسال می کند. مشتری روی دستگاه توسعه شما اجرا می شود. با صدور یک دستور adb می توانید از یک ترمینال خط فرمان استفاده کنید.
  • Daemon (ADBD) ، که دستورات را روی یک دستگاه اجرا می کند. Daemon به عنوان یک فرآیند پس زمینه در هر دستگاه اجرا می شود.
  • سرور ، که ارتباط بین مشتری و daemon را مدیریت می کند. سرور به عنوان یک فرآیند پس زمینه در دستگاه توسعه شما اجرا می شود.

adb در بسته Android SDK Platform Tools گنجانده شده است. این بسته را با SDK Manager بارگیری کنید ، که آن را در android_sdk /platform-tools/ نصب می کند. اگر می خواهید بسته ابزارهای SDK SDK STANLONE ANDALONE ، آن را در اینجا بارگیری کنید .

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

چگونه ADB کار می کند

هنگامی که مشتری adb شروع می کنید ، مشتری ابتدا بررسی می کند که آیا فرآیند سرور adb در حال اجرا است یا خیر. اگر وجود نداشته باشد ، فرایند سرور را شروع می کند. با شروع سرور ، به پورت محلی TCP 5037 متصل می شود و دستورات ارسال شده از مشتری های adb را گوش می دهد.

توجه: همه کلاینت های adb برای ارتباط با سرور adb از پورت 5037 استفاده می کنند.

سپس سرور اتصالات را به تمام دستگاه های در حال اجرا تنظیم می کند. این شبیه سازها را با اسکن درگاه های شماره عجیب و غریب در محدوده 5555 تا 5585 ، که دامنه ای است که توسط 16 شبیه ساز اول استفاده می شود ، قرار می دهد. جایی که سرور یک Daemon adb (ADBD) پیدا می کند ، اتصال به آن درگاه را تنظیم می کند.

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

شبیه ساز 1 ، کنسول: 5554
شبیه ساز 1 ، adb : 5555
شبیه ساز 2 ، کنسول: 5556
شبیه ساز 2 ، adb : 5557
و غیره

همانطور که نشان داده شده است ، شبیه ساز متصل به adb در پورت 5555 همان شبیه ساز است که کنسول در پورت 5554 گوش می کند.

هنگامی که سرور اتصالات همه دستگاه ها را تنظیم کرد ، می توانید از دستورات adb برای دسترسی به آن دستگاه ها استفاده کنید. از آنجا که سرور اتصالات را به دستگاه ها مدیریت می کند و دستورات زیادی را از مشتری های مختلف adb کنترل می کند ، می توانید هر دستگاه را از هر مشتری یا از اسکریپت کنترل کنید.

اشکال زدایی adb را در دستگاه خود فعال کنید

برای استفاده از adb با دستگاهی که از طریق USB متصل است، باید اشکال زدایی USB را در تنظیمات سیستم دستگاه، در قسمت گزینه های برنامه نویس فعال کنید. در Android 4.2 (API سطح 17) و بالاتر ، صفحه گزینه های توسعه دهنده به طور پیش فرض پنهان است. برای قابل مشاهده کردن، گزینه های برنامه نویس را فعال کنید.

اکنون می توانید دستگاه خود را با USB وصل کنید. می‌توانید با اجرای adb devices از پوشه android_sdk /platform-tools/ تأیید کنید که دستگاه شما متصل است. در صورت اتصال، نام دستگاه را می‌بینید که به‌عنوان «دستگاه» فهرست شده است.

توجه: هنگامی که دستگاهی را که Android 4.2.2 (API سطح 17) یا بالاتر را در حال اجرا است وصل می کنید ، سیستم یک گفتگو را نشان می دهد که می پرسد آیا یک کلید RSA را می پذیرد که امکان ا��کال زدایی ا�� طریق این ��ایانه را فراهم می کند. این مکانیسم امنیتی از دستگاه های کاربر محافظت می کند زیرا تضمین می کند که اشکال زدایی USB و سایر دستورات ADB قابل اجرا نیستند مگر اینکه بتوانید دستگاه را باز کنید و گفتگو را تصدیق کنید.

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

از طریق Wi-Fi به یک دستگاه متصل شوید

توجه: دستورالعمل های زیر در مورد دستگاه های Wear در حال اجرا Android 11 (API سطح 30) اعمال نمی شود. برای اطلاعات بیشتر به راهنمای اشکال زدایی یک برنامه OS Wear مراجعه کنید.

Android 11 (API سطح 30) و پشتیبانی بالاتر استقرار و اشکال زدایی برنامه شما به صورت بی سیم از ایستگاه کاری خود با استفاده از Android Debug Bridge (ADB). به عنوان مثال ، می توانید برنامه اشکال زدایی خود را در چندین دستگاه از راه دور مستقر کنید بدون اینکه نیاز به اتصال جسمی دستگاه خود از طریق USB داشته باشید. این امر نیاز به مقابله با مشکلات مشترک اتصال USB ، مانند نصب درایور را از بین می برد.

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

  • اطمینان حاصل کنید که ایستگاه کاری و دستگاه شما به همان شبکه بی سیم وصل شده است.

  • اطمینان حاصل کنید که دستگاه شما در حال اجرا Android 11 (API سطح 30) یا بالاتر برای تلفن یا Android 13 (API سطح 33) یا بالاتر برای تلویزیون و پوشاک است. برای اطلاعات بیشتر ، نسخه Android خود را بررسی و به روز کنید .

  • در صورت استفاده از IDE ، اطمینان حاصل کنید که آخرین نسخه Android Studio را نصب کرده اید. می توانید آن را از اینجا دانلود کنید.

  • در ایستگاه کاری خود ، آخرین نسخه ابزارهای پلت فرم SDK را به روز کنید.

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

  1. گزینه های توسعه دهنده را در دستگاه خود فعال کنید .

  2. Android Studio را باز کنید و دستگاه های جفت را با استفاده از Wi-Fi از منوی Run Configurations انتخاب کنید.

    منوی کشویی تنظیمات را اجرا کنید
    شکل 1. منوی تنظیمات را اجرا کنید.

    دستگاه های زوج از طریق پنجره Wi-Fi ظاهر می شوند ، همانطور که در شکل 2 نشان داده شده است.

    تصویر از دستگاه های زوج از طریق پنجره پنجره Wi-Fi
    شکل 2. پنجره پنجره برای جفت کردن دستگاه ها با استفاده از کد QR یا کد جفت شدن.
  3. در دستگاه خود ، روی اشکال زدایی بی سیم ضربه بزنید و دستگاه خود را جفت کنید:

    تصویر یک تلفن پیکسل که تنظیمات سیستم های اشکال زدایی بی سیم را نشان می دهد.
    شکل 3. تصویر تنظیمات اشکال زدایی بی سیم در تلفن Google Pixel.
    1. برای جفت کردن دستگاه خود با کد QR ، دستگاه جفت را با کد QR انتخاب کرده و کد QR به دست آمده از دستگاه های جفت را از طریق پنجره Wi-Fi نشان داده شده در شکل 2 اسکن کنید.

    2. برای جفت کردن دستگاه خود با یک کد جفت شدن ، دستگاه جفت را با کد جفت شدن از دستگاه های جفت بیش از Wi-Fi Popup انتخاب کنید. در دستگاه خود با استفاده از کد جفت شدن ، جفت را انتخاب کنید و از کد شش رقمی ارائه شده توجه داشته باشید. پس از ظاهر شدن دستگاه شما در دستگاه های جفت از پنجره Wi-Fi ، می توانید جفت را انتخاب کرده و کد شش رقمی نشان داده شده در دستگاه خود را وارد کنید.

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

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

  5. اگر می خواهید به سرعت اشکال زدایی بی سیم را روشن و خاموش کنید ، می توانید از کاشی های توسعه دهنده تنظیمات سریع برای اشکال زدایی بی سیم استفاده کنید ، که در گزینه های توسعه دهنده > کاشی های توسعه دهنده تنظیم کننده سریع یافت می شود.

    تصاویر کاشی های توسعه دهنده تنظیمات سریع از یک تلفن Google Pixel.
    شکل 5. تنظیم سریع کاشی های توسعه دهنده تنظیمات به شما امکان می دهد تا سریعاً اشکال زدایی بی سیم را روشن و خاموش کنید.

اتصال Wi-Fi با استفاده از خط فرمان

از طرف دیگر ، برای اتصال به دستگاه خود با استفاده از خط فرمان بدون استودیوی Android ، این مراحل را دنبال کنید:

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

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

  3. در ایستگاه کاری خود ، یک پنجره ترمینال را باز کرده و به android_sdk/platform-tools بروید.

  4. آدرس IP ، شماره پورت و کد جفت شدن خود را با انتخاب دستگاه جفت با کد جفت شدن پیدا کنید. به آدرس IP ، شماره پورت و کد جفت نمایش داده شده در دستگاه توجه داشته باشید.

  5. در ترمینال ایستگاه کاری خود ، adb pair ipaddr:port اجرا کنید. از بالا از آدرس IP و شماره پورت از بالا استفاده کنید.

  6. در صورت درخواست ، کد جفت شدن را وارد کنید ، همانطور که در زیر آمده است.

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

مشکلات اتصال بی سیم را حل کنید

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

بررسی کنید که آیا ایستگاه کاری و دستگاه شما پیش نیازها را برآورده می کند

بررسی کنید که ایستگاه کاری و دستگاه پیش نیازهای ذکر شده در ابتدای این بخش را ملاقات کنید.

سایر موارد شناخته شده را بررسی کنید

در زیر لیستی از موضوعات شناخته شده فعلی با اشکال زدایی بی سیم (با ADB یا Android Studio) و نحوه حل آنها وجود دارد:

  • Wi-Fi در حال اتصال نیست : شبکه های Wi-Fi ایمن ، مانند شبکه های Wi-Fi شرکت ، ممکن است اتصالات P2P را مسدود کرده و به شما اجازه نمی دهد از طریق Wi-Fi متصل شوید. سعی کنید با یک کابل یا شبکه Wi-Fi دیگری (غیر CORP) وصل کنید. اتصال بی سیم با استفاده از adb connect ip : port Over TCP/IP (به دنبال اتصال USB اولیه) گزینه دیگری است ، در صورت استفاده از شبکه غیر CORP گزینه ای است.

  • adb Over Wi-Fi گاهی اوقات به طور خودکار خاموش می شود : اگر دستگاه یا شبکه های Wi-Fi را تغییر دهد یا از شبکه جدا شود ، این اتفاق می افتد. برای حل و فصل ، دوباره به شبکه وصل شوید.

  • دستگاهی که پس از جفت شدن با موفقیت وصل نمی شوند : adb به MDN ها متکی است تا کشف و به طور خودکار به دستگاه های زوج متصل شود. اگر پیکربندی شبکه یا دستگاه شما از MDN ها پشتیبانی نمی کند یا آن را غیرفعال کرده است ، پس باید با استفاده از adb connect ip : port به صورت دستی به دستگاه متصل شوید.

پس از اتصال USB اولیه (تنها گزینه موجود در Android 10 و پایین) با یک دستگاه بی سیم را به صورت بی سیم متصل کنید)

توجه: این گردش کار نیز در مورد Android 11 (و بالاتر) نیز قابل استفاده است ، که این نکته که شامل یک اتصال * اولیه * از طریق USB فیزیکی نیز می شود.

توجه: دستورالعمل های زیر در مورد دستگاه های Wear در حال اجرا Android 10 (API سطح 29) یا پایین تر اعمال نمی شود. برای اطلاعات بیشتر به راهنمای اشکال زدایی یک برنامه OS Wear مراجعه کنید.

adb معمولاً از طریق USB با دستگاه ارتباط برقرار می کند ، اما می توانید از Wi-Fi adb نیز استفاده کنید. برای اتصال دستگاهی که Android 10 (API سط�� 29) یا پایین تر دارد ، این مراحل اولیه را از طریق USB دنبال کنید:

  1. دستگاه Android و رایانه میزبان adb خود را به یک شبکه Wi-Fi مشترک وصل کنید.
  2. توجه: مراقب باشید که همه نقاط دسترسی مناسب نیستند. شاید لازم باشد از یک نقطه دسترسی استفاده کنید که فایروال به درستی برای پشتیبانی adb پیکربندی شده است.

  3. دستگاه را با کابل USB به رایانه میزبان وصل کنید.
  4. دستگاه هدف را برای گوش دادن به اتصال TCP/IP در پورت 5555 تنظیم کنید:
    adb tcpip 5555
    
  5. کابل USB را از دستگاه هدف جدا کنید.
  6. آدرس IP دستگاه Android را پیدا کنید. به عنوان مثال ، در یک دستگاه Nexus ، می توانید آدرس IP را در تنظیمات > درباره رایانه لوحی (یا درباره تلفن )> وضعیت > آدرس IP پیدا کنید.
  7. توسط آدرس IP خود به دستگاه وصل شوید:
    adb connect device_ip_address:5555
    
  8. تأیید کنید که رایانه میزبان شما به دستگاه هدف وصل شده است:
    $ adb devices
    List of devices attached
    device_ip_address:5555 device
    

دستگاه شما اکنون به adb وصل شده است.

اگر اتصال adb به دستگاه شما از بین رفته باشد:

  • اطمینان حاصل کنید که میزبان شما هنوز به همان شبکه Wi-Fi به عنوان دستگاه Android شما متصل است.
  • دوباره با اجرای مرحله adb connect دوباره وصل شوید.
  • اگر این کار نمی کند ، میزبان adb خود را مجدداً تنظیم کنید:
    adb kill-server
    

    سپس از ابتدا شروع کنید.

پرس و جو برای دستگاه ها

قبل از صدور دستورات adb ، مفید است بدانید که نمونه های دستگاه به سرور adb چه متصل هستند. لیستی از دستگاه های پیوست شده را با استفاده از دستور devices تولید کنید:

  adb devices -l
  

در پاسخ ، adb این اطلاعات وضعیت را برای هر دستگاه چاپ می کند:

  • شماره سریال: adb رشته ای را برای شناسایی منحصر به فرد دستگاه با شماره پورت خود ایجاد می کند. در اینجا یک شماره سریال مثال وجود دارد: emulator-5554
  • حالت: وضعیت اتصال دستگاه می تواند یکی از موارد زیر باشد:
    • offline : دستگاه به adb متصل نیست یا پاسخ نمی دهد.
    • device : دستگاه به سرور adb وصل شده است. توجه داشته باشید که این حالت دلالت بر این ندارد که سیستم اندرویدی کاملاً بوت و عملیاتی است ، زیرا دستگاه در حالی که سیستم هنوز در حال بوت شدن است به adb متصل می شود. پس از بوت شدن ، این وضعیت عملیاتی عادی یک دستگاه است.
    • no device : هیچ دستگاهی متصل نیست.
  • توضیحات: اگر گزینه -l درج کنید ، دستور devices به شما می گوید دستگاه چیست. این اطلاعات هنگامی که چندین دستگاه به هم وصل کرده اید مفید است تا بتوانید آنها را از هم جدا کنید.

مثال زیر دستور devices و خروجی آن را نشان می دهد. سه دستگاه در حال اجرا هستند. دو خط اول در لیست شبیه سازها هستند و خط سوم دستگاه سخت افزاری است که به رایانه وصل شده است.

$ adb devices
List of devices attached
emulator-5556 device product:sdk_google_phone_x86_64 model:Android_SDK_built_for_x86_64 device:generic_x86_64
emulator-5554 device product:sdk_google_phone_x86 model:Android_SDK_built_for_x86 device:generic_x86
0a388e93      device usb:1-1 product:razor model:Nexus_7 device:flo

شبیه ساز ذکر نشده است

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

  • سرور adb در حال اجرا نیست.
  • شما از دستور emulator با گزینه -port یا -ports با مقدار پورت با شماره عجیب و غریب بین 5554 تا 5584 استفاده می کنید.
  • پورت شماره ای عجیب و غریب که انتخاب کردید مشغول کار نیست ، بنابراین می توان اتصال پورت را در شماره پورت مشخص شده ایجاد کرد-یا اگر شلوغ باشد ، شبیه ساز به درگاه دیگری تغییر می یابد که در 2 مورد نیاز را برآورده می کند.
  • سرور adb را پس از شروع شبیه ساز شروع می کنید.

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

مثال 1: در دنباله فرمان زیر ، دستور adb devices سرور adb را شروع می کند ، اما لیست دستگاه ها ظاهر نمی شود.

سرور adb را متوقف کرده و دستورات زیر را به ترتیب نشان داده شده وارد کنید. برای نام AVD ، یک نام AVD معتبر را از سیستم خود تهیه کنید. برای به دست آوردن لیستی از نام های AVD ، نوع emulator -list-avds . دستور emulator در فهرست android_sdk /tools است.

$ adb kill-server
$ emulator -avd Nexus_6_API_25 -port 5555
$ adb devices

List of devices attached
* daemon not running. starting it now on port 5037 *
* daemon started successfully *

مثال 2: در دنباله فرمان زیر ، adb devices لیست دستگاه ها را نشان می دهند زیرا سرور adb ابتدا شروع شد.

برای دیدن شبیه ساز در خروجی adb devices ، سرور adb ��ا متوقف کنید و سپس دوباره آن را پس از استفاده از دستور emulator و قبل از استفاده از دستور adb devices ، به شرح زیر شروع کنید:

$ adb kill-server
$ emulator -avd Nexus_6_API_25 -port 5557
$ adb start-server
$ adb devices

List of devices attached
emulator-5557 device

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

ارسال دستورات به یک دستگاه خاص

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

  1. برای به دست آوردن شماره سریال هدف از دستور devices استفاده کنید.
  2. پس از داشتن شماره سریال ، از گزینه -s با دستورات adb استفاده کنید تا شماره سریال را مشخص کنید.
    1. اگر می خواهید دستورات adb زیادی را صادر کنید ، می توانید متغیر محیط $ANDROID_SERIAL را تنظیم کنید تا به جای آن شماره سریال را در خود جای دهد.
    2. اگر از هر دو -s و $ANDROID_SERIAL استفاده می کنید ، -s $ANDROID_SERIAL را نادیده می گیرد.

در مثال زیر ، لیست دستگاه های پیوست به دست می آید و سپس از شماره سریال یکی از دستگاه ها برای نصب helloWorld.apk در آن دستگاه استفاده می شود:

$ adb devices
List of devices attached
emulator-5554 device
emulator-5555 device
0.0.0.0:6520  device

# To install on emulator-5555
$ adb -s emulator-5555 install helloWorld.apk
# To install on 0.0.0.0:6520
$ adb -s 0.0.0.0:6520 install helloWorld.apk

توجه: اگر در صورت وجود چندین دستگاه ، یک دستور را بدون مشخص کردن دستگاه هدف صادر می کنید ، adb خطایی "ADB: بیش از یک دستگاه/شبیه ساز" را نشان می دهد.

اگر چندین دستگاه در دسترس دارید اما فقط یک شبیه ساز است ، از گزینه -e برای ارسال دستورات به شبیه ساز استفاده کنید. اگر چندین دستگاه وجود دارد اما فقط یک دستگاه سخت افزار وصل شده است ، از گزینه -d برای ارسال دستورات به دستگاه سخت افزار استفاده کنید.

نصب یک برنامه

می توانید adb برای نصب APK بر روی یک شبیه ساز یا دستگاه متصل با دستور install استفاده کنید:

adb install path_to_apk

هنگام نصب یک تست APK ، باید از گزینه -t با دستور install استفاده کنید. برای اطلاعات بیشتر ، به -t مراجعه کنید.

برای نصب چندین APK از install-multiple استفاده کنید. این امر مفید است اگر تمام APK ها را برای یک دستگاه خاص برای برنامه خود از کنسول Play بارگیری کنید و می خواهید آنها را بر روی یک شبیه ساز یا دستگاه فیزیکی نصب کنید.

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

توجه: اگر از Android Studio استفاده می کنید ، نیازی به استفاده مستقیم از adb برای نصب برنامه خود بر روی شبیه ساز یا دستگاه ندارید. در عوض ، Android Studio بسته بندی و نصب برنامه را برای ��ما انجام می دهد.

راه اندازی بندر را تنظیم کنید

از دستور forward برای تنظیم پورت دلخواه استفاده کنید ، که درخواست ها را در یک درگاه میزبان خاص به یک درگاه متفاوت در یک دستگاه منتقل می کند. مثال زیر ارسال پورت میزبان 6100 به درگاه دستگاه 7100 را تنظیم می کند:

adb forward tcp:6100 tcp:7100

مثال زیر ارسال پورت میزبان 6100 به محلی: logd:

adb forward tcp:6100 local:logd

اگر می خواهید آنچه را که به یک درگاه معین در دستگاه ارسال می شود ، مفید باشد ، این می تواند مفید باشد. تمام داده های دریافت شده به Daemon-Logging System نوشته شده و در سیاهههای مربوط به دستگاه نمایش داده می شوند.

کپی کردن پرونده ها به یک دستگاه

برای کپی کردن پرونده ها به دستگاه و از طریق دستگاه از دستورات pull و push استفاده کنید. بر خلاف دستور install ، که فقط یک فایل APK را در یک مکان خاص کپی می کند ، دستورات pull و push به شما امکان می دهد دایرکتوری ها و پرونده های دلخواه را در هر مکان در یک دستگاه کپی کنید.

برای کپی کردن یک پرونده یا فهرست و فهرست های فرعی آن از دستگاه ، موارد زیر را انجام دهید:

adb pull remote local

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

adb push local remote

local و remote را با مسیرها به پرونده ها/دایرکتوری های هدف در دستگاه توسعه (محلی) و دستگاه (از راه دور) جایگزین کنید. به عنوان مثال:

adb push myfile.txt /sdcard/myfile.txt

سرور ADB را متوقف کنید

در بعضی موارد ، ممکن است شما نیاز به فرایند سرور adb داشته باشید و سپس آن را مجدداً راه اندازی کنید تا مشکل حل شود. به عنوان مثال ، اگر adb به یک دستور پاسخ ندهد ، می تواند این مورد باشد.

برای متوقف کردن سرور adb ، از دستور adb kill-server استفاده کنید. سپس می توانید سرور را با صدور دستور adb دیگر مجدداً راه اندازی کنید.

دستورات ADB را صادر کنید

دستورات adb را از یک خط فرمان در دستگاه توسعه خود یا از اسکریپت با استفاده از موارد زیر صادر کنید:

adb [-d | -e | -s serial_number] command

اگر فقط یک شبیه ساز در حال اجرا باشد یا فقط یک دستگاه متصل باشد ، دستور adb به طور پیش فرض به آن دستگاه ارسال می شود. اگر چندین شبیه ساز در حال اجرا هستند و/یا چندین دستگاه به هم وصل شده اند ، برای مشخص کردن دستگاه هدف که باید دستور کار را انجام دهد ، باید از گزینه -d ، -e یا -s استفاده کنید.

با استفاده از دستور زیر می توانید لیست مفصلی از کلیه دستورات adb پشتیبانی شده را مشاهده کنید:

adb --help

دستورات پوسته را صادر کنید

می توانید از دستور shell برای صدور دستورات دستگاه از طریق adb یا شروع یک پوسته تعاملی استفاده کنید. برای صدور یک دستور واحد ، از دستور shell مانند این استفاده کنید:

adb [-d |-e | -s serial_number] shell shell_command

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

adb [-d | -e | -s serial_number] shell

برای خروج از پوسته تعاملی ، Control+D یا نوع exit را فشار دهید.

Android بسیاری از ابزارهای معمول خط فرمان یونیکس را ارائه می دهد. برای لیستی از ابزارهای موجود ، از دستور زیر استفاده کنید:

adb shell ls /system/bin

کمک برای بیشتر دستورات از طریق آرگومان --help در دسترس است. بسیاری از دستورات پوسته توسط Toybox ارائه شده است. کمک عمومی قابل استفاده برای کلیه دستورات ToyBox از طریق toybox --help در دسترس است.

با استفاده از ابزارهای پلت فرم Android 23 و بالاتر ، adb آرگومان هایی را به همان روشی که دستور ssh(1) انجام می دهد ، انجام می دهد. این تغییر مشکلات زیادی را در مورد تزریق فرمان برطرف کرده است و امکان اجرای ایمن دستوراتی را که حاوی metacharacter های پوسته هستند ، مانند adb install Let\'sGo.apk امکان پذیر می کند. این تغییر بدان معنی است که تفسیر هر دستور که حاوی metacharacters پوسته باشد نیز تغییر کرده است.

به عنوان مثال ، adb shell setprop key ' two words ' اکنون یک خطا است ، زیرا نقل قول ها توسط پوسته محلی بلعیده می شوند ، و دستگاه می بیند که adb shell setprop key two words می بیند. برای کار کردن فرمان ، دو بار ، یک بار برای پوسته محلی و یک بار برای پوسته از راه دور ، همانطور که با ssh(1) انجام می دهید ، نقل قول کنید. به عنوان مثال ، adb shell setprop key "' two words '" کار می کند زیرا پوسته محلی سطح بیرونی نقل قول را می گیرد و دستگاه هنوز سطح داخلی نقل قول را می بیند: setprop key 'two words' . فرار نیز گزینه ای است ، اما نقل قول دو بار معمولاً آسان تر است.

همچنین به ابزار خط فرمان LogCat مراجعه کنید ، که برای نظارت بر ورود به سیستم مفید است.

با مدیر فعالیت تماس بگیرید

در داخل یک پوسته adb ، می توانید دستوراتی را با ابزار مدیر فعالیت ( am ) برای انجام اقدامات مختلف سیستم ، مانند شروع یک فعالیت ، فرآیند نیرو ، پخش یک قصد ، تغییر و تغییر خصوصیات صفحه دستگاه و موارد دیگر صادر کنید.

در حالی که در یک پوسته ، نحو am است:

am command

همچنین می توانید بدون وارد کردن پوسته از راه دور ، یک دستور مدیر فعالیت را مستقیماً از adb صادر کنید. به عنوان مثال:

adb shell am start -a android.intent.action.VIEW

جدول 1. دستورات مدیر فعالیت موجود

فرمان توضیحات
start [ options ] intent Activity که توسط intent مشخص شده است شروع کنید.

مشخصات استدلال های هدف را مشاهده کنید.

گزینه ها عبارتند از:

  • -D : اشکال زدایی را فعال کنید.
  • -W : منتظر تکمیل راه اندازی باشید.
  • --start-profiler file : Profiler را شروع کنید و نتایج را به file ارسال کنید.
  • -P file : مانند --start-profiler ، اما وقتی برنامه بیکار می شود ، پروفایل متوقف می شود.
  • -R count : زمان count فعالیت را تکرار کنید. قبل از هر تکرار ، فعالیت برتر به پایان می رسد.
  • -S : نیرو قبل از شروع فعالیت ، برنامه هدف را متوقف کنید.
  • --opengl-trace : ردیابی توابع OpenGL را فعال کنید.
  • --user user_id | current : مشخص کنید که کدام کاربر را باید اجرا کنید. اگر مشخص نشده است ، سپس به عنوان کاربر فعلی اجرا کنید.
startservice [ options ] intent Service مشخص شده توسط intent شروع کنید.

مشخصات استدلال های هدف را مشاهده کنید.

گزینه ها عبارتند از:

  • --user user_id | current : مشخص کنید که کدام کاربر را باید اجرا کنید. اگر مشخص نشده است ، سپس به عنوان کاربر فعلی اجرا کنید.
force-stop package Force-Stop همه چیز مرتبط با package .
kill [ options ] package تمام فرآیندهای مرتبط با package را بکشید. این دستور فقط فرایندهایی را که برای کشتن ایمن هستند ، می کشد و این امر بر تجربه کاربر تأثیر نمی گذارد.

گزینه ها عبارتند از:

  • --user user_id | all | current : مشخص کنید که فرآیندهای کاربر برای کشتن. اگر مشخص نشده است ، سپس تمام فرآیندهای کاربران را بکشید.
kill-all تمام مراحل پس زمینه را بکشید.
broadcast [ options ] intent هدف پخش را صادر کنید.

مشخصات استدلال های هدف را مشاهده کنید.

گزینه ها عبارتند از:

  • [--user user_id | all | current] : مشخص کنید که کاربر برای ارسال به کدام کاربر ارسال کنید. اگر مشخص نشده است ، سپس به همه کاربران ارسال کنید.
instrument [ options ] component نظارت را با نمونه Instrumentation انجام ��هید. به ��ور ��عمول component هدف فرم test_package / runner_class است.

گزینه ها عبارتند از:

  • -r : نتایج خام را چاپ کنید (در غیر این صورت رمزگشایی report_key_streamresult ). برای تولید خروجی خام برای اندازه گیری عملکرد با [-e perf true] استفاده کنید.
  • -e name value : name آرگومان را روی value تنظیم کنید. برای دونده های آزمون یک فرم مشترک -e testrunner_flag value [, value ...] است.
  • -p file : داده های پروفایل را برای file بنویسید.
  • -w : صبر کنید تا ابزار دقیق قبل از بازگشت به پایان برسد. برای دوندگان آزمون مورد نیاز است.
  • --no-window-animation : انیمیشن های پنجره را هنگام اجرا خاموش کنید.
  • --user user_id | current : مشخص کنید که ابزار کاربر کدام یک را اجرا می کند. اگر مشخص نشده باشد ، در کاربر فعلی اجرا کنید.
profile start process file Profiler را در process شروع کنید ، نتایج را برای file بنویسید.
profile stop process متوقف کردن پروفایل در process .
dumpheap [ options ] process file پشته process را رها کنید ، به file بنویسید.

گزینه ها عبارتند از:

  • --user [ user_id | current] : هنگام تهیه نام فرآیند ، کاربر را برای حذف کردن مشخص کنید. If not specified, the current user is used.
  • -b [| png | jpg | webp] : Dump bitmaps from graphics memory (API level 35 and above). Optionally specify the format to dump in (PNG by default).
  • -n : Dump native heap instead of managed heap.
set-debug-app [ options ] package Set app package to debug.

گزینه ها عبارتند از:

  • -w : Wait for debugger when app starts.
  • --persistent : Retain this value.
clear-debug-app Clear the package previous set for debugging with set-debug-app .
monitor [ options ] Start monitoring for crashes or ANRs.

گزینه ها عبارتند از:

  • --gdb : Start gdbserv on the given port at crash/ANR.
screen-compat {on | off} package Control screen compatibility mode of package .
display-size [reset | width x height ] Override device display size. This command is helpful for testing your app across different screen sizes by mimicking a small screen resolution using a device with a large screen, and vice versa.

مثال:
am display-size 1280x800

display-density dpi Override device display density. This command is helpful for testing your app across different screen densities by mimicking a high-density screen environment using a low-density screen, and vice versa.

مثال:
am display-density 480

to-uri intent Print the given intent specification as a URI.

See the Specification for intent arguments .

to-intent-uri intent Print the given intent specification as an intent: URI.

See the Specification for intent arguments .

Specification for intent arguments

For activity manager commands that take an intent argument, you can specify the intent with the following options:

Call package manager ( pm )

Within an adb shell, you can issue commands with the package manager ( pm ) tool to perform actions and queries on app packages installed on the device.

While in a shell, the pm syntax is:

pm command

You can also issue a package manager command directly from adb without entering a remote shell. به عنوان مثال:

adb shell pm uninstall com.example.MyApp

Table 2. Available package manager commands

Command توضیحات
list packages [ options ] filter Print all packages, optionally only those whose package name contains the text in filter .

Options:

  • -f : See associated file.
  • -d : Filter to only show disabled packages.
  • -e : Filter to only show enabled packages.
  • -s : Filter to only show system packages.
  • -3 : Filter to only show third-party packages.
  • -i : See the installer for the packages.
  • -u : Include uninstalled packages.
  • --user user_id : The user space to query.
list permission-groups Print all known permission groups.
list permissions [ options ] group Print all known permissions, optionally only those in group .

Options:

  • -g : Organize by group.
  • -f : Print all information.
  • -s : Short summary.
  • -d : Only list dangerous permissions.
  • -u : List only the permissions users will see.
list instrumentation [ options ] List all test packages.

Options:

  • -f : List the APK file for the test package.
  • target_package : List test packages for only this app.
list features Print all features of the system.
list libraries Print all the libraries supported by the current device.
list users Print all users on the system.
path package Print the path to the APK of the given package .
install [ options ] path Install a package, specified by path , to the system.

Options:

  • -r : Reinstall an existing app, keeping its data.
  • -t : Allow test APKs to be installed. Gradle generates a test APK when you have only run or debugged your app or have used the Android Studio Build > Build APK command. If the APK is built using a developer preview SDK, you must include the -t option with the install command if you are installing a test APK.
  • -i installer_package_name : Specify the installer package name.
  • --install-location location : Set the install location using one of the following values:
    • 0 : Use the default install location.
    • 1 : Install on internal device storage.
    • 2 : Install on external media.
  • -f : Install package on the internal system memory.
  • -d : Allow version code downgrade.
  • -g : Grant all permissions listed in the app manifest.
  • --fastdeploy : Quickly update an installed package by only updating the parts of the APK that changed.
  • --incremental : Installs enough of the APK to launch the app while streaming the remaining data in the background. To use this feature, you must sign the APK, create an APK Signature Scheme v4 file , and place this file in the same directory as the APK. This feature is only supported on certain devices. This option forces adb to use the feature or fail if it is not supported, with verbose information on why it failed. Append the --wait option to wait until the APK is fully installed before granting access to the APK.

    --no-incremental prevents adb from using this feature.

uninstall [ options ] package Removes a package from the system.

Options:

  • -k : Keep the data and cache directories after package removal.
  • --user user_id : Specifies the user for whom the package is removed.
  • --versionCode version_code : Only uninstalls if the app has the given version code.
clear package Delete all data associated with a package.
enable package_or_component Enable the given package or component (written as "package/class").
disable package_or_component Disable the given package or component (written as "package/class").
disable-user [ options ] package_or_component

Options:

  • --user user_id : The user to disable.
grant package_name permission Grant a permission to an app. On devices running Android 6.0 (API level 23) and higher, the permission can be any permission declared in the app manifest. On devices running Android 5.1 (API level 22) and lower, must be an optional permission defined by the app.
revoke package_name permission Revoke a permission from an app. On devices running Android 6.0 (API level 23) and higher, the permission can be any permission declared in the app manifest. On devices running Android 5.1 (API level 22) and lower, must be an optional permission defined by the app.
set-install-location location Change the default install location. Location values:
  • 0 : Auto: Let system decide the best location.
  • 1 : Internal: Install on internal device storage.
  • 2 : External: Install on external media.

Note: This is only intended for debugging. Using this can cause apps to break and other undesireable behavior.

get-install-location Returns the current install location. Return values:
  • 0 [auto] : Let system decide the best location
  • 1 [internal] : Install on internal device storage
  • 2 [external] : Install on external media
set-permission-enforced permission [true | false] Specify whether the given permission should be enforced.
trim-caches desired_free_space Trim cache files to reach the given free space.
create-user user_name Create a new user with the given user_name , printing the new user identifier of the user.
remove-user user_id Remove the user with the given user_id , deleting all data associated with that user
get-max-users Print the maximum number of users supported by the device.
get-app-links [ options ] [ package ]

Print the domain verification state for the given package , or for all packages if none is specified. State codes are defined as follows:

  • none : nothing has been recorded for this domain
  • verified : the domain has been successfully verified
  • approved : force-approved, usually through shell
  • denied : force-denied, usually through shell
  • migrated : preserved verification from a legacy response
  • restored : preserved verification from a user data restore
  • legacy_failure : rejected by a legacy verifier, unknown reason
  • system_configured : automatically approved by the device config
  • >= 1024 : custom error code, which is specific to the device verifier

گزینه ها عبارتند از:

  • --user user_id : include user selections. Include all domains, not just autoVerify ones.
reset-app-links [ options ] [ package ]

Reset domain verification state for the given package, or for all packages if none is specified.

  • package : the package to reset, or "all" to reset all packages

گزینه ها عبارتند از:

  • --user user_id : include user selections. Include all domains, not just autoVerify ones.
verify-app-links [ --re-verify ] [ package ]

Broadcast a verification request for the given package , or for all packages if none is specified. Only sends if the package has previously not recorded a response.

  • --re-verify : send even if the package has recorded a response
set-app-links [--package package ] state domains

Manually set the state of a domain for a package. The domain must be declared by the package as autoVerify for this to work. This command will not report a failure for domains that could not be applied.

  • --package package : the package to set, or "all" to set all packages
  • state : the code to set the domains to. Valid values are:
    • STATE_NO_RESPONSE (0) : reset as if no response was ever recorded.
    • STATE_SUCCESS (1) : treat domain as successfully verified by domain verification agent. Note that the domain verification agent can override this.
    • STATE_APPROVED (2) : treat domain as always approved, preventing the domain verification agent from changing it.
    • STATE_DENIED (3) : treat domain as always denied, preventing the domain verification agent from changing it.
  • domains : space-separated list of domains to change, or "all" to change every domain.
set-app-links-user-selection --user user_id [--package package ] enabled domains

Manually set the state of a host user selection for a package. The domain must be declared by the package for this to work. This command will not report a failure for domains that could not be applied.

  • --user user_id : the user to change selections for
  • --package package : the package to set
  • enabled : whether to approve the domain
  • domains : space-separated list of domains to change, or "all" to change every domain
set-app-links-user-selection --user user_id [--package package ] enabled domains

Manually set the state of a host user selection for a package. The domain must be declared by the package for this to work. This command will not report a failure for domains that could not be applied.

  • --user user_id : the user to change selections for
  • --package package : the package to set
  • enabled : whether to approve the domain
  • domains : space-separated list of domains to change, or "all" to change every domain
set-app-links-allowed --user user_id [--package package ] allowed

Toggle the auto-verified link-handling setting for a package.

  • --user user_id : the user to change selections for
  • --package package : the package to set, or "all" to set all packages; packages will be reset if no package is specified
  • allowed : true to allow the package to open auto-verified links, false to disable
get-app-link-owners --user user_id [--package package ] domains

Print the owners for a specific domain for a given user in low- to high-priority order.

  • --user user_id : the user to query for
  • --package package : optionally also print for all web domains declared by a package, or "all" to print all packages
  • domains : space-separated list of domains to query for

Call device policy manager ( dpm )

To help you develop and test your device management apps, issue commands to the device policy manager ( dpm ) tool. Use the tool to control the active admin app or change a policy's status data on the device.

While in a shell, the dpm syntax is:

dpm command

You can also issue a device policy manager command directly from adb without entering a remote shell:

adb shell dpm command

Table 3. Available device policy manager commands

Command توضیحات
set-active-admin [ options ] component Sets component as active admin.

گزینه ها عبارتند از:

  • --user user_id : Specify the target user. You can also pass --user current to select the current user.
set-profile-owner [ options ] component Set component as active admin and its package as profile owner for an existing user.

گزینه ها عبارتند از:

  • --user user_id : Specify the target user. You can also pass --user current to select the current user.
  • --name name : Specify the human-readable organization name.
set-device-owner [ options ] component Set component as active admin and its package as device owner.

گزینه ها عبارتند از:

  • --user user_id : Specify the target user. You can also pass --user current to select the current user.
  • --name name : Specify the human-readable organization name.
remove-active-admin [ options ] component Disable an active admin. The app must declare android:testOnly in the manifest. This command also removes device and profile owners.

گزینه ها عبارتند از:

  • --user user_id : Specify the target user. You can also pass --user current to select the current user.
clear-freeze-period-record Clear the device's record of previously set freeze periods for system OTA updates. This is useful to avoid the device scheduling restrictions when developing apps that manage freeze periods. See Manage system updates .

Supported on devices running Android 9.0 (API level 28) and higher.

force-network-logs Force the system to make any existing network logs ready for retrieval by a DPC. If there are connection or DNS logs available, the DPC receives the onNetworkLogsAvailable() callback. See Network activity logging .

This command is rate-limited. Supported on devices running Android 9.0 (API level 28) and higher.

force-security-logs Force the system to make any existing security logs available to the DPC. If there are logs available, the DPC receives the onSecurityLogsAvailable() callback. See Log enterprise device activity .

This command is rate-limited. Supported on devices running Android 9.0 (API level 28) and higher.

اسکرین شات بگیرید

The screencap command is a shell utility for taking a screenshot of a device display.

While in a shell, the screencap syntax is:

screencap filename

To use screencap from the command line, enter the following:

adb shell screencap /sdcard/screen.png

Here's an example screenshot session, using the adb shell to capture the screenshot and the pull command to download the file from the device:

$ adb shell
shell@ $ screencap /sdcard/screen.png
shell@ $ exit
$ adb pull /sdcard/screen.png

یک ویدیو ضبط کنید

The screenrecord command is a shell utility for recording the display of devices running Android 4.4 (API level 19) and higher. The utility records screen activity to an MPEG-4 file. You can use this file to create promotional or training videos or for debugging and testing.

In a shell, use the following syntax:

screenrecord [options] filename

To use screenrecord from the command line, enter the following:

adb shell screenrecord /sdcard/demo.mp4

Stop the screen recording by pressing Control+C. Otherwise, the recording stops automatically at three minutes or the time limit set by --time-limit .

To begin recording your device screen, run the screenrecord command to record the video. Then, run the pull command to download the video from the device to the host computer. Here's an example recording session:

$ adb shell
shell@ $ screenrecord --verbose /sdcard/demo.mp4
(press Control + C to stop)
shell@ $ exit
$ adb pull /sdcard/demo.mp4

The screenrecord utility can record at any supported resolution and bit rate you request, while retaining the aspect ratio of the device display. The utility records at the native display resolution and orientation by default, with a maximum length of three minutes.

Limitations of the screenrecord utility:

  • Audio is not recorded with the video file.
  • Video recording is not available for devices running Wear OS.
  • Some devices might not be able to record at their native display resolution. If you encounter problems with screen recording, try using a lower screen resolution.
  • Rotation of the screen during recording is not supported. If the screen does rotate during recording, some of the screen is cut off in the recording.

Table 4. screenrecord options

گزینه ها توضیحات
--help Display command syntax and options
--size width x height Set the video size: 1280x720 . The default value is the device's native display resolution (if supported), 1280x720 if not. For best results, use a size supported by your device's Advanced Video Coding (AVC) encoder.
--bit-rate rate Set the video bit rate for the video, in megabits per second. The default value is 20Mbps. You can increase the bit rate to improve video quality, but doing so results in larger movie files. The following example sets the recording bit rate to 6Mbps:
screenrecord --bit-rate 6000000 /sdcard/demo.mp4
--time-limit time Set the maximum recording time, in seconds. The default and maximum value is 180 (3 minutes).
--rotate Rotate the output 90 degrees. This feature is experimental.
--verbose Display log information on the command-line screen. If you do not set this option, the utility does not display any information while running.

Read ART profiles for apps

Starting in Android 7.0 (API level 24), the Android Runtime (ART) collects execution profiles for installed apps, which are used to optimize app performance. Examine the collected profiles to understand which methods are executed frequently and which classes are used during app startup.

Note: It is only possible to retrieve the execution profile filename if you have root access to the file system, for example, on an emulator.

To produce a text form of the profile information, use the following command:

adb shell cmd package dump-profiles package

To retrieve the file produced, use:

adb pull /data/misc/profman/package.prof.txt

Reset test devices

If you test your app across multiple test devices, it may be useful to reset your device between tests, for example, to remove user data and reset the test environment. You can perform a factory reset of a test device running Android 10 (API level 29) or higher using the testharness adb shell command, as shown:

adb shell cmd testharness enable

When restoring the device using testharness , the device automatically backs up the RSA key that allows debugging through the current workstation in a persistent location. That is, after the device is reset, the workstation can continue to debug and issue adb commands to the device without manually registering a new key.

Additionally, to help make it easier and more secure to keep testing your app, using the testharness to restore a device also changes the following device settings:

  • The device sets up certain system settings so that initial device setup wizards do not appear. That is, the device enters a state from which you can quickly install, debug, and test your app.
  • تنظیمات:
    • Disables lock screen.
    • Disables emergency alerts.
    • Disables auto-sync for accounts.
    • Disables automatic system updates.
  • دیگر:
    • Disables preinstalled security apps.

If your app needs to detect and adapt to the default settings of the testharness command, use the ActivityManager.isRunningInUserTestHarness() .

sqlite

sqlite3 starts the sqlite command-line program for examining SQLite databases. It includes commands such as .dump to print the contents of a table and .schema to print the SQL CREATE statement for an existing table. You can also execute SQLite commands from the command line, as shown:

$ adb -s emulator-5554 shell
$ sqlite3 /data/data/com.example.app/databases/rssitems.db
SQLite version 3.3.12
Enter ".help" for instructions

Note: It is only possible to access a SQLite database if you have root access to the file system, for example, on an emulator.

For more information, see the sqlite3 command line documentation .

adb USB backends

The adb server can interact with the USB stack through two backends. It can either use the native backend of the OS (Windows, Linux, or macOS) or it can use the libusb backend. Some features, such as attach , detach , and USB speed detection, are only available when using libusb backend.

You can choose a backend by using the ADB_LIBUSB environment variable. If it isn't set, adb uses its default backend. The default behavior varies among OS. Starting with ADB v34 , the liubusb backend is used by default on all OS except Windows, where the native backend is used by default. If ADB_LIBUSB is set, it determines whether the native backend or libusb is used. See the adb manual page for more information about adb environment variables.

adb mDNS backends

ADB can use the multicast DNS protocol to automatically connect the server and devices. The ADB server ships with two backends, Bonjour (Apple's mdnsResponder) and Openscreen.

The Bonjour backend needs a daemon to be running on the host machine. On macOS Apple's built-in daemon is always running, but on Windows and Linux, the user must make sure the mdnsd daemon is up and running. If the command adb mdns check returns an error, it is likely that ADB is using the Bonjour backend but there is no Bonjour daemon running.

The Openscreen backend does not need a daemon to be running on the machine. Support for the Openscreen backend on macOS starts at ADB v35. Windows and Linux are supported as of ADB v34.

By default ADB uses the Bonjour backend. This behavior can be changed using the environment variable ADB_MDNS_OPENSCREEN (set to 1 or 0 ). See the ADB manual page for further details.

،

Android Debug Bridge ( adb ) یک ابزار خط فرمان همه کاره است که به شما امکان می دهد با یک دستگاه ارتباط برقرار کنید. دستور adb انواع اعمال دستگاه مانند نصب و اشکال زدایی برنامه ها را تسهیل می کند. adb دسترسی به پوسته یونیکس را فراهم می کند که می توانید از آن برای اجرای انواع دستورات روی دستگاه استفاده کنید. It is a client-server program that includes three components:

  • A client , which sends commands. The client runs on your development machine. You can invoke a client from a command-line terminal by issuing an adb command.
  • A daemon (adbd) , which runs commands on a device. The daemon runs as a background process on each device.
  • A server , which manages communication between the client and the daemon. The server runs as a background process on your development machine.

adb در بسته Android SDK Platform Tools گنجانده شده است. Download this package with the SDK Manager , which installs it at android_sdk /platform-tools/ . If you want the standalone Android SDK Platform Tools package, download it here .

For information on connecting a device for use over adb , including how to use the Connection Assistant to troubleshoot common problems, see Run apps on a hardware device .

How adb works

When you start an adb client, the client first checks whether there is an adb server process already running. If there isn't, it starts the server process. When the server starts, it binds to local TCP port 5037 and listens for commands sent from adb clients.

توجه: همه کلاینت های adb برای ارتباط با سرور adb از پورت 5037 استفاده می کنند.

سپس سرور اتصالات را به تمام دستگاه های در حال اجرا تنظیم می کند. It locates emulators by scanning odd-numbered ports in the range 5555 to 5585, which is the range used by the first 16 emulators. Where the server finds an adb daemon (adbd), it sets up a connection to that port.

Each emulator uses a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections. به عنوان مثال:

Emulator 1, console: 5554
Emulator 1, adb : 5555
Emulator 2, console: 5556
Emulator 2, adb : 5557
و غیره

As shown, the emulator connected to adb on port 5555 is the same as the emulator whose console listens on port 5554.

Once the server has set up connections to all devices, you can use adb commands to access those devices. Because the server manages connections to devices and handles commands from multiple adb clients, you can control any device from any client or from a script.

اشکال زدایی adb را در دستگاه خود فعال کنید

برای استفاده از adb با دستگاهی که از طریق USB متصل است، باید اشکال زدایی USB را در تنظیمات سیستم دستگاه، در قسمت گزینه های برنامه نویس فعال کنید. On Android 4.2 (API level 17) and higher, the Developer options screen is hidden by default. برای قابل مشاهده کردن، گزینه های برنامه نویس را فعال کنید.

اکنون می توانید دستگاه خود را با USB وصل کنید. می‌توانید با اجرای adb devices از پوشه android_sdk /platform-tools/ تأیید کنید که دستگاه شما متصل است. در صورت اتصال، نام دستگاه را می‌بینید که به‌عنوان «دستگاه» فهرست شده است.

Note: When you connect a device running Android 4.2.2 (API level 17) or higher, the system shows a dialog asking whether to accept an RSA key that allows debugging through this computer. This security mechanism protects user devices because it ensures that USB debugging and other adb commands cannot be executed unless you're able to unlock the device and acknowledge the dialog.

For more information about connecting to a device over USB, read Run apps on a hardware device .

Connect to a device over Wi-Fi

Note: The instructions below do not apply to Wear devices running Android 11 (API level 30). See the guide to debugging a Wear OS app for more information.

Android 11 (API level 30) and higher support deploying and debugging your app wirelessly from your workstation using Android Debug Bridge (adb). For example, you can deploy your debuggable app to multiple remote devices without ever needing to physically connect your device via USB. This eliminates the need to deal with common USB connection issues, such as driver installation.

Before you begin using wireless debugging, do the following:

  • Ensure that your workstation and device are connected to the same wireless network.

  • Ensure that your device is running Android 11 (API level 30) or higher for phone or Android 13 (API level 33) or higher for TV and WearOS. For more information, see Check & update your Android version .

  • If using the IDE, ensure that you have the latest version of Android Studio installed. می توانید آن را از اینجا دانلود کنید.

  • On your workstation, update to the latest version of the SDK Platform Tools .

To use wireless debugging, you must pair your device to your workstation using a QR code or a pairing code. Your workstation and device must be connected to the same wireless network. To connect to your device, follow these steps:

  1. Enable developer options on your device.

  2. Open Android Studio and select Pair Devices Using Wi-Fi from the run configurations menu.

    Run configurations dropdown menu
    Figure 1. Run configurations menu.

    The Pair devices over Wi-Fi window pops up, as shown in figure 2.

    Screenshot of the pair devices over Wi-Fi popup window
    Figure 2. Popup window to pair devices using QR code or pairing code.
  3. On your device, tap Wireless debugging and pair your device:

    Screenshot of
            a pixel phone showing the Wireless debugging systems setting.
    Figure 3. Screenshot of the Wireless debugging setting on a Google Pixel phone.
    1. To pair your device with a QR code, select Pair device with QR code and scan the QR code obtained from the Pair devices over Wi-Fi popup shown in figure 2.

    2. To pair your device with a pairing code, select Pair device with pairing code from the Pair devices over Wi-Fi popup. On your device, select Pair using pairing code and take note of the six-digit code provided. Once your device appears on the Pair devices over Wi-Fi window, you can select Pair and enter the six-digit code shown on your device.

      Screenshot of example pin code entry
      Figure 4. Example of six-digit code entry.
  4. After your device is paired, you can attempt to deploy your app to your device.

    To pair a different device or to forget the current device on your workstation, navigate to Wireless debugging on your device. Tap your workstation name under Paired devices and select Forget .

  5. If you want to quickly turn on and off wireless debugging, you can utilize the Quick settings developer tiles for Wireless debugging , found in Developer Options > Quick settings developer tiles .

    Screenshot of
            Quick settings developer tiles from a Google Pixel phone.
    Figure 5. The Quick settings developer tiles setting lets you quickly turn wireless debugging on and off.

Wi-Fi connection using command line

Alternatively, to connect to your device using command line without Android Studio, follow these steps:

  1. Enable developer options on your device, as described earlier.

  2. Enable Wireless debugging on your device, as described earlier.

  3. On your workstation, open a terminal window and navigate to android_sdk/platform-tools .

  4. Find your IP address, port number, and pairing code by selecting Pair device with pairing code . Take note of the IP address, port number, and pairing code displayed on the device.

  5. On your workstation's terminal, run adb pair ipaddr:port . Use the IP address and port number from above.

  6. When prompted, enter the pairing code, as shown below.

    Screenshot of
            pairing on the command line.
    Figure 6. A message indicates that your device has been successfully paired.

Resolve wireless connection issues

If you are having issues connecting to your device wirelessly, try the following troubleshooting steps to resolve the issue.

Check whether your workstation and device meet the prerequisites

Check that the workstation and device meet the prerequisites listed at the beginning of this section .

Check for other known issues

The following is a list of current known issues with wireless debugging (with adb or Android Studio) and how to resolve them:

  • Wi-Fi is not connecting : Secure Wi-Fi networks, such as corporate Wi-Fi networks, may block p2p connections and not let you connect over Wi-Fi. Try connecting with a cable or another (non-corp) Wi-Fi network. Wireless connection using adb connect ip : port over tcp/ip (following an initial USB connection) is another option, in case resorting to a non-corp network is an option.

  • adb over Wi-Fi sometimes turns off automatically : This can happen if the device either switches Wi-Fi networks or disconnects from the network. To resolve, re-connect to the network.

  • Device not connecting after pairing successfully : adb relies on mDNS to discover and automatically connect to paired devices. If your network or device configuration does not support mDNS or has disabled it, then you need to manually connect to the device using adb connect ip : port .

Connect wirelessly with a device after an initial USB connection (only option available on Android 10 and lower)

Note: This workflow is applicable also to Android 11 (and higher), the caveat being that it also involves an *initial* connection over physical USB.

Note: The following instructions do not apply to Wear devices running Android 10 (API level 29) or lower. See the guide about debugging a Wear OS app for more information.

adb usually communicates with the device over USB, but you can also use adb over Wi-Fi. To connect a device running Android 10 (API level 29) or lower, follow these initial steps over USB:

  1. Connect your Android device and adb host computer to a common Wi-Fi network.
  2. Note: Beware that not all access points are suitable. You might need to use an access point whose firewall is configured properly to support adb .

  3. Connect the device to the host computer with a USB cable.
  4. Set the target device to listen for a TCP/IP connection on port 5555:
    adb tcpip 5555
    
  5. Disconnect the USB cable from the target device.
  6. Find the IP address of the Android device. For example, on a Nexus device, you can find the IP address at Settings > About tablet (or About phone ) > Status > IP address .
  7. Connect to the device by its IP address:
    adb connect device_ip_address:5555
    
  8. Confirm that your host computer is connected to the target device:
    $ adb devices
    List of devices attached
    device_ip_address:5555 device
    

Your device is now connected to adb .

If the adb connection to your device is lost:

  • Make sure that your host is still connected to the same Wi-Fi network as your Android device.
  • Reconnect by executing the adb connect step again.
  • If that doesn't work, reset your adb host:
    adb kill-server
    

    Then start over from the beginning.

Query for devices

Before issuing adb commands, it is helpful to know what device instances are connected to the adb server. Generate a list of attached devices using the devices command:

  adb devices -l
  

In response, adb prints this status information for each device:

  • Serial number: adb creates a string to uniquely identify the device by its port number. Here's an example serial number: emulator-5554
  • State: The connection state of the device can be one of the following:
    • offline : The device is not connected to adb or is not responding.
    • device : The device is connected to the adb server. Note that this state does not imply that the Android system is fully booted and operational, because the device connects to adb while the system is still booting. After boot-up, this is the normal operational state of a device.
    • no device : There is no device connected.
  • Description: If you include the -l option, the devices command tells you what the device is. This information is helpful when you have multiple devices connected so that you can tell them apart.

The following example shows the devices command and its output. There are three devices running. The first two lines in the list are emulators, and the third line is a hardware device that is attached to the computer.

$ adb devices
List of devices attached
emulator-5556 device product:sdk_google_phone_x86_64 model:Android_SDK_built_for_x86_64 device:generic_x86_64
emulator-5554 device product:sdk_google_phone_x86 model:Android_SDK_built_for_x86 device:generic_x86
0a388e93      device usb:1-1 product:razor model:Nexus_7 device:flo

Emulator not listed

The adb devices command has a corner-case command sequence that causes running emulators to not show up in the adb devices output even though the emulators are visible on your desktop. This happens when all of the following conditions are true:

  • The adb server is not running.
  • You use the emulator command with the -port or -ports option with an odd-numbered port value between 5554 and 5584.
  • The odd-numbered port you chose is not busy, so the port connection can be made at the specified port number — or, if it is busy, the emulator switches to another port that meets the requirements in 2.
  • You start the adb server after you start the emulator.

One way to avoid this situation is to let the emulator choose its own ports and to run no more than 16 emulators at once. Another way is to always start the adb server before you use the emulator command, as explained in the following examples.

Example 1: In the following command sequence, the adb devices command starts the adb server, but the list of devices does not appear.

Stop the adb server and enter the following commands in the order shown. For the AVD name, provide a valid AVD name from your system. To get a list of AVD names, type emulator -list-avds . The emulator command is in the android_sdk /tools directory.

$ adb kill-server
$ emulator -avd Nexus_6_API_25 -port 5555
$ adb devices

List of devices attached
* daemon not running. starting it now on port 5037 *
* daemon started successfully *

Example 2: In the following command sequence, adb devices displays the list of devices because the adb server was started first.

To see the emulator in the adb devices output, stop the adb server, and then start it again after using the emulator command and before using the adb devices command, as follows:

$ adb kill-server
$ emulator -avd Nexus_6_API_25 -port 5557
$ adb start-server
$ adb devices

List of devices attached
emulator-5557 device

For more information about emulator command-line options, see Command-Line startup options .

Send commands to a specific device

If multiple devices are running, you must specify the target device when you issue the adb command. To specify the target, follow these steps:

  1. Use the devices command to get the serial number of the target.
  2. Once you have the serial number, use the -s option with the adb commands to specify the serial number.
    1. If you're going to issue a lot of adb commands, you can set the $ANDROID_SERIAL environment variable to contain the serial number instead.
    2. If you use both -s and $ANDROID_SERIAL , -s overrides $ANDROID_SERIAL .

In the following example, the list of attached devices is obtained, and then the serial number of one of the devices is used to install the helloWorld.apk on that device:

$ adb devices
List of devices attached
emulator-5554 device
emulator-5555 device
0.0.0.0:6520  device

# To install on emulator-5555
$ adb -s emulator-5555 install helloWorld.apk
# To install on 0.0.0.0:6520
$ adb -s 0.0.0.0:6520 install helloWorld.apk

Note: If you issue a command without specifying a target device when multiple devices are available, adb displays an error "adb: more than one device/emulator".

If you have multiple devices available but only one is an emulator, use the -e option to send commands to the emulator. If there are multiple devices but only one hardware device attached, use the -d option to send commands to the hardware device.

Install an app

You can use adb to install an APK on an emulator or connected device with the install command:

adb install path_to_apk

You must use the -t option with the install command when you install a test APK. For more information, see -t .

To install multiple APKs use install-multiple . This is useful if you download all the APKs for a specific device for your app from the Play Console and want to install them on an emulator or physical device.

For more information about how to create an APK file that you can install on an emulator/device instance, see Build and run your app .

Note: If you are using Android Studio, you do not need to use adb directly to install your app on the emulator or device. Instead, Android Studio handles the packaging and installation of the app for you.

Set up port forwarding

Use the forward command to set up arbitrary port forwarding, which forwards requests on a specific host port to a different port on a device. The following example sets up forwarding of host port 6100 to device port 7100:

adb forward tcp:6100 tcp:7100

The following example sets up forwarding of host port 6100 to local:logd:

adb forward tcp:6100 local:logd

This could be useful if you are trying to detemine what is being sent to a given port on the device. All received data will be written to the system-logging daemon and displayed in the device logs.

Copy files to and from a device

Use the pull and push commands to copy files to and from a device. Unlike the install command, which only copies an APK file to a specific location, the pull and push commands let you copy arbitrary directories and files to any location in a device.

To copy a file or directory and its sub-directories from the device, do the following:

adb pull remote local

To copy a file or directory and its sub-directories to the device, do the following:

adb push local remote

Replace local and remote with the paths to the target files/directory on your development machine (local) and on the device (remote). به عنوان مثال:

adb push myfile.txt /sdcard/myfile.txt

Stop the adb server

In some cases, you might need to terminate the adb server process and then restart it to resolve the problem. For example, this could be the case if adb does not respond to a command.

To stop the adb server, use the adb kill-server command. You can then restart the server by issuing any other adb command.

Issue adb commands

Issue adb commands from a command line on your development machine or from a script using the following:

adb [-d | -e | -s serial_number] command

If there's only one emulator running or only one device connected, the adb command is sent to that device by default. If multiple emulators are running and/or multiple devices are attached, you need to use the -d , -e , or -s option to specify the target device to which the command should be directed.

You can see a detailed list of all supported adb commands using the following command:

adb --help

Issue shell commands

You can use the shell command to issue device commands through adb or to start an interactive shell. To issue a single command, use the shell command like this:

adb [-d |-e | -s serial_number] shell shell_command

To start an interactive shell on a device, use the shell command like this:

adb [-d | -e | -s serial_number] shell

To exit an interactive shell, press Control+D or type exit .

Android provides most of the usual Unix command-line tools. For a list of available tools, use the following command:

adb shell ls /system/bin

Help is available for most of the commands via the --help argument. Many of the shell commands are provided by toybox . General help applicable to all toybox commands is available via toybox --help .

With Android Platform Tools 23 and higher, adb handles arguments the same way that the ssh(1) command does. This change has fixed a lot of problems with command injection and makes it possible to safely execute commands that contain shell metacharacters , such as adb install Let\'sGo.apk . This change means that the interpretation of any command that contains shell metacharacters has also changed.

For example, adb shell setprop key ' two words ' is now an error, because the quotes are swallowed by the local shell, and the device sees adb shell setprop key two words . To make the command work, quote twice, once for the local shell and once for the remote shell, as you do with ssh(1) . For example, adb shell setprop key "' two words '" works because the local shell takes the outer level of quoting and the device still sees the inner level of quoting: setprop key 'two words' . Escaping is also an option, but quoting twice is usually easier.

See also Logcat command-line tool , which is useful for monitoring the system log.

Call activity manager

Within an adb shell, you can issue commands with the activity manager ( am ) tool to perform various system actions, such as start an activity, force-stop a process, broadcast an intent, modify the device screen properties, and more.

While in a shell, the am syntax is:

am command

You can also issue an activity manager command directly from adb without entering a remote shell. به عنوان مثال:

adb shell am start -a android.intent.action.VIEW

Table 1. Available activity manager commands

Command توضیحات
start [ options ] intent Start an Activity specified by intent .

See the Specification for intent arguments .

گزینه ها عبارتند از:

  • -D : Enable debugging.
  • -W : Wait for launch to complete.
  • --start-profiler file : Start profiler and send results to file .
  • -P file : Like --start-profiler , but profiling stops when the app goes idle.
  • -R count : Repeat the activity launch count times. Prior to each repeat, the top activity will be finished.
  • -S : Force stop the target app before starting the activity.
  • --opengl-trace : Enable tracing of OpenGL functions.
  • --user user_id | current : Specify which user to run as; if not specified, then run as the current user.
startservice [ options ] intent Start the Service specified by intent .

See the Specification for intent arguments .

گزینه ها عبارتند از:

  • --user user_id | current : Specify which user to run as. If not specified, then run as the current user.
force-stop package Force-stop everything associated with package .
kill [ options ] package Kill all processes associated with package . This command kills only processes that are safe to kill and that will not impact the user experience.

گزینه ها عبارتند از:

  • --user user_id | all | current : Specify which user's processes to kill. If not specified, then kill all users' processes.
kill-all Kill all background processes.
broadcast [ options ] intent Issue a broadcast intent.

See the Specification for intent arguments .

گزینه ها عبارتند از:

  • [--user user_id | all | current] : Specify which user to send to. If not specified, then send to all users.
instrument [ options ] component Start monitoring with an Instrumentation instance. Typically the target component is the form test_package / runner_class .

گزینه ها عبارتند از:

  • -r : Print raw results (otherwise decode report_key_streamresult ). Use with [-e perf true] to generate raw output for performance measurements.
  • -e name value : Set argument name to value . For test runners a common form is -e testrunner_flag value [, value ...] .
  • -p file : Write profiling data to file .
  • -w : Wait for instrumentation to finish before returning. Required for test runners.
  • --no-window-animation : Turn off window animations while running.
  • --user user_id | current : Specify which user instrumentation runs in. If not specified, run in the current user.
profile start process file Start profiler on process , write results to file .
profile stop process Stop profiler on process .
dumpheap [ options ] process file Dump the heap of process , write to file .

گزینه ها عبارتند از:

  • --user [ user_id | current] : When supplying a process name, specify the user of the process to dump. If not specified, the current user is used.
  • -b [| png | jpg | webp] : Dump bitmaps from graphics memory (API level 35 and above). Optionally specify the format to dump in (PNG by default).
  • -n : Dump native heap instead of managed heap.
set-debug-app [ options ] package Set app package to debug.

گزینه ها عبارتند از:

  • -w : Wait for debugger when app starts.
  • --persistent : Retain this value.
clear-debug-app Clear the package previous set for debugging with set-debug-app .
monitor [ options ] Start monitoring for crashes or ANRs.

گزینه ها عبارتند از:

  • --gdb : Start gdbserv on the given port at crash/ANR.
screen-compat {on | off} package Control screen compatibility mode of package .
display-size [reset | width x height ] Override device display size. This command is helpful for testing your app across different screen sizes by mimicking a small screen resolution using a device with a large screen, and vice versa.

مثال:
am display-size 1280x800

display-density dpi Override device display density. This command is helpful for testing your app across different screen densities by mimicking a high-density screen environment using a low-density screen, and vice versa.

مثال:
am display-density 480

to-uri intent Print the given intent specification as a URI.

See the Specification for intent arguments .

to-intent-uri intent Print the given intent specification as an intent: URI.

See the Specification for intent arguments .

Specification for intent arguments

For activity manager commands that take an intent argument, you can specify the intent with the following options:

Call package manager ( pm )

Within an adb shell, you can issue commands with the package manager ( pm ) tool to perform actions and queries on app packages installed on the device.

While in a shell, the pm syntax is:

pm command

You can also issue a package manager command directly from adb without entering a remote shell. به عنوان مثال:

adb shell pm uninstall com.example.MyApp

Table 2. Available package manager commands

Command توضیحات
list packages [ options ] filter Print all packages, optionally only those whose package name contains the text in filter .

Options:

  • -f : See associated file.
  • -d : Filter to only show disabled packages.
  • -e : Filter to only show enabled packages.
  • -s : Filter to only show system packages.
  • -3 : Filter to only show third-party packages.
  • -i : See the installer for the packages.
  • -u : Include uninstalled packages.
  • --user user_id : The user space to query.
list permission-groups Print all known permission groups.
list permissions [ options ] group Print all known permissions, optionally only those in group .

Options:

  • -g : Organize by group.
  • -f : Print all information.
  • -s : Short summary.
  • -d : Only list dangerous permissions.
  • -u : List only the permissions users will see.
list instrumentation [ options ] List all test packages.

Options:

  • -f : List the APK file for the test package.
  • target_package : List test packages for only this app.
list features Print all features of the system.
list libraries Print all the libraries supported by the current device.
list users Print all users on the system.
path package Print the path to the APK of the given package .
install [ options ] path Install a package, specified by path , to the system.

Options:

  • -r : Reinstall an existing app, keeping its data.
  • -t : Allow test APKs to be installed. Gradle generates a test APK when you have only run or debugged your app or have used the Android Studio Build > Build APK command. If the APK is built using a developer preview SDK, you must include the -t option with the install command if you are installing a test APK.
  • -i installer_package_name : Specify the installer package name.
  • --install-location location : Set the install location using one of the following values:
    • 0 : Use the default install location.
    • 1 : Install on internal device storage.
    • 2 : Install on external media.
  • -f : Install package on the internal system memory.
  • -d : Allow version code downgrade.
  • -g : Grant all permissions listed in the app manifest.
  • --fastdeploy : Quickly update an installed package by only updating the parts of the APK that changed.
  • --incremental : Installs enough of the APK to launch the app while streaming the remaining data in the background. To use this feature, you must sign the APK, create an APK Signature Scheme v4 file , and place this file in the same directory as the APK. This feature is only supported on certain devices. This option forces adb to use the feature or fail if it is not supported, with verbose information on why it failed. Append the --wait option to wait until the APK is fully installed before granting access to the APK.

    --no-incremental prevents adb from using this feature.

uninstall [ options ] package Removes a package from the system.

Options:

  • -k : Keep the data and cache directories after package removal.
  • --user user_id : Specifies the user for whom the package is removed.
  • --versionCode version_code : Only uninstalls if the app has the given version code.
clear package Delete all data associated with a package.
enable package_or_component Enable the given package or component (written as "package/class").
disable package_or_component Disable the given package or component (written as "package/class").
disable-user [ options ] package_or_component

Options:

  • --user user_id : The user to disable.
grant package_name permission Grant a permission to an app. On devices running Android 6.0 (API level 23) and higher, the permission can be any permission declared in the app manifest. On devices running Android 5.1 (API level 22) and lower, must be an optional permission defined by the app.
revoke package_name permission Revoke a permission from an app. On devices running Android 6.0 (API level 23) and higher, the permission can be any permission declared in the app manifest. On devices running Android 5.1 (API level 22) and lower, must be an optional permission defined by the app.
set-install-location location Change the default install location. Location values:
  • 0 : Auto: Let system decide the best location.
  • 1 : Internal: Install on internal device storage.
  • 2 : External: Install on external media.

Note: This is only intended for debugging. Using this can cause apps to break and other undesireable behavior.

get-install-location Returns the current install location. Return values:
  • 0 [auto] : Let system decide the best location
  • 1 [internal] : Install on internal device storage
  • 2 [external] : Install on external media
set-permission-enforced permission [true | false] Specify whether the given permission should be enforced.
trim-caches desired_free_space Trim cache files to reach the given free space.
create-user user_name Create a new user with the given user_name , printing the new user identifier of the user.
remove-user user_id Remove the user with the given user_id , deleting all data associated with that user
get-max-users Print the maximum number of users supported by the device.
get-app-links [ options ] [ package ]

Print the domain verification state for the given package , or for all packages if none is specified. State codes are defined as follows:

  • none : nothing has been recorded for this domain
  • verified : the domain has been successfully verified
  • approved : force-approved, usually through shell
  • denied : force-denied, usually through shell
  • migrated : preserved verification from a legacy response
  • restored : preserved verification from a user data restore
  • legacy_failure : rejected by a legacy verifier, unknown reason
  • system_configured : automatically approved by the device config
  • >= 1024 : custom error code, which is specific to the device verifier

گزینه ها عبارتند از:

  • --user user_id : include user selections. Include all domains, not just autoVerify ones.
reset-app-links [ options ] [ package ]

Reset domain verification state for the given package, or for all packages if none is specified.

  • package : the package to reset, or "all" to reset all packages

گزینه ها عبارتند از:

  • --user user_id : include user selections. Include all domains, not just autoVerify ones.
verify-app-links [ --re-verify ] [ package ]

Broadcast a verification request for the given package , or for all packages if none is specified. Only sends if the package has previously not recorded a response.

  • --re-verify : send even if the package has recorded a response
set-app-links [--package package ] state domains

Manually set the state of a domain for a package. The domain must be declared by the package as autoVerify for this to work. This command will not report a failure for domains that could not be applied.

  • --package package : the package to set, or "all" to set all packages
  • state : the code to set the domains to. Valid values are:
    • STATE_NO_RESPONSE (0) : reset as if no response was ever recorded.
    • STATE_SUCCESS (1) : treat domain as successfully verified by domain verification agent. Note that the domain verification agent can override this.
    • STATE_APPROVED (2) : treat domain as always approved, preventing the domain verification agent from changing it.
    • STATE_DENIED (3) : treat domain as always denied, preventing the domain verification agent from changing it.
  • domains : space-separated list of domains to change, or "all" to change every domain.
set-app-links-user-selection --user user_id [--package package ] enabled domains

Manually set the state of a host user selection for a package. The domain must be declared by the package for this to work. This command will not report a failure for domains that could not be applied.

  • --user user_id : the user to change selections for
  • --package package : the package to set
  • enabled : whether to approve the domain
  • domains : space-separated list of domains to change, or "all" to change every domain
set-app-links-user-selection --user user_id [--package package ] enabled domains

Manually set the state of a host user selection for a package. The domain must be declared by the package for this to work. This command will not report a failure for domains that could not be applied.

  • --user user_id : the user to change selections for
  • --package package : the package to set
  • enabled : whether to approve the domain
  • domains : space-separated list of domains to change, or "all" to change every domain
set-app-links-allowed --user user_id [--package package ] allowed

Toggle the auto-verified link-handling setting for a package.

  • --user user_id : the user to change selections for
  • --package package : the package to set, or "all" to set all packages; packages will be reset if no package is specified
  • allowed : true to allow the package to open auto-verified links, false to disable
get-app-link-owners --user user_id [--package package ] domains

Print the owners for a specific domain for a given user in low- to high-priority order.

  • --user user_id : the user to query for
  • --package package : optionally also print for all web domains declared by a package, or "all" to print all packages
  • domains : space-separated list of domains to query for

Call device policy manager ( dpm )

To help you develop and test your device management apps, issue commands to the device policy manager ( dpm ) tool. Use the tool to control the active admin app or change a policy's status data on the device.

While in a shell, the dpm syntax is:

dpm command

You can also issue a device policy manager command directly from adb without entering a remote shell:

adb shell dpm command

Table 3. Available device policy manager commands

Command توضیحات
set-active-admin [ options ] component Sets component as active admin.

گزینه ها عبارتند از:

  • --user user_id : Specify the target user. You can also pass --user current to select the current user.
set-profile-owner [ options ] component Set component as active admin and its package as profile owner for an existing user.

گزینه ها عبارتند از:

  • --user user_id : Specify the target user. You can also pass --user current to select the current user.
  • --name name : Specify the human-readable organization name.
set-device-owner [ options ] component Set component as active admin and its package as device owner.

گزینه ها عبارتند از:

  • --user user_id : Specify the target user. You can also pass --user current to select the current user.
  • --name name : Specify the human-readable organization name.
remove-active-admin [ options ] component Disable an active admin. The app must declare android:testOnly in the manifest. This command also removes device and profile owners.

گزینه ها عبارتند از:

  • --user user_id : Specify the target user. You can also pass --user current to select the current user.
clear-freeze-period-record Clear the device's record of previously set freeze periods for system OTA updates. This is useful to avoid the device scheduling restrictions when developing apps that manage freeze periods. See Manage system updates .

Supported on devices running Android 9.0 (API level 28) and higher.

force-network-logs Force the system to make any existing network logs ready for retrieval by a DPC. If there are connection or DNS logs available, the DPC receives the onNetworkLogsAvailable() callback. See Network activity logging .

This command is rate-limited. Supported on devices running Android 9.0 (API level 28) and higher.

force-security-logs Force the system to make any existing security logs available to the DPC. If there are logs available, the DPC receives the onSecurityLogsAvailable() callback. See Log enterprise device activity .

This command is rate-limited. Supported on devices running Android 9.0 (API level 28) and higher.

اسکرین شات بگیرید

The screencap command is a shell utility for taking a screenshot of a device display.

While in a shell, the screencap syntax is:

screencap filename

To use screencap from the command line, enter the following:

adb shell screencap /sdcard/screen.png

Here's an example screenshot session, using the adb shell to capture the screenshot and the pull command to download the file from the device:

$ adb shell
shell@ $ screencap /sdcard/screen.png
shell@ $ exit
$ adb pull /sdcard/screen.png

یک ویدیو ضبط کنید

The screenrecord command is a shell utility for recording the display of devices running Android 4.4 (API level 19) and higher. The utility records screen activity to an MPEG-4 file. You can use this file to create promotional or training videos or for debugging and testing.

In a shell, use the following syntax:

screenrecord [options] filename

To use screenrecord from the command line, enter the following:

adb shell screenrecord /sdcard/demo.mp4

Stop the screen recording by pressing Control+C. Otherwise, the recording stops automatically at three minutes or the time limit set by --time-limit .

To begin recording your device screen, run the screenrecord command to record the video. Then, run the pull command to download the video from the device to the host computer. Here's an example recording session:

$ adb shell
shell@ $ screenrecord --verbose /sdcard/demo.mp4
(press Control + C to stop)
shell@ $ exit
$ adb pull /sdcard/demo.mp4

The screenrecord utility can record at any supported resolution and bit rate you request, while retaining the aspect ratio of the device display. The utility records at the native display resolution and orientation by default, with a maximum length of three minutes.

Limitations of the screenrecord utility:

  • Audio is not recorded with the video file.
  • Video recording is not available for devices running Wear OS.
  • Some devices might not be able to record at their native display resolution. If you encounter problems with screen recording, try using a lower screen resolution.
  • Rotation of the screen during recording is not supported. If the screen does rotate during recording, some of the screen is cut off in the recording.

Table 4. screenrecord options

گزینه ها توضیحات
--help Display command syntax and options
--size width x height Set the video size: 1280x720 . The default value is the device's native display resolution (if supported), 1280x720 if not. For best results, use a size supported by your device's Advanced Video Coding (AVC) encoder.
--bit-rate rate Set the video bit rate for the video, in megabits per second. The default value is 20Mbps. You can increase the bit rate to improve video quality, but doing so results in larger movie files. The following example sets the recording bit rate to 6Mbps:
screenrecord --bit-rate 6000000 /sdcard/demo.mp4
--time-limit time Set the maximum recording time, in seconds. The default and maximum value is 180 (3 minutes).
--rotate Rotate the output 90 degrees. This feature is experimental.
--verbose Display log information on the command-line screen. If you do not set this option, the utility does not display any information while running.

Read ART profiles for apps

Starting in Android 7.0 (API level 24), the Android Runtime (ART) collects execution profiles for installed apps, which are used to optimize app performance. Examine the collected profiles to understand which methods are executed frequently and which classes are used during app startup.

Note: It is only possible to retrieve the execution profile filename if you have root access to the file system, for example, on an emulator.

To produce a text form of the profile information, use the following command:

adb shell cmd package dump-profiles package

To retrieve the file produced, use:

adb pull /data/misc/profman/package.prof.txt

Reset test devices

If you test your app across multiple test devices, it may be useful to reset your device between tests, for example, to remove user data and reset the test environment. You can perform a factory reset of a test device running Android 10 (API level 29) or higher using the testharness adb shell command, as shown:

adb shell cmd testharness enable

When restoring the device using testharness , the device automatically backs up the RSA key that allows debugging through the current workstation in a persistent location. That is, after the device is reset, the workstation can continue to debug and issue adb commands to the device without manually registering a new key.

Additionally, to help make it easier and more secure to keep testing your app, using the testharness to restore a device also changes the following device settings:

  • The device sets up certain system settings so that initial device setup wizards do not appear. That is, the device enters a state from which you can quickly install, debug, and test your app.
  • تنظیمات:
    • Disables lock screen.
    • Disables emergency alerts.
    • Disables auto-sync for accounts.
    • Disables automatic system updates.
  • دیگر:
    • Disables preinstalled security apps.

If your app needs to detect and adapt to the default settings of the testharness command, use the ActivityManager.isRunningInUserTestHarness() .

sqlite

sqlite3 starts the sqlite command-line program for examining SQLite databases. It includes commands such as .dump to print the contents of a table and .schema to print the SQL CREATE statement for an existing table. You can also execute SQLite commands from the command line, as shown:

$ adb -s emulator-5554 shell
$ sqlite3 /data/data/com.example.app/databases/rssitems.db
SQLite version 3.3.12
Enter ".help" for instructions

Note: It is only possible to access a SQLite database if you have root access to the file system, for example, on an emulator.

For more information, see the sqlite3 command line documentation .

adb USB backends

The adb server can interact with the USB stack through two backends. It can either use the native backend of the OS (Windows, Linux, or macOS) or it can use the libusb backend. Some features, such as attach , detach , and USB speed detection, are only available when using libusb backend.

You can choose a backend by using the ADB_LIBUSB environment variable. If it isn't set, adb uses its default backend. The default behavior varies among OS. Starting with ADB v34 , the liubusb backend is used by default on all OS except Windows, where the native backend is used by default. If ADB_LIBUSB is set, it determines whether the native backend or libusb is used. See the adb manual page for more information about adb environment variables.

adb mDNS backends

ADB can use the multicast DNS protocol to automatically connect the server and devices. The ADB server ships with two backends, Bonjour (Apple's mdnsResponder) and Openscreen.

The Bonjour backend needs a daemon to be running on the host machine. On macOS Apple's built-in daemon is always running, but on Windows and Linux, the user must make sure the mdnsd daemon is up and running. If the command adb mdns check returns an error, it is likely that ADB is using the Bonjour backend but there is no Bonjour daemon running.

The Openscreen backend does not need a daemon to be running on the machine. Support for the Openscreen backend on macOS starts at ADB v35. Windows and Linux are supported as of ADB v34.

By default ADB uses the Bonjour backend. This behavior can be changed using the environment variable ADB_MDNS_OPENSCREEN (set to 1 or 0 ). See the ADB manual page for further details.