Self-maintained QuickJS Android Bindings.
- Download the latest
.aar
archive from release page; - In Android Studio:
File > New > New Module > Import .JAR/.AAR Package
, locate.aar
, clickFinish
.
QuickJS quickJS = new QuickJS.Builder().build();
try (JSRuntime runtime = quickJS.createJSRuntime()) {
try (JSContext context = runtime.createJSContext()) {
String script1 = "" +
"function fibonacci(n) {" +
" if (n == 0 || n == 1) return n;" +
" return fibonacci(n - 1) + fibonacci(n - 2);" +
"}";
// Evaluate a script without return value
context.evaluate(script1, "fibonacci.js");
String script2 = "fibonacci(10);";
// Evaluate a script with return value
int result = context.evaluate(script2, "fibonacci.js", int.class);
assertEquals(55, result);
}
}
See Usages.md for advanced usages.
git clone --recurse-submodules https://github.com/shiqimei/quickjs-android.git
Open the folder quickjs-android
in Android Studio.
This is a non-serious benchmark. The purpose is to compare the performance of QuickJS and V8 on Android.
Engine | v8 | QuickJS (Script Mode) | QuickJS (Bytecode Mode) |
---|---|---|---|
init | 30ms | 18ms | 18ms |
eval | 29ms | 282ms | 48ms |
total | 59ms | 300ms | 56ms |
- Device: Huawei P30 Pro (Kirin 980), Android 10.
- Test JavaScript File:
asset:/sonic.js
(189 KB).
- Even when operating in bytecode mode, QuickJS's evaluation time is notably higher than V8's, and this disparity intensifies as the JavaScript file size increases.
- QuickJS's initialization time is slightly lower than V8's, and this advantage is constant despite of file sizes.
- bellard/quickjs QuickJS official repository.
- seven332/quickjs-android QuickJS Android Wrapper.
- openwebf/quickjs Optimized quickjs mantained by OpenWebF team.
- taoweiji/quickjs-android Android Bindings for QuickJS, A fine little javascript engine.