Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
Q

quickjs-android

> 编程语言
Open source

QuickJS Android wrapper

195 stars0 likes2 views
WebsiteGitHub

About

QuickJS Android wrapper

QuickJS Android

QuickJS Android wrapper.

Build

bash
git clone --recurse-submodules https://github.com/seven332/quickjs-android.git

Open the folder quickjs-android in Android Studio.

Download

  1. Add the JitPack repository to your root build.gradle.
gradle
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add quickjs-android dependency to your application build.gradle.
gradle
dependencies {
    implementation "com.github.seven332:quickjs-android:0.1.0"
}

Usage

Evaluate Javascript Scripts

…

Call Java Methods in Javascript Scripts

Non-static methods and static methods are supported. Wrap a Java method as a JSFunction, then add the JSFunction to the JSContext. Call it like a normal Javascript function.

…

Or create a JSFunction with a callback.

…

Call Javascript Methods in Java codes

Just evaluate it. Or call JSFunction.invoke().

Promise

Use JSContext.executePendingJob() to execute pending job of promises. You may call JSContext.executePendingJob() several times until it returns false.

java
QuickJS quickJS = new QuickJS.Builder().build();
try (JSRuntime runtime = quickJS.createJSRuntime()) {
  try (JSContext context = runtime.createJSContext()) {
    context.evaluate("a = 1;Promise.resolve().then(() => { a = 2 })", "test.js");
    assertEquals(1, context.getGlobalObject().getProperty("a").cast(JSNumber.class).getInt());
    // Execute the pending job
    assertTrue(context.executePendingJob());
    assertEquals(2, context.getGlobalObject().getProperty("a").cast(JSNumber.class).getInt());
    // No pending job
    assertFalse(context.executePendingJob());
  }
}

Conversion between Java Values and Javascript Values

Java values are converted to Javascript values when calling Java methods in Javascript scripts. Javascript values are converted to a Java values when receiving return values from evaluated Javascript scripts. QuickJS Android supports primitive types, string, array.

java
QuickJS quickJS = new QuickJS.Builder().build();
try (JSRuntime runtime = quickJS.createJSRuntime()) {
  try (JSContext context = runtime.createJSContext()) {
    String[] result = context.evaluate("['hello', 'world']", "test.js", String[].class);
    assertArrayEquals(new String[] { "hello", "world" }, result);
  }
}

Java Interfaces are also supported.

…

Use TypeAdapter to support any type you like.

…

Concept

QuickJS Android uses the similar APIs to QuickJS.

JSRuntime

JSRuntime represents a Javascript runtime corresponding to an object heap. Several runtimes can exist at the same time but they cannot exchange objects. Inside a given runtime, no multi-threading is supported.

-- QuickJS Document

JSContext

JSContext represents a Javascript context (or Realm). Each JSContext has its own global objects and system objects. There can be several JSContexts per JSRuntime and they can share objects, similar to frames of the same origin sharing Javascript objects in a web browser.

-- QuickJS Document

JSValue

JSValue represents a Javascript value which can be a primitive type or an object.

-- QuickJS Document

Available subclasses of JSValue are JSNull, JSUndefined, JSBoolean, JSNumber, JSString, JSObject, JSArray, JSFunction, JSSymbol.

Test

The original tests and benchmarks of QuickJS are in android-test. It's a console-like app running all tests and benchmarks at startup, like make test.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言