百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
Q

quickjs-android

> 编程语言
开源

QuickJS Android 包装程序

195 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

QuickJS Android 包装程序

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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