Skip to content

Methods ​

Loading ​

MethodReturnsDescription
loadFromFile(file)Promise<this>Load from a File object
loadFromUrl(url, options?)Promise<this>Download with fetch, then load
loadFromArrayBuffer(buffer)Promise<this>Load from raw bytes
loadFromZip(zip)Promise<this>Load from a JSZip instance

All four reject if the file is not a valid APK, contains native libraries, or exceeds the size limit.

Lifecycle ​

MethodReturnsDescription
setDevice(device)thisMerge device overrides and apply the new size
stop()thisStop the engine, keep the canvas
destroy()thisStop and remove the canvas from its host

Properties ​

PropertyTypeDescription
vmJavaVM | nullCurrent VM instance, read-only
canvasHTMLCanvasElement | nullThe canvas in use
runningbooleanWhether an activity is running
deviceobjectEffective device configuration

Example ​

js
const sim = createSimulator({ element: '#screen' });

await sim.loadFromUrl('https://caofangkuai.github.io/apk.js/samples/hello-dex.apk');
console.log(sim.vm?.packageName);

sim.setDevice({ width: 280, height: 480 });
sim.destroy();

Released under the MIT License.