1.0.5 • Published 11 days ago

@wtto00/android-tools v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
11 days ago

android-tools

Test

Node module for managing and controlling the Android Devices.

English | 简体中文

Install

npm i @wtto00/android-tools

Usage

import Android from '@wtto00/android-tools';

const options = {
  // adb: "platform-tools/adb",
  // avdmanager: "cmdline-tools/bin/avdmanager",
  // sdkmanager: "cmdline-tools/bin/sdkmanager",
  // emulator: "emulator/emulator",
};
const android = new Android(options);

Andorid Options | field | type | required | default | note | | ----- | ---- | -------- | ------- | ---- | |adb|string|false|${process.env.ANDROID_HOME}/platform-tools/adb or adb in PATH|The location of the adb executable file relative to ANDROID_HOME| |avdmanager|string|false|${process.env.ANDROID_HOME}/cmdline-tools/bin/avdmanager or avdmanager in PATH| The location of the avdmanager executable file relative to ANDROID_HOME| |sdkmanager|string|false|${process.env.ANDROID_HOME}/cmdline-tools/bin/sdkmanager or sdkmanager in PATH|The location of the sdkmanager executable file relative to ANDROID_HOME| |emulator|string|false|${process.env.ANDROID_HOME}/emulator/emulator or emulator in PATH|The location of the emulator executable file relative to ANDROID_HOME|

start

Start the emulator using the AVD supplied through with avdName.

android
  .start({
    avd: 'android-avd-name',
    verbose: true
    // ...
  })
  .then((res) => {
    console.log(`emulatorId: ${res.id}`);
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
avdstringtrue-use a specific android virtual device
verbosebooleantrue-enable specific debug messages
noWindowbooleanfalse-disable graphical window display
noSnapshotbooleanfalse-perform a full boot and do not auto-save, but qemu vmload and vmsave operate on snapstorage
noSnapstoragebooleanfalse-do not mount a snapshot storage file (this disables all snapshot functionality)
noSnapshotUpdateTimebooleanfalse-do not try to correct snapshot time on restore
noSnapshotSavebooleanfalse-do not auto-save to snapshot on exit: abandon changed state
noSnapshotLoadbooleanfalse-do not auto-start from snapshot: perform a full boot
cameraBack"emulated""virtualscene""videoplayback""none""webcam"false-set emulation mode for a camera facing back
cameraFront'emulated''webcam''none'false-set emulation mode for a camera facing front
gpu'auto''auto-no-window''host''swiftshader_indirect''angle_indirect''guest'false'auto'set hardware OpenGLES emulation mode
nocachebooleanfalse-disable the cache partition
noaudiobooleanfalse-disable audio support
noBootAnimbooleanfalse-disable animation for faster boot
lowrambooleanfalse-device is a low ram device
restartWhenStalledbooleanfalse-Allows restarting guest when it is stalled.
waitForDebuggerbooleanfalse-Pause on launch and wait for a debugger process to attach before resuming
httpProxystringfalse-make TCP connections through a HTTP/HTTPS proxy
coresnumberfalse-Set number of CPU cores to emulator
wipeDatabooleanfalse-reset the user data image (copy it from initdata)
noPassiveGpsbooleanfalse-disable passive gps updates

waitForDevice

Waiting for the simulator device to become available.

android
  .waitForDevice('emulator-id')
  .then(() => {
    console.log('available');
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
emulatorIdstringtrue-ID of emulator device

ensureReady

Ensure device has been started and ready.

android
  .ensureReady('emulator-id')
  .then(() => {
    console.log('ready');
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
emulatorIdstringtrue-ID of emulator device

createAVD

Create a AVD based upon image.

android
  .createAVD({
    name: avdName,
    package: 'android-image-name',
    force: false
  })
  .then(() => {
    console.log('has been created');
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
apiLevelnumberfalse-API level of the platform system image - e.g. 23 for Android Marshmallow, 29 for Android 10.
target'default''google_apis''playstore''android-wear''android-wear-cn''android-tv''google-tv''aosp_atd ''google_atd'false'default'Target of the system image .
arch'x86_64''x86''arm64-v8a''armeabi-v7a'falseCurrent system CPU architectureCPU architecture of the system image
packagestringfalse-Package path of the system image for this AVD (e.g. 'system-images;android-19;google_apis;x86').
namestringfalse-Name of the new AVD.
forcebooleanfalse-Forces creation (overwrites an existing AVD)
  • If you pass a package, the parameters apiLevel, target, and arch will be ignored. If you don't pass a package, the apiLevel parameter is required.

hasAVD

Check if a specific AVD has been created on this machine.

android
  .hasAVD('android-avd-name')
  .then((res) => {
    console.log(res ? 'has been created' : 'not exist');
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
emulatorIdstringtrue-Name of AVD

stop

Stop a certain emulator.

android
  .stop('emulator-id')
  .then(() => {
    console.log('has sent stop command');
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
emulatorIdstringtrue-ID of emulator device

waitForStop

Wait until the device is stopped.

android
  .waitForStop('emulator-id')
  .then(() => {
    console.log('has been stopped');
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
emulatorIdstringtrue-ID of emulator device

isInstalled

Check the package specified with packageName is installed or not.

android
  .isInstalled('emulator-id', 'com.android.webview')
  .then((res) => {
    console.log(res ? 'installed' : 'not installed');
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
emulatorIdstringtrue-ID of emulator device
packageNamestringtrue-Package name of App

install

Install an APK located by absolute URI apkPath onto device with emulatorId.

android
  .install('emulator-id', '/path/to/apk', { r: true })
  .then(() => {
    console.log('installed');
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
emulatorIdstringtrue-ID of emulator device
apkPathstringtrue-Absolute path of apk file
optionsobjectfalse-The parameters for "adb install": -lrtsdg

inputKeyEvent

adb shell input keyevent.

android
  .inputKeyEvent('emulator-id', 82)
  .then(() => {
    console.log('has send key');
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
emulatorIdstringtrue-ID of emulator device
keynumbertrue-key number,seeAndroid Document

devices

List connected devices

android
  .devices()
  .then((res) => {
    res.forEach((item) => {
      console.log(`name: ${item.name}, status: ${item.status}`);
    });
  })
  .catch((err) => {
    console.log(err);
  });

listPackages

List packages installed on the emulator with emulatorId.

android
  .listPackages('emulator-id')
  .then((res) => {
    res.forEach((item) => {
      console.log(item);
    });
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
emulatorIdstringtrue-ID of emulator device

listDevices

List the available device list for creating emulators in the current system.

android
  .listDevices()
  .then((res) => {
    res.forEach((item) => {
      console.log(`id: ${item.id}, Name: ${item.Name}, OEM: ${item.OEM}, Tag: ${item.Tag}`);
    });
  })
  .catch((err) => {
    console.log(err);
  });

listAVDs

List all AVDs created on this machine.

android
  .listAVDs()
  .then((res) => {
    res.forEach((item) => {
      console.log(`Name: ${item.Name}, Path: ${item.Path}, Target: ${item.Target}, Sdcard: ${item.Sdcard}`);
    });
  })
  .catch((err) => {
    console.log(err);
  });

listTargets

List available Android targets.

android
  .listTargets()
  .then((res) => {
    res.forEach((item) => {
      console.log(`id: ${item.id}, Name: ${item.Name}, Type: ${item.Type}, API level: ${item['API level']}`);
    });
  })
  .catch((err) => {
    console.log(err);
  });

listImages

List available android images on this machine.

android
  .listImages()
  .then((res) => {
    res.forEach((item) => {
      console.log(
        `name: ${item.name}, type: ${item.type}, sdk: ${item.sdk}, target: ${item.target}, arch: ${item.arch}`
      );
    });
  })
  .catch((err) => {
    console.log(err);
  });

listInstalledImages

List installed android images on this machine.

android
  .listInstalledImages()
  .then((res) => {
    res.forEach((item) => {
      console.log(
        `name: ${item.name}, type: ${item.type}, sdk: ${item.sdk}, target: ${item.target}, arch: ${item.arch}`
      );
    });
  })
  .catch((err) => {
    console.log(err);
  });

adb

Use adb to execute commands.

android
  .adb('emulator-id', 'shell pm list packages')
  .then((res) => {
    console.log(res.output);
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
cmdstringtrue-The command to be executed.

avdmanager

Use avdmanager to execute commands.

android
  .avdmanager('list avd')
  .then((res) => {
    console.log(res.output);
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
cmdstringtrue-The command to be executed.

sdkmanager

Use sdkmanager to execute commands.

android
  .sdkmanager('--list')
  .then((res) => {
    console.log(res.output);
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
cmdstringtrue-The command to be executed.

emulator

Use emulator to execute commands.

android
  .emulator('--help')
  .then((res) => {
    console.log(res.output);
  })
  .catch((err) => {
    console.log(err);
  });
fieldtyperequireddefaultnote
cmdstringtrue-The command to be executed.
1.0.5

11 days ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago