### Quick Start: Initialize ADB and Basic Device/App Operations Source: https://github.com/appium/appium-adb/blob/master/_autodocs/index.md Demonstrates how to create an ADB instance, retrieve API level and connected devices, install and start an application, and uninstall an application. ```typescript import { ADB } from 'appium-adb'; // Create an ADB instance const adb = await ADB.createADB(); // Basic device interaction const apiLevel = await adb.getApiLevel(); const devices = await adb.getConnectedDevices(); // App management await adb.install('/path/to/app.apk'); await adb.startApp({pkg: 'com.example.app', activity: '.MainActivity'}); // Clean up await adb.uninstallApk('com.example.app'); ``` -------------------------------- ### Install and Launch App with Permissions Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Installs an app, grants all its permissions, resolves its launchable activity, and then starts the app. ```typescript // Install and start app with permissions const apkPath = '/path/to/app.apk'; await adb.install(apkPath); await adb.grantAllPermissions('com.example.app'); const activity = await adb.resolveLaunchableActivity('com.example.app'); await adb.startApp({ pkg: 'com.example.app', activity }); ``` -------------------------------- ### Install and Launch Application Source: https://github.com/appium/appium-adb/blob/master/_autodocs/DOCUMENTATION_INDEX.md Install an APK, grant all necessary permissions, resolve the launchable activity, and then start the application. Useful for setting up and running an app for testing. ```typescript await adb.install('/path/to/app.apk'); await adb.grantAllPermissions('com.example.app'); const activity = await adb.resolveLaunchableActivity('com.example.app'); await adb.startApp({ pkg: 'com.example.app', activity }); ``` -------------------------------- ### Appium ADB Setup and Basic Operations Source: https://github.com/appium/appium-adb/blob/master/_autodocs/README.md Demonstrates how to initialize the ADB class, install an application, grant permissions, launch an app, retrieve device information, perform file operations, and uninstall an APK. ```typescript import { ADB } from 'appium-adb'; // Setup const adb = await ADB.createADB({ sdkRoot: '/path/to/android-sdk' }); // Install app await adb.install('/path/to/app.apk'); // Grant permissions await adb.grantAllPermissions('com.example.app'); // Launch app const activity = await adb.resolveLaunchableActivity('com.example.app'); await adb.startApp({ pkg: 'com.example.app', activity }); // Get device info const model = await adb.getModel(); const version = await adb.getPlatformVersion(); // File operations await adb.push('local/file.txt', '/sdcard/file.txt'); await adb.pull('/sdcard/log.txt', './logs/'); // Cleanup await adb.uninstallApk('com.example.app'); ``` -------------------------------- ### Command-Specific Timeout Examples Source: https://github.com/appium/appium-adb/blob/master/_autodocs/configuration.md Illustrates setting command-specific timeouts for methods like `install`, `launchAVD`, and `waitForDevice`. Note that `waitForDevice` accepts timeout in seconds. ```typescript await adb.install('/app.apk', { timeout: 60000 }); await adb.launchAVD('test_avd', { launchTimeout: 120000 }); await adb.waitForDevice(30); // timeout in seconds ``` -------------------------------- ### Configure App Installation Options Source: https://github.com/appium/appium-adb/blob/master/_autodocs/errors.md Install applications using specific options like `replace: true` to overwrite existing installations or `grantPermissions: true` to automatically grant necessary permissions. This helps avoid installation failures. ```typescript // Use install options await adb.install('/path/to/app.apk', { timeout: 60000, replace: true, grantPermissions: true }); // Or check first const installed = await adb.isAppInstalled('com.example.app'); if (installed) { await adb.uninstallApk('com.example.app'); } ``` -------------------------------- ### Start App with Options Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Starts an application on the device. Requires start options including package name, activity, and optional parameters like stopApp, waitDuration, user, and waitForLaunch. ```typescript async startApp(opts: StartAppOptions): Promise ``` ```typescript await adb.startApp({ pkg: 'com.example.app', activity: '.MainActivity', stopApp: true }); ``` -------------------------------- ### Create ADB Instance with Defaults Source: https://github.com/appium/appium-adb/blob/master/_autodocs/configuration.md Instantiate an ADB object using default settings, which automatically detects the Android SDK path. This is the simplest way to get started. ```typescript import { ADB } from 'appium-adb'; // Use defaults with auto-detected SDK const adb = await ADB.createADB(); ``` -------------------------------- ### Install appium-adb Source: https://github.com/appium/appium-adb/blob/master/README.md Install the appium-adb package using npm. ```bash npm install appium-adb ``` -------------------------------- ### Get Process IDs by Name using appium-adb Source: https://github.com/appium/appium-adb/blob/master/README.md Example of creating an ADB instance and retrieving process IDs by their name. Ensure appium-adb is installed and imported. ```javascript import { ADB } from 'appium-adb'; const adb = await ADB.createADB(); console.log(await adb.getPIDsByName('com.android.phone')); ``` -------------------------------- ### Install APK with Options Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Install an APK file onto the device, with options to grant permissions and set a timeout. ```typescript await adb.install('/path/to/app.apk', { grantPermissions: true, timeout: 30000 }); ``` -------------------------------- ### InstallOptions Interface Source: https://github.com/appium/appium-adb/blob/master/_autodocs/types.md Options for installing a single APK. Includes settings for timeout, test packages, SD card installation, permissions, and replacement behavior. ```typescript interface InstallOptions { timeout?: number; timeoutCapName?: string; allowTestPackages?: boolean; useSdcard?: boolean; grantPermissions?: boolean; replace?: boolean; noIncremental?: boolean; } ``` -------------------------------- ### Basic Try-Catch for App Installation Source: https://github.com/appium/appium-adb/blob/master/_autodocs/errors.md Demonstrates a basic try-catch block for handling potential errors during app installation, with specific handling for 'device not found' errors. ```typescript try { await adb.install('/app.apk'); } catch (error) { console.error('Installation failed:', error.message); if (error.message.includes('device not found')) { // Handle device error } } ``` -------------------------------- ### Install or Upgrade APK Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Intelligently installs or upgrades an application. Use this for a streamlined installation process that handles both new installs and updates. ```typescript const result = await adb.installOrUpgrade( '/path/to/app.apk', 'com.example.app', {enforceCurrentBuild: true} ); console.log(`Was uninstalled: ${result.wasUninstalled}`); console.log(`Previous state: ${result.appState}`); ``` -------------------------------- ### App Install State Constants Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Defines constants for various application installation states. Used to determine the current installation status before performing actions like installing or updating an app. ```typescript const APP_INSTALL_STATE: StringRecord = { UNKNOWN: 'unknown', NOT_INSTALLED: 'notInstalled', NEWER_VERSION_INSTALLED: 'newerVersionInstalled', SAME_VERSION_INSTALLED: 'sameVersionInstalled', OLDER_VERSION_INSTALLED: 'olderVersionInstalled' }; ``` ```typescript const state = await adb.getApplicationInstallState(apkPath, 'com.example.app'); if (state === adb.APP_INSTALL_STATE.NOT_INSTALLED) { await adb.install(apkPath); } ``` -------------------------------- ### Smart APK Installation Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Installs or upgrades an APK file, with optional custom signing using a provided keystore configuration. It intelligently handles installation with options like enforcing the current build and granting permissions. ```typescript async function smartInstall( apkPath: string, keystoreConfig?: ApkCreationOptions ): Promise { const info = await adb.getApkInfo(apkPath); // Determine if signing needed if (keystoreConfig) { const signed = await adb.signWithCustomCert( apkPath, keystoreConfig.keystore!, keystoreConfig.keystorePassword!, keystoreConfig.keyAlias!, keystoreConfig.keyPassword! ); apkPath = signed; } // Install with smart options await adb.installOrUpgrade(apkPath, info.name!, { enforceCurrentBuild: true, grantPermissions: true, timeout: 60000 }); } ``` -------------------------------- ### Install APK from Device Path Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Installs an APK that is already present on the device. Useful for installing pre-downloaded or system APKs. ```typescript await adb.installFromDevicePath('/sdcard/app.apk'); ``` -------------------------------- ### InstallMultipleApksOptions Interface Source: https://github.com/appium/appium-adb/blob/master/_autodocs/types.md Configuration options for installing multiple APKs simultaneously. Includes settings for timeout, test packages, SD card, permissions, and partial installation. ```typescript interface InstallMultipleApksOptions { timeout?: number | string; timeoutCapName?: string; allowTestPackages?: boolean; useSdcard?: boolean; grantPermissions?: boolean; partialInstall?: boolean; } ``` -------------------------------- ### Installation State Type Source: https://github.com/appium/appium-adb/blob/master/_autodocs/types.md Defines the possible states for an application's installation on a device. ```typescript type InstallState = | 'unknown' | 'notInstalled' | 'newerVersionInstalled' | 'sameVersionInstalled' | 'olderVersionInstalled'; ``` -------------------------------- ### getPackageInfo Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Gets package information for a given package name, including name, version codes, and installation status. ```APIDOC ## getPackageInfo ### Description Gets package information. ### Method `async` ### Parameters #### Path Parameters - **pkg** (string) - Required - Package name ### Response #### Success Response - **Promise** - An object containing app information: {name, versionCode, versionName, isInstalled} ``` -------------------------------- ### Start App with Activity Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Launches an application on the device, specifying the package name and activity. Can force-stop the app before starting and retry with a dot prefix if the initial attempt fails. ```typescript // Start with activity await adb.startApp({ pkg: 'com.example.app', activity: '.MainActivity', stopApp: true }); ``` -------------------------------- ### APP_INSTALL_STATE Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Constants for installation state detection, used to check the installation status of an application before performing actions like installation. ```APIDOC ## APP_INSTALL_STATE ### Description Constants for installation state detection. ### Usage ```typescript const state = await adb.getApplicationInstallState(apkPath, 'com.example.app'); if (state === adb.APP_INSTALL_STATE.NOT_INSTALLED) { await adb.install(apkPath); } ``` ``` -------------------------------- ### Bundle Installation with Device Spec Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md A workflow for installing an Android App Bundle (.aab) using bundletool. It initializes bundletool, generates a device-specific APK set, and then installs the generated APKs. ```typescript async function installBundle(bundlePath: string): Promise { // Initialize bundletool await adb.initBundletool(); // Get device spec const specPath = '/tmp/device-spec.json'; await adb.getDeviceSpec(specPath); // Generate APKs for device const apksPath = '/tmp/app.apks'; await adb.execBundletool([ 'build-apks', `--bundle=${bundlePath}`, `--output=${apksPath}`, `--device-spec=${specPath}` ]); // Install await adb.installApks(apksPath, {grantPermissions: true}); } ``` -------------------------------- ### ADB.createADB Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Asynchronously creates and initializes a new ADB instance, including locating the ADB executable and starting the ADB server. ```APIDOC ## Static Methods ### createADB ```typescript static async createADB(opts: ADBOptions = {}): Promise ``` ### Description Creates and initializes a new ADB instance. This method: - Instantiates the ADB class - Resolves the SDK root directory - Locates the ADB executable - Starts the ADB server (unless `suppressKillServer` is true) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | opts | ADBOptions | {} | Configuration options | ### Returns Promise - Initialized ADB instance ### Request Example ```typescript const adb = await ADB.createADB({ sdkRoot: '/path/to/android-sdk', udid: 'emulator-5554' }); ``` ``` -------------------------------- ### Build and Deploy Workflow Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md A common workflow for building and deploying an Android application. It checks the installation state, signs the APK with custom certificates, and then installs it on the device. ```typescript async function buildAndDeploy( apkPath: string, pkg: string, keystoreConfig: ApkCreationOptions ): Promise { // Check if newer version is available const state = await adb.getApplicationInstallState(apkPath, pkg); if (state === adb.APP_INSTALL_STATE.NOT_INSTALLED) { console.log('Installing fresh...'); } else if (state === adb.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED) { console.log('Upgrading to newer version...'); } else { console.log('Same version already installed, skipping'); return; } // Sign APK const signedApk = await adb.signWithCustomCert( apkPath, keystoreConfig.keystore!, keystoreConfig.keystorePassword!, keystoreConfig.keyAlias!, keystoreConfig.keyPassword! ); // Install await adb.install(signedApk, { replace: true, grantPermissions: true }); console.log('Deployment successful'); } ``` -------------------------------- ### StartAppOptions Interface Source: https://github.com/appium/appium-adb/blob/master/_autodocs/types.md Defines the configuration options for starting an application. Use this to specify package name, activity, action, and various waiting or retry parameters. ```typescript interface StartAppOptions { pkg: string; activity?: string; action?: string; retry?: boolean; stopApp?: boolean; waitPkg?: string; waitActivity?: string; waitDuration?: number; user?: string | number; waitForLaunch?: boolean; category?: string; flags?: string; optionalIntentArguments?: string; } ``` -------------------------------- ### Install APKs Bundle Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Installs an .apks bundle, which is a compressed archive containing multiple APKs. Useful for deploying apps with dynamic feature modules. ```typescript async installApks(bundlePath: string, opts?: InstallApksOptions): Promise ``` ```typescript await adb.installApks('/path/to/app.apks', { timeout: 120000, grantPermissions: true }); ``` -------------------------------- ### installMultipleApks Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Installs multiple APKs in a single operation. This is useful for installing an application along with its required split APKs. ```APIDOC ## installMultipleApks ### Description Installs multiple APKs in one operation. This method is efficient for deploying applications that consist of a base APK and one or more split APKs. ### Method `async installMultipleApks(apks: string[], opts?: InstallMultipleApksOptions): Promise` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **apks** (string[]) - Required - Array of paths to the APK files to be installed. * **opts** (InstallMultipleApksOptions) - Optional - Options for the installation process, such as granting permissions. ### Response #### Success Response (200) * **Promise** - A promise that resolves with the installation output string. ### Request Example ```typescript const apks = [ '/path/to/base.apk', '/path/to/split_hdpi.apk', '/path/to/split_en.apk' ]; await adb.installMultipleApks(apks, {grantPermissions: true}); ``` ``` -------------------------------- ### getApplicationInstallState Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Determines the installation state of an application on the device, comparing it against a given APK. It returns one of several predefined states indicating whether the app is installed, and if so, whether the installed version is newer, the same, or older. ```APIDOC ## getApplicationInstallState ### Description Determines if app is installed and version comparison. ### Method `async getApplicationInstallState(appPath: string, pkg: string): Promise` ### Parameters #### Path Parameters - **appPath** (string) - Required - Path to the APK to compare against - **pkg** (string) - Required - Package name of the application ### Response #### Success Response (200) - **Promise** - One of: - 'unknown' - 'notInstalled' - 'newerVersionInstalled' - 'sameVersionInstalled' - 'olderVersionInstalled' ### Example ```typescript const state = await adb.getApplicationInstallState( '/path/to/app.apk', 'com.example.app' ); if (state === adb.APP_INSTALL_STATE.NOT_INSTALLED) { console.log('App not installed, installing...'); await adb.install('/path/to/app.apk'); } else if (state === adb.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED) { console.log('Newer version available, upgrading...'); await adb.install('/path/to/app.apk', {replace: true}); } ``` ``` -------------------------------- ### startUri Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Starts an app via an intent URI, optionally specifying the package to use for opening the URI. ```APIDOC ## startUri ### Description Starts an app via intent URI. ### Method async ### Parameters #### Path Parameters - **uri** (string) - Required - Intent URI - **pkg** (string) - Optional - Package to start (optional) - **opts.waitForLaunch** (boolean) - Optional - Wait for activity (default true) ### Request Example ```typescript // Open a URL await adb.startUri('https://appium.io'); // Open with specific app await adb.startUri('https://example.com', 'com.android.chrome'); ``` ``` -------------------------------- ### Create ADB Instance Source: https://github.com/appium/appium-adb/blob/master/_autodocs/DOCUMENTATION_INDEX.md Instantiate the ADB class with the path to your Android SDK root. This is the initial setup required before using other ADB commands. ```typescript import { ADB } from 'appium-adb'; const adb = await ADB.createADB({ sdkRoot: '/path/to/android-sdk' }); ``` -------------------------------- ### Custom App APK Installation Error Handling Source: https://github.com/appium/appium-adb/blob/master/_autodocs/errors.md Wraps the adb.install command to provide more specific error messages for common installation failures like invalid APK or insufficient storage. Throws custom errors based on the original error message. ```typescript async function installApp(apkPath: string): Promise { try { await adb.install(apkPath); } catch (error) { const msg = (error as Error).message; if (msg.includes('INSTALL_FAILED_INVALID_APK')) { throw new Error('APK is corrupted or invalid'); } if (msg.includes('INSTALL_FAILED_INSUFFICIENT_STORAGE')) { throw new Error('Device storage full'); } if (msg.includes('timeout')) { throw new Error('Installation timeout - device may be slow'); } throw error; } } ``` -------------------------------- ### Start App and Wait for Activity Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Starts an application and waits for a specific activity to become active. Includes options for package, activity, wait activity, and duration. ```typescript // Start and wait for specific activity await adb.startApp({ pkg: 'com.example.app', activity: '.SplashActivity', waitActivity: '.MainActivity', waitDuration: 15000 }); ``` -------------------------------- ### List Installed Packages Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Retrieves a list of all installed packages on the device, including their package name and version code. Useful for inventory or pre-installation checks. ```typescript async listInstalledPackages(opts?: ListInstalledPackagesOptions): Promise ``` ```typescript const packages = await adb.listInstalledPackages(); packages.forEach(p => { console.log(`${p.appPackage}: v${p.versionCode}`); }); ``` -------------------------------- ### App Info Interface Source: https://github.com/appium/appium-adb/blob/master/_autodocs/types.md Represents information about an installed application. Includes its name, version code, version name, and installation status. ```typescript interface AppInfo { name: string; versionCode?: number; versionName?: string; isInstalled?: boolean; } ``` -------------------------------- ### Install Multiple APKs Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Installs multiple APKs in a single operation. Use when you need to deploy an app with multiple split APKs. ```typescript async installMultipleApks( apks: string[], opts?: InstallMultipleApksOptions ): Promise ``` ```typescript const apks = [ '/path/to/base.apk', '/path/to/split_hdpi.apk', '/path/to/split_en.apk' ]; await adb.installMultipleApks(apks, {grantPermissions: true}); ``` -------------------------------- ### Check Application Install State Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Checks the installation state of an app against a given path and package name. Returns one of the APP_INSTALL_STATE values. ```typescript const state = await adb.getApplicationInstallState('/app.apk', 'com.example.app'); switch (state) { case adb.APP_INSTALL_STATE.NOT_INSTALLED: console.log('App not installed, installing...'); break; case adb.APP_INSTALL_STATE.SAME_VERSION_INSTALLED: console.log('Same version already installed'); break; case adb.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED: console.log('Newer version, upgrading...'); break; } ``` -------------------------------- ### Starting App with Resolved Activity Source: https://github.com/appium/appium-adb/blob/master/_autodocs/errors.md Automatically resolves the launchable activity for a package and starts the app. Alternatively, provides both package and activity names. ```typescript const activity = await adb.resolveLaunchableActivity('com.example.app'); await adb.startApp({pkg: 'com.example.app', activity}); await adb.startApp({ pkg: 'com.example.app', activity: 'com.example.app.MainActivity' }); ``` -------------------------------- ### Check Application Install State Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Determines if an app is installed and compares its version against a given APK. This helps in deciding whether to install or upgrade. ```typescript const state = await adb.getApplicationInstallState( '/path/to/app.apk', 'com.example.app' ); if (state === adb.APP_INSTALL_STATE.NOT_INSTALLED) { console.log('App not installed, installing...'); await adb.install('/path/to/app.apk'); } else if (state === adb.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED) { console.log('Newer version available, upgrading...'); await adb.install('/path/to/app.apk', {replace: true}); } ``` -------------------------------- ### installOrUpgrade Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Intelligently installs or upgrades an application based on its current state on the device. It handles both new installations and updates. ```APIDOC ## installOrUpgrade ### Description Intelligently installs or upgrades an app. ### Method `async installOrUpgrade(apkPath: string, pkg: string, opts?: InstallOrUpgradeOptions): Promise` ### Parameters #### Path Parameters - **apkPath** (string) - Required - APK file path - **pkg** (string) - Required - Package name #### Query Parameters - **opts** (InstallOrUpgradeOptions) - Optional - Options ### Response #### Success Response (200) - **Promise** - {wasUninstalled, appState} ### Example ```typescript const result = await adb.installOrUpgrade( '/path/to/app.apk', 'com.example.app', {enforceCurrentBuild: true} ); console.log(`Was uninstalled: ${result.wasUninstalled}`); console.log(`Previous state: ${result.appState}`); ``` ``` -------------------------------- ### Check if App is Installed Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Verifies if a specified application package is installed on the device. Accepts package name and optional installation check options. ```typescript async isAppInstalled(pkg: string, opts?: IsAppInstalledOptions): Promise ``` -------------------------------- ### installFromDevicePath Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Installs an APK that is already present on the device. This is useful if the APK has been transferred to the device through other means. ```APIDOC ## installFromDevicePath ### Description Installs an APK that's already on the device. ### Method `async installFromDevicePath(apkPath: string, opts?: InstallOptions): Promise` ### Parameters #### Path Parameters - **apkPath** (string) - Required - Device APK path #### Query Parameters - **opts** (InstallOptions) - Optional - Installation options ### Response #### Success Response (200) - **Promise** - Installation output ### Example ```typescript await adb.installFromDevicePath('/sdcard/app.apk'); ``` ``` -------------------------------- ### Start App with Wait Conditions Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Starts an application and waits for a specific activity to become focused, with a configurable timeout. Ensures the desired screen or component is ready before proceeding. ```typescript // With wait conditions await adb.startApp({ pkg: 'com.example.app', activity: '.SplashActivity', waitActivity: '.MainActivity', waitDuration: 10000 }); ``` -------------------------------- ### Local Development ADB Configuration Source: https://github.com/appium/appium-adb/blob/master/_autodocs/configuration.md Example configuration for setting up an ADB instance for local development. It specifies the SDK root and a custom command execution timeout. ```typescript const adb = await ADB.createADB({ sdkRoot: '/Users/user/Library/Android/sdk', // macOS // or process.env.ANDROID_HOME, adbExecTimeout: 30000 }); ``` -------------------------------- ### getApplicationInstallState Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Checks the installation state of an app on the device. Returns one of the APP_INSTALL_STATE values. ```APIDOC ## getApplicationInstallState ### Description Checks the installation state of an app. ### Method `async` ### Parameters #### Path Parameters - **appPath** (string) - Required - Path to the APK file - **pkg** (string) - Required - Package name ### Response #### Success Response - **Promise** - One of APP_INSTALL_STATE values ``` -------------------------------- ### InstallApksOptions Interface Source: https://github.com/appium/appium-adb/blob/master/_autodocs/types.md Options specifically for installing an .apks bundle. Configurable with timeout, test packages, and permission granting. ```typescript interface InstallApksOptions { timeout?: number | string; timeoutCapName?: string; allowTestPackages?: boolean; grantPermissions?: boolean; } ``` -------------------------------- ### isAppInstalled Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Checks if a specified application package is installed on the Android device. It accepts the package name and optional installation options, returning a boolean indicating whether the app is installed. ```APIDOC ## isAppInstalled ### Description Checks if an app is installed. ### Method async ### Parameters #### Path Parameters - **pkg** (string) - Required - Package name - **opts** (IsAppInstalledOptions) - Optional - Options including user ID ### Returns Promise ``` -------------------------------- ### InstallOrUpgradeResult Interface Source: https://github.com/appium/appium-adb/blob/master/_autodocs/types.md Represents the result of an install or upgrade operation. Indicates if the app was uninstalled first and its state before installation. ```typescript interface InstallOrUpgradeResult { wasUninstalled: boolean; appState: InstallState; } ``` -------------------------------- ### IsAppInstalledOptions Interface Source: https://github.com/appium/appium-adb/blob/master/_autodocs/types.md Options for checking if an app is installed. Allows specifying a user ID. ```typescript interface IsAppInstalledOptions { user?: string; } ``` -------------------------------- ### Start App with Action Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Initiates an application using an intent action, without requiring a specific activity. Useful for launching apps that respond to general actions like viewing a URL. ```typescript // Start with action (no activity required) await adb.startApp({ pkg: 'com.android.chrome', action: 'android.intent.action.VIEW' }); ``` -------------------------------- ### Check MITM Certificate Installation Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/system-commands.md Verifies whether a Man-in-the-Middle certificate is currently installed on the device. ```typescript async isMitmCertificateInstalled(): Promise ``` -------------------------------- ### adb.install Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Installs an APK file onto the Android device, with options for granting permissions and setting timeouts. ```APIDOC ## App Commands ### installApk / install ```typescript async install(apkPath: string, opts?: InstallOptions): Promise ``` ### Description Installs an APK on the device. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Description | |-----------|------|-------------| | apkPath | string | Local path to APK file | | opts | InstallOptions | Installation options | ### Returns Promise - Installation output ### Request Example ```typescript await adb.install('/path/to/app.apk', { grantPermissions: true, timeout: 30000 }); ``` ``` -------------------------------- ### Initializing Bundletool and Handling Not Found Errors Source: https://github.com/appium/appium-adb/blob/master/_autodocs/errors.md Initializes the bundletool, providing instructions for installation and PATH configuration. Includes a try-catch block to handle cases where bundletool is not available. ```bash # Install bundletool # Download from https://github.com/google/bundletool export PATH="$PATH:$HOME/bundletool" ``` ```typescript try { await adb.initBundletool(); } catch (e) { console.error('Bundletool not available'); } ``` -------------------------------- ### startApp Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Starts an application on the device. Supports various options to control the launch process, including activity, action, and wait conditions. ```APIDOC ## startApp ### Description Starts an application on the device. ### Method async ### Parameters #### Path Parameters - **opts.pkg** (string) - Required - Package name - **opts.activity** (string) - Optional - Activity name (full or with leading dot) - **opts.action** (string) - Optional - Intent action (e.g., android.intent.action.MAIN) - **opts.stopApp** (boolean) - Optional - Default: true - Force-stop before starting - **opts.retry** (boolean) - Optional - Default: true - Retry with dot prefix if fails - **opts.waitPkg** (string) - Optional - Default: opts.pkg - Package to wait for on focus - **opts.waitActivity** (string) - Optional - Default: opts.activity - Activity to wait for - **opts.waitDuration** (number) - Optional - Default: 5000 - Wait timeout (ms) - **opts.user** (string | number) - Optional - User profile ID - **opts.waitForLaunch** (boolean) - Optional - Default: true - Wait for activity to respond - **opts.category** (string) - Optional - Intent category - **opts.flags** (string) - Optional - Intent flags - **opts.optionalIntentArguments** (string) - Optional - Extra intent arguments ### Request Example ```typescript // Start with activity await adb.startApp({ pkg: 'com.example.app', activity: '.MainActivity', stopApp: true }); // Start with action (no activity required) await adb.startApp({ pkg: 'com.android.chrome', action: 'android.intent.action.VIEW' }); // With wait conditions await adb.startApp({ pkg: 'com.example.app', activity: '.SplashActivity', waitActivity: '.MainActivity', waitDuration: 10000 }); ``` ``` -------------------------------- ### Option Merging Example Source: https://github.com/appium/appium-adb/blob/master/_autodocs/configuration.md Demonstrates how provided options override default settings and how properties are deeply merged when creating an ADB instance. Constructor validates and normalizes values. ```typescript // Example: baseOptions get merged with overrides const baseOptions = { sdkRoot: '/sdk', adbPort: 5037 }; const overrides = { udid: 'device-1' }; const adb = new ADB(Object.assign({}, baseOptions, overrides)); ``` -------------------------------- ### Install MITM Certificate Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/system-commands.md Installs a Man-in-the-Middle certificate required for network traffic interception during testing. ```typescript async installMitmCertificate(certPath: string): Promise ``` -------------------------------- ### StartUriOptions Interface Source: https://github.com/appium/appium-adb/blob/master/_autodocs/types.md Configuration options for starting a URI. Primarily used to control whether to wait for the activity to return after launching the URI. ```typescript interface StartUriOptions { waitForLaunch?: boolean; } ``` -------------------------------- ### getEmuVersionInfo Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/emulator-commands.md Gets emulator version and build information. ```APIDOC ## getEmuVersionInfo ### Description Gets emulator version and build information. ### Method async ### Endpoint N/A ### Parameters None ### Response #### Success Response - **return value** (EmuVersionInfo) - {revision, buildId} ### Response Example ```json { "example": { "revision": "3", "buildId": "google/sdk_google_phone_x86/generic_x86:11/RS2A.211022.001/7758249:user/release-keys" } } ``` ``` -------------------------------- ### installApks Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Installs an .apks bundle, which is a format used by bundletool to generate APKs tailored for specific device configurations. ```APIDOC ## installApks ### Description Installs an .apks bundle. This method is typically used after generating a set of APKs for a specific device using bundletool. ### Method `async installApks(bundlePath: string, opts?: InstallApksOptions): Promise` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **bundlePath** (string) - Required - The file path to the .apks bundle. * **opts** (InstallApksOptions) - Optional - Options for the installation process, such as setting a timeout or granting permissions. ### Response #### Success Response (200) * **Promise** - A promise that resolves with the installation output string. ### Request Example ```typescript await adb.installApks('/path/to/app.apks', { timeout: 120000, grantPermissions: true }); ``` ``` -------------------------------- ### ListInstalledPackagesOptions Interface Source: https://github.com/appium/appium-adb/blob/master/_autodocs/types.md Options for listing installed packages. Specify a user ID to filter results. ```typescript interface ListInstalledPackagesOptions { user?: string; } ``` -------------------------------- ### Get Target SDK Version of Installed App Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Retrieves the target SDK version of an already installed application on the device using its package name. Returns undefined if the information is unavailable. ```typescript async targetSdkVersionUsingPKG(pkg: string): Promise ``` -------------------------------- ### InstallOrUpgradeOptions Interface Source: https://github.com/appium/appium-adb/blob/master/_autodocs/types.md Options for installing or upgrading an application. Supports configuration for timeout, test packages, SD card, permissions, and enforcing the current build. ```typescript interface InstallOrUpgradeOptions { timeout?: number; allowTestPackages?: boolean; useSdcard?: boolean; grantPermissions?: boolean; enforceCurrentBuild?: boolean; } ``` -------------------------------- ### CI/CD Environment ADB Configuration Source: https://github.com/appium/appium-adb/blob/master/_autodocs/configuration.md Example configuration for an ADB instance in a CI/CD environment. It uses environment variables for SDK path and enables options like suppressing server killing and allowing offline devices. ```typescript const adb = await ADB.createADB({ sdkRoot: process.env.ANDROID_SDK_ROOT || process.env.ANDROID_HOME, suppressKillServer: true, allowOfflineDevices: true, adbExecTimeout: 60000 }); ``` -------------------------------- ### Get APK Information Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Extracts package information, including name, version code, and version name, from an APK file. Also indicates if the app is currently installed. ```typescript const info = await adb.getApkInfo('/path/to/app.apk'); console.log(`Package: ${info.name}`); console.log(`Version: ${info.versionName} (${info.versionCode})`); console.log(`Installed: ${info.isInstalled}`); ``` -------------------------------- ### Get Binary from System PATH Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/system-commands.md Searches the system's PATH environment variable for a specified binary. ```typescript async getBinaryFromPath(binaryName: string): Promise ``` -------------------------------- ### Generate Device Specification for Bundle Installation Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/apk-operations.md Generates a device specification file required for installing Android App Bundles. This file describes the device's capabilities and configuration. ```typescript async getDeviceSpec(outputPath: string): Promise ``` -------------------------------- ### ListInstalledPackagesResult Interface Source: https://github.com/appium/appium-adb/blob/master/_autodocs/types.md Represents information about an installed package. Includes the package name and optionally the version code. ```typescript interface ListInstalledPackagesResult { appPackage: string; versionCode: string | null; } ``` -------------------------------- ### Start App via Intent URI Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Launches an application by resolving an intent URI. Optionally specifies the package to handle the URI and whether to wait for the activity to launch. ```typescript // Open a URL await adb.startUri('https://appium.io'); ``` ```typescript // Open with specific app await adb.startUri('https://example.com', 'com.android.chrome'); ``` -------------------------------- ### Setup Bidirectional Port Forwarding Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/file-network-commands.md Configures both forward (local to device) and reverse (device to local) port forwarding simultaneously. This enables communication in both directions. ```typescript async function setupBidirectionalForwarding(): Promise { // Local app server → Device (reverse) await adb.reversePort(8080, 8080); // Device server → Local machine (forward) await adb.forwardPort(3000, 3000); console.log('Bidirectional forwarding configured'); } ``` -------------------------------- ### Setup Port Forwarding for Testing Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/file-network-commands.md Sets up a port forward from a local port to an application server port on the device. This is commonly used for testing purposes. ```typescript async function setupPortForwarding( appServerPort: number, localPort: number = 8000 ): Promise { // Forward local port to app server on device await adb.forwardPort(localPort, appServerPort); console.log(`Local http://localhost:${localPort} -> Device port ${appServerPort}`); console.log('Port forward ready for testing'); } async function cleanupPortForwarding(localPort: number): Promise { await adb.removePortForward(localPort); console.log(`Port ${localPort} forward removed`); } ``` -------------------------------- ### getVersion Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/system-commands.md Gets the version information for the ADB binary and the Appium ADB bridge. ```APIDOC ## getVersion ### Description Gets the version information for the ADB binary and the Appium ADB bridge. ### Method POST ### Endpoint /session/:sessionId/appium/device/version ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the session. ### Response #### Success Response (200) - **value** (object) - {binary: {version: string}, bridge: {version: string}} - ADB and bridge version details. ### Request Example ```json { "args": {} } ``` ``` -------------------------------- ### Shell Command Usage with Output Format Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/system-commands.md Example of executing a shell command and specifying the desired output format using EXEC_OUTPUT_FORMAT. ```typescript const result = await adb.shell(['command'], { outputFormat: adb.EXEC_OUTPUT_FORMAT.FULL }); ``` -------------------------------- ### listInstalledPackages Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Lists all installed packages on the device, returning an array of objects containing the app package name and version code. ```APIDOC ## listInstalledPackages ### Description Lists all installed packages. ### Method async ### Response #### Success Response - **Array** - Array of {appPackage, versionCode} ### Request Example ```typescript const packages = await adb.listInstalledPackages(); packages.forEach(p => { console.log(`${p.appPackage}: v${p.versionCode}`); }); ``` ``` -------------------------------- ### Create ADB Instance Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Use the static `createADB` method for asynchronous initialization of an ADB instance. It handles SDK resolution, executable location, and server startup. ```typescript const adb = await ADB.createADB({ sdkRoot: '/path/to/android-sdk', udid: 'emulator-5554' }); ``` -------------------------------- ### Get SDK Binary Path Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/system-commands.md Resolves the full path to an SDK binary like 'aapt' or 'zipalign'. ```typescript const aaptPath = await adb.getSdkBinaryPath('aapt'); const zipAlignPath = await adb.getSdkBinaryPath('zipalign'); ``` -------------------------------- ### installMitmCertificate Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/system-commands.md Installs a Man-in-the-Middle (MITM) certificate on the device, which is necessary for certain types of network traffic interception during testing. ```APIDOC ## installMitmCertificate ### Description Installs a Man-in-the-Middle certificate for testing. ### Method `async installMitmCertificate(certPath: string): Promise` ### Parameters #### Path Parameters - **certPath** (string) - Required - Path to certificate file ``` -------------------------------- ### isAppInstalled Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Checks if an app is installed on the device. It takes the package name and optional user profile ID for multi-user devices. ```APIDOC ## isAppInstalled ### Description Checks if an app is installed on the device. ### Method async ### Parameters #### Path Parameters - **pkg** (string) - Required - Package name - **opts.user** (string) - Optional - User profile ID (multi-user devices) ### Response #### Success Response - **boolean** - true if installed ### Request Example ```typescript const installed = await adb.isAppInstalled('com.android.chrome'); ``` ``` -------------------------------- ### Get Connected Emulators Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Lists all currently running Android emulator instances. ```typescript async getConnectedEmulators(): Promise ``` -------------------------------- ### Configuring ADB with Keystore for Signing Source: https://github.com/appium/appium-adb/blob/master/_autodocs/errors.md Creates an ADB instance configured to use a keystore for signing, specifying paths and passwords for the keystore and key alias. ```typescript const adb = await ADB.createADB({ useKeystore: true, keystorePath: '/path/to/valid.keystore', keystorePassword: 'correctpassword', keyAlias: 'existingkey', keyPassword: 'keypassword' }); ``` -------------------------------- ### ADB Constructor Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Initializes a new ADB instance. It is recommended to use the `createADB` static method for asynchronous initialization. ```APIDOC ## Constructor ```typescript constructor(opts: ADBOptions = {}) ``` ### Description Creates a new ADB instance. Note: use `ADB.createADB()` static method instead for async initialization. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | opts | ADBOptions | {} | Configuration options | ``` -------------------------------- ### Get Device Model Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Retrieves the model name of the connected Android device. ```typescript async getModel(): Promise ``` -------------------------------- ### Get Product Default Language Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/device-settings.md Retrieves the default language setting for the product running on the device. ```typescript async getDeviceProductLanguage(): Promise ``` -------------------------------- ### Remote ADB Server Configuration Source: https://github.com/appium/appium-adb/blob/master/_autodocs/configuration.md Example configuration for connecting to a remote ADB server. It specifies the host and port of the remote ADB server along with the local SDK root. ```typescript const adb = await ADB.createADB({ remoteAdbHost: '192.168.1.100', remoteAdbPort: 5037, sdkRoot: '/path/to/sdk' }); ``` -------------------------------- ### mkdir Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/file-network-commands.md Creates a directory on the device. ```APIDOC ## mkdir ### Description Creates a directory on device. ### Method `mkdir(devicePath: string): Promise` ### Parameters #### Path Parameters - **devicePath** (string) - Required - Directory path to create ### Response #### Success Response - **Promise** - Command output ### Request Example ```typescript await adb.mkdir('/sdcard/mydir'); await adb.push('local/file.txt', '/sdcard/mydir/file.txt'); ``` ``` -------------------------------- ### Set Up Port Forwarding Source: https://github.com/appium/appium-adb/blob/master/_autodocs/DOCUMENTATION_INDEX.md Forward a local port to a device port, enabling access to services running on the device from your local machine. Example: access http://localhost:8000 for device port 3000. ```typescript await adb.forwardPort(8000, 3000); // Access http://localhost:8000 for device port 3000 ``` -------------------------------- ### getSetting Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/device-settings.md Retrieves a specific setting value from the device. Requires namespace and key. ```APIDOC ## getSetting ### Description Gets a settings value. ### Method `getSetting(namespace: string, key: string): Promise` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * **namespace** (string) - Required - Settings namespace (secure, system, global) * **key** (string) - Required - Setting key ### Response #### Success Response (200) * **Promise** - Setting value ### Example ```typescript const brightness = await adb.getSetting('system', 'screen_brightness'); const timeout = await adb.getSetting('system', 'screen_off_timeout'); ``` ``` -------------------------------- ### Get Device Setting Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/device-settings.md Fetches the value of a specific system, secure, or global setting. Requires the namespace and key of the setting. ```typescript const brightness = await adb.getSetting('system', 'screen_brightness'); const timeout = await adb.getSetting('system', 'screen_off_timeout'); ``` -------------------------------- ### Get ADB Version Information Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Fetch version details for both the ADB binary and the Android Debug Bridge. ```typescript const version = await adb.getVersion(); console.log(version.binary?.version); // e.g., "35.0.1" console.log(version.bridge.version); // e.g., "1.0.46" ``` -------------------------------- ### Get Package Information Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Retrieves information about a specific application package. Returns an object containing name, versionCode, versionName, and isInstalled status. ```typescript const info = await adb.getPackageInfo('com.example.app'); console.log(`${info.name} v${info.versionName} (${info.versionCode})`); ``` -------------------------------- ### Create ADB Instance with Custom Configuration Source: https://github.com/appium/appium-adb/blob/master/_autodocs/configuration.md Instantiate an ADB object with specific configuration options, including the SDK root, target device UDID, and command execution timeout. This allows for fine-grained control over the ADB instance. ```typescript import { ADB } from 'appium-adb'; // With custom configuration const adb = await ADB.createADB({ sdkRoot: '/path/to/android-sdk', udid: 'emulator-5554', adbExecTimeout: 30000 }); ``` -------------------------------- ### Get Device Property Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Retrieves a specific system property from the device. Requires the property key, e.g., 'ro.build.version.sdk'. ```typescript async getDeviceProperty(key: string): Promise ``` -------------------------------- ### Get Emulator Version Information Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/emulator-commands.md Fetches the emulator's version and build details. Returns an object containing revision and buildId. ```typescript async getEmuVersionInfo(): Promise ``` ```typescript const version = await adb.getEmuVersionInfo(); console.log(`Emulator: v${version.revision} (build ${version.buildId})`); ``` -------------------------------- ### Get Connected Devices Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Lists all connected Android devices. An optional verbose option can include extended properties. ```typescript async getConnectedDevices(opts?: ConnectedDevicesOptions): Promise ``` ```typescript const devices = await adb.getConnectedDevices({verbose: true}); ``` -------------------------------- ### Check if App is Installed Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/app-commands.md Checks if a specific application package is installed on the device. Supports specifying a user profile ID for multi-user devices. ```typescript async isAppInstalled(pkg: string, opts?: IsAppInstalledOptions): Promise ``` ```typescript const installed = await adb.isAppInstalled('com.android.chrome'); ``` -------------------------------- ### Get Process Name by ID Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Retrieves the process name associated with a given process ID (PID). ```typescript async getProcessNameById(pid: number): Promise ``` -------------------------------- ### Get Process IDs by Name Source: https://github.com/appium/appium-adb/blob/master/_autodocs/api-reference/adb-class.md Retrieves an array of process IDs (PIDs) for all processes matching a given name. ```typescript async getProcessIdsByName(name: string): Promise ```