@nativescript/android 8.9.0-napi-jsc.11 → 8.9.0-napi-quickjs.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,13 +1,28 @@
1
- # Node-API Android Runtime for NativeScript
2
- [![Build Status](https://travis-ci.org/NativeScript/android-runtime.svg?branch=master)](https://travis-ci.org/NativeScript/android-runtime)
1
+ <p align="center" >
2
+ <img src="https://raw.githubusercontent.com/NativeScript/artwork/refs/heads/main/logo/export/NativeScript_Logo_White_Blue_Rounded.png" alt="NativeScript Logo" width="20%" height="20%">
3
+ </p>
3
4
 
4
- Contains the source code for the NativeScript's Android Runtime. [NativeScript](https://www.nativescript.org/) is a framework which enables developers to write truly native mobile applications for Android and iOS using JavaScript and CSS. Each mobile platform has its own ecosystem and offers completely different development tools and language(s) - Java for Android and Objective C (Swift) for iOS. In order to translate JavaScript code to the corresponding native APIs some kind of proxy mechanism is needed. This is exactly what the "Runtime" parts of NativeScript are responsible for. The Android Runtime may be thought of as "The Bridge" between the JavaScript and Android worlds. A NativeScript application for Android is a standard native package (apk) which besides the JavaScript files embed the runtime as well.
5
+ <h1 align="center">Node-API Android Runtime for NativeScript</h1>
6
+
7
+ <div align = "center">
8
+
9
+ ![NPM Version (with dist tag)](https://img.shields.io/npm/v/%40nativescript%2Fandroid/napi-v8?style=for-the-badge&logo=nativescript)
10
+ ![NPM Version (with dist tag)](https://img.shields.io/npm/v/%40nativescript%2Fandroid/napi-quickjs?style=for-the-badge&logo=nativescript)
11
+ ![NPM Version (with dist tag)](https://img.shields.io/npm/v/%40nativescript%2Fandroid/napi-hermes?style=for-the-badge&logo=nativescript)
12
+ ![NPM Version (with dist tag)](https://img.shields.io/npm/v/%40nativescript%2Fandroid/napi-jsc?style=for-the-badge&logo=nativescript)
13
+
14
+ </div>
15
+
16
+ [NativeScript](https://www.nativescript.org/) is an open-source framework for building truly native mobile applications using JavaScript. This repository contains the source code for the Node-API based Android Runtime used by NativeScript.
17
+
18
+ The Android Runtime is a key component of the NativeScript framework. It is responsible for executing JavaScript code on Android devices. The runtime is built on top of [Node-API](https://nodejs.org/api/n-api.html) and provides a way to interact with the Android platform APIs from JavaScript.
19
+
20
+ The new runtime is based on the Node-API and is designed to be more stable, faster, and easier to maintain. It also supports multiple JavaScript engines, including [V8](https://v8.dev/), [QuickJS](https://github.com/quickjs-ng/quickjs/), [Hermes](https://github.com/facebook/hermes), and [JavaScriptCore](https://docs.webkit.org/Deep%20Dive/JSC/JavaScriptCore.html).
5
21
 
6
22
  <!-- TOC depthFrom:2 -->
7
23
 
8
24
  - [Main Projects](#main-projects)
9
25
  - [Helper Projects](#helper-projects)
10
- - [Architecture Diagram](#architecture-diagram)
11
26
  - [Build Prerequisites](#build-prerequisites)
12
27
  - [How to build](#how-to-build)
13
28
  - [How to run tests](#how-to-run-tests)
@@ -16,118 +31,102 @@ Contains the source code for the NativeScript's Android Runtime. [NativeScript](
16
31
 
17
32
  <!-- /TOC -->
18
33
 
19
- ## Additional docs
20
- Several Wiki pages describe some internal topics about the runtime [here](https://github.com/NativeScript/android-runtime/wiki)
34
+ ## Project structure
21
35
 
22
- ## Main Projects
23
36
  The repo is structured in the following projects (ordered by dependencies):
24
37
 
25
- * [**android-metadata-generator**](android-metadata-generator) - generates metadata necessary for the Android Runtime.
26
- * [**android-binding-generator**](test-app/runtime-binding-generator) - enables Java & Android types to be dynamically created at runtime. Needed by the `extend` routine.
27
- * [**android-runtime**](test-app/runtime) - contains the core logic behind the NativeScript's Android Runtime. This project contains native C++ code and needs the Android NDK to build properly.
28
- * [**android-runtime-testapp**](test-app/app) - this is a vanilla Android Application, which contains the tests for the runtime project.
38
+ - [**android-metadata-generator**](android-metadata-generator) - generates metadata necessary for the Android Runtime.
39
+ - [**android-binding-generator**](test-app/runtime-binding-generator) - enables Java & Android types to be dynamically created at runtime. Needed by the `extend` routine.
40
+ - [**android-runtime**](test-app/runtime) - contains the core logic behind the NativeScript's Android Runtime. This project contains native C++ code and needs the Android NDK to build properly.
41
+ - [**android-runtime-testapp**](test-app/app) - this is a vanilla Android Application, which contains the tests for the runtime project.
42
+ - [**napi-implementations**](test-app/runtime/src/main//cpp/napi/) - contains the implementation of the Node-API for each supported JS engine.
29
43
 
30
44
  ## Helper Projects
31
45
 
32
- * [**android-static-binding-generator**](android-static-binding-generator) - build tool that generates bindings based on the user's javascript code.
33
- * [**project-template**](build-artifacts/project-template-gradle) - this is an empty placeholder Android Application project, used by the [NativeScript CLI](https://github.com/NativeScript/nativescript-cli) when building an Android project.
46
+ - [**android-static-binding-generator**](android-static-binding-generator) - build tool that generates bindings based on the user's javascript code.
47
+ - [**project-template**](build-artifacts/project-template-gradle) - this is an empty placeholder Android Application project, used by the [NativeScript CLI](https://github.com/NativeScript/nativescript-cli) when building an Android project.
34
48
 
35
- ## Architecture Diagram
36
- The NativeScript Android Runtime architecture can be summarized in the following diagram.
49
+ ### Build Prerequisites
37
50
 
38
- ![Android Runtime diagram](https://github.com/NativeScript/docs/blob/master/docs/img/ns-runtime-android.png)
51
+ Following are the minimal prerequisites to build the runtime package.
39
52
 
40
- For more details on how it works, read the [documentation](https://v7.docs.nativescript.org/core-concepts/android-runtime/overview).
53
+ - Install the latest [Android Studio](https://developer.android.com/studio/index.html).
54
+ - From the SDK Manager (Android Studio -> Tools -> Android -> SDK Manager) install the following components:
41
55
 
42
- ## Build Prerequisites
43
- Following are the minimal prerequisites to build the runtime package.
56
+ - Android API Level 23, 24, 25, 26, 27
57
+ - Android NDK
58
+ - Android Support Repository
59
+ - Download Build Tools
60
+ - CMake
61
+ - LLDB
44
62
 
45
- * Install the latest [Android Studio](https://developer.android.com/studio/index.html).
46
- * From the SDK Manager (Android Studio -> Tools -> Android -> SDK Manager) install the following components:
47
- * Android API Level 23, 24, 25, 26, 27
48
- * Android NDK
49
- * Android Support Repository
50
- * Download Build Tools
51
- * CMake
52
- * LLDB
53
- * Clone this repository as well as the submodules: `git clone --recurse-submodules git@github.com:NativeScript/android-runtime.git`
63
+ ## How to Build
54
64
 
55
- ## Working with the Runtime in Android Studio
65
+ Clone the repo:
56
66
 
57
- * Open the test-app folder in Android Studio. It represents a valid Android project and you are able to build and run a test application working with the Runtime from the source.
67
+ ```Shell
68
+ git clone https://github.com/NativeScript/napi-android.git
69
+ ```
58
70
 
59
- Note: You might need to run the Android Studio from the command line in order to preserve the environment variables. This is in case you get errors like "missing npm" if starting the studio the usual way.
71
+ Install the jsparser dependencies:
60
72
 
61
- ## How to Build
73
+ ```Shell
74
+ cd test-app/build-tools/jsparser
75
+ npm install
76
+ ```
62
77
 
63
- * Install dependencies from NPM:
78
+ Set the following environment variables:
64
79
 
65
- ```Shell
66
- cd test-app/build-tools/jsparser
67
- npm install
68
- ```
80
+ - `JAVA_HOME` such that `$JAVA_HOME/bin/java` points to your Java executable
81
+ - `ANDROID_HOME` pointing to where you have installed the Android SDK
82
+ - `ANDROID_NDK_HOME` pointing to the version of the Android NDK needed for this version of NativeScript
69
83
 
70
- * Set environment variables:
71
- - `JAVA_HOME` such that `$JAVA_HOME/bin/java` points to your Java executable
72
- - `ANDROID_HOME` pointing to where you have installed the Android SDK
73
- - `ANDROID_NDK_HOME` pointing to the version of the Android NDK needed for this version of NativeScript
84
+ Run command
74
85
 
75
- * Run command
86
+ Windows:
76
87
 
77
- Windows:
88
+ ```Shell
89
+ gradlew -Pengine=V8
90
+ ```
78
91
 
79
- ```Shell
80
- gradlew -Pengine=V8
81
- ```
92
+ Mac/Linux:
82
93
 
83
- Mac/Linux:
94
+ ```Shell
95
+ ./gradlew -Pengine=V8
96
+ ```
84
97
 
85
- ```Shell
86
- ./gradlew -Pengine=V8
87
- ```
88
98
  You can pass in `QUICKJS`, `HERMES`, `JSC` or `V8` to compile the runtime with the respective JS engine.
89
99
 
90
- * The build process includes building of the runtime package (both optimized and with unstripped v8 symbol table), as well as all supplementary tools used for the android builds: metadata-generator, binding-generator, metadata-generator, static-binding-generator
91
- * The result of the build will be in the dist folder.
92
-
93
- `Note:` To cut the build time in half and package only the optimized (stripped) version of the runtime package comment out 'tasks.generateRuntimeAar.execute()' in the [build.gradle](https://github.com/NativeScript/android-runtime/blob/v3.0.0-rc.1/build.gradle#L114) script.
100
+ - The build process includes building of the runtime package (both optimized and with unstripped v8 symbol table), as well as all supplementary tools used for the android builds: metadata-generator, binding-generator, metadata-generator, static-binding-generator
101
+ - The result of the build will be in the dist\_[engine] folder. For example if you are building with V8, the result will be in the dist_v8 folder.
94
102
 
95
103
  ## How to Run Tests
96
104
 
97
- * Go to subfolder test-app after you built the runtime.
98
- * Start an emulator or connect a device.
105
+ - Go to subfolder test-app after you built the runtime.
106
+ - Start an emulator or connect a device.
107
+
108
+ - Run command
99
109
 
100
- ``Note: Keep in mind the device or emulator needs to have an sdcard mounted.``
101
- * Run command
102
110
  ```Shell
103
111
  gradlew runtests
104
112
  ```
105
113
 
106
- ## How to Connect the Inspector
114
+ ## Working with the Runtime in Android Studio
107
115
 
108
- * Install dependencies: run command
109
- ```Shell
110
- cd test-app
111
- npm install
112
- ```
113
- * Run the test app in Android Studio, or manually in the emulator.
114
- * Run command
115
- ```Shell
116
- npx ns debug android --start
117
- ```
118
- (If you instead have the `nativescript` NPM module installed globally,
119
- you can omit the `npm install` and the `npx` prefix.)
120
- * This will print out a URL, such as
121
- `devtools://devtools/bundled/inspector.html?ws=localhost:40000`.
122
- Open this URL in Chrome or Chromium.
116
+ - Open the test-app folder in Android Studio. It represents a valid Android project and you are able to build and run a test application working with the Runtime from the source.
123
117
 
124
- ## Contribute
125
- We love PRs! Check out the [contributing guidelines](CONTRIBUTING.md). If you want to contribute, but you are not sure where to start - look for [issues labeled `help wanted`](https://github.com/NativeScript/android-runtime/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22).
118
+ Note: You might need to run the Android Studio from the command line in order to preserve the environment variables. This is in case you get errors like "missing npm" if starting the studio the usual way.
126
119
 
120
+ You can change the JS engine used by the runtime by setting the `jsEngine` property in the [`build.gradle`](test-app/runtime/build.gradle) file in the root of the project. The possible values are `QUICKJS`, `HERMES`, `JSC` or `V8`.
127
121
 
128
- ## Misc
122
+ ## Contribute
129
123
 
130
- * [Implementing additional Chrome DevTools protocol Domains](docs/extending-inspector.md)
124
+ We love PRs! Check out the [contributing guidelines](CONTRIBUTING.md). If you want to contribute, but you are not sure where to start - look for [issues labeled `help wanted`](https://github.com/NativeScript/napi-android/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22).
131
125
 
132
126
  ## Get Help
133
- Please, use [github issues](https://github.com/NativeScript/android-runtime/issues) strictly for [reporting bugs](CONTRIBUTING.md#reporting-bugs) or [requesting features](CONTRIBUTING.md#requesting-new-features). For general questions and support, check out [Stack Overflow](https://stackoverflow.com/questions/tagged/nativescript) or ask our experts in [NativeScript community Slack channel](http://developer.telerik.com/wp-login.php?action=slack-invitation).
127
+
128
+ Please, use [github issues](https://github.com/NativeScript/napi-android/issues) strictly for [reporting bugs](CONTRIBUTING.md#reporting-bugs) or [requesting features](CONTRIBUTING.md#requesting-new-features). For general questions and support, check out [Stack Overflow](https://stackoverflow.com/questions/tagged/nativescript) or ask our experts in [NativeScript community on Discord](https://nativescript.org/discord).
129
+
130
+ ## License
131
+
132
+ This project is licensed under the Apache License Version 2.0. See the [LICENSE file](LICENSE) for more info.
@@ -92,13 +92,13 @@
92
92
  Array.prototype.slice.call(arguments, 1)
93
93
  );
94
94
  } else {
95
- thiz = new (Function.prototype.bind.apply(
95
+ thiz = new (Function.prototype.bind.apply(
96
96
  Extended,
97
97
  [null].concat(Array.prototype.slice.call(arguments, 1))
98
98
  ))();
99
99
  }
100
100
  } else {
101
- thiz = new Extended();
101
+ thiz = new Extended();
102
102
  }
103
103
  return thiz;
104
104
  };
@@ -107,17 +107,14 @@
107
107
  var Extended = extend(thiz);
108
108
  thiz.__container__ = true;
109
109
  if (args && args.length > 0) {
110
- if (typeof Extended !== "function") {
111
- thiz = Reflect.construct(
112
- Extended,
113
- [null].concat(args)
114
- );
115
- } else {
116
- thiz = new (Function.prototype.bind.apply(
117
- Extended,
118
- [null].concat(args)
119
- ))();
120
- }
110
+ if (typeof Extended !== "function") {
111
+ thiz = Reflect.construct(Extended, [null].concat(args));
112
+ } else {
113
+ thiz = new (Function.prototype.bind.apply(
114
+ Extended,
115
+ [null].concat(args)
116
+ ))();
117
+ }
121
118
  } else {
122
119
  thiz = new Extended();
123
120
  }
@@ -279,14 +276,14 @@
279
276
  return undefined;
280
277
  }
281
278
 
282
- globalThis.__prepareHostObject = function (hostObject, jsThis) {
283
- // const prototype = Object.getPrototypeOf(jsThis);
284
- // Object.setPrototypeOf(hostObject, prototype);
285
- Object.defineProperty(hostObject, "super", {
286
- get: () => jsThis["super"],
279
+ globalThis.__prepareHostObject = function (hostObject, jsThis) {
280
+ // const prototype = Object.getPrototypeOf(jsThis);
281
+ // Object.setPrototypeOf(hostObject, prototype);
282
+ Object.defineProperty(hostObject, "super", {
283
+ get: () => jsThis["super"],
287
284
  });
288
- };
289
-
285
+ };
286
+
290
287
  const EXTERNAL_PROP = "[[external]]";
291
288
  const REFERENCE_PROP_JSC = "[[jsc_reference_info]]";
292
289
 
@@ -331,4 +328,66 @@ globalThis.__prepareHostObject = function (hostObject, jsThis) {
331
328
  lines[2] = " at extend(native)";
332
329
  return lines.join("\n");
333
330
  };
331
+
332
+ if (globalThis.URL) {
333
+ const BLOB_STORE = new Map();
334
+ URL.createObjectURL = function (object, options = null) {
335
+ try {
336
+ if (object instanceof Blob || object instanceof File) {
337
+ const id = java.util.UUID.randomUUID().toString();
338
+ const ret = `blob:nativescript/${id}`;
339
+ BLOB_STORE.set(ret, {
340
+ blob: object,
341
+ type: object?.type,
342
+ ext: options?.ext,
343
+ });
344
+ return ret;
345
+ }
346
+ } catch (error) {
347
+ return null;
348
+ }
349
+ return null;
350
+ };
351
+ URL.revokeObjectURL = function (url) {
352
+ BLOB_STORE.delete(url);
353
+ };
354
+ const InternalAccessor = class {};
355
+ InternalAccessor.getData = function (url) {
356
+ return BLOB_STORE.get(url);
357
+ };
358
+ URL.InternalAccessor = InternalAccessor;
359
+ Object.defineProperty(URL.prototype, "searchParams", {
360
+ get() {
361
+ if (this._searchParams == null) {
362
+ this._searchParams = new URLSearchParams(this.search);
363
+ Object.defineProperty(this._searchParams, "_url", {
364
+ enumerable: false,
365
+ writable: false,
366
+ value: this,
367
+ });
368
+ this._searchParams._append = this._searchParams.append;
369
+ this._searchParams.append = function (name, value) {
370
+ this._append(name, value);
371
+ this._url.search = this.toString();
372
+ };
373
+ this._searchParams._delete = this._searchParams.delete;
374
+ this._searchParams.delete = function (name) {
375
+ this._delete(name);
376
+ this._url.search = this.toString();
377
+ };
378
+ this._searchParams._set = this._searchParams.set;
379
+ this._searchParams.set = function (name, value) {
380
+ this._set(name, value);
381
+ this._url.search = this.toString();
382
+ };
383
+ this._searchParams._sort = this._searchParams.sort;
384
+ this._searchParams.sort = function () {
385
+ this._sort();
386
+ this._url.search = this.toString();
387
+ };
388
+ }
389
+ return this._searchParams;
390
+ },
391
+ });
392
+ }
334
393
  })();
@@ -23,7 +23,7 @@ public final class RuntimeHelper {
23
23
  private RuntimeHelper() {
24
24
  }
25
25
 
26
- // private static AndroidJsV8Inspector v8Inspector;
26
+ private static AndroidJsV8Inspector v8Inspector;
27
27
 
28
28
  // hasErrorIntent tells you if there was an event (with an uncaught
29
29
  // exception) raised from ErrorReport
@@ -151,8 +151,8 @@ public final class RuntimeHelper {
151
151
  runtime = Runtime.initializeRuntimeWithConfiguration(config);
152
152
  if (isDebuggable) {
153
153
  try {
154
- // v8Inspector = new AndroidJsV8Inspector(context.getFilesDir().getAbsolutePath(), context.getPackageName());
155
- // v8Inspector.start();
154
+ v8Inspector = new AndroidJsV8Inspector(context.getFilesDir().getAbsolutePath(), context.getPackageName());
155
+ v8Inspector.start();
156
156
 
157
157
  // the following snippet is used as means to notify the VSCode extension
158
158
  // debugger that the debugger agent has started
@@ -176,7 +176,7 @@ public final class RuntimeHelper {
176
176
  shouldBreak = true;
177
177
  }
178
178
 
179
- // v8Inspector.waitForDebugger(shouldBreak);
179
+ v8Inspector.waitForDebugger(shouldBreak);
180
180
  } catch (IOException e) {
181
181
  if (Util.isDebuggableApp(context)) {
182
182
  e.printStackTrace();
@@ -1,4 +1,4 @@
1
- #Wed, 26 Feb 2025 12:42:21 -0800
1
+ #Wed, 19 Mar 2025 19:19:01 -0700
2
2
  # Project-wide Gradle settings.
3
3
 
4
4
  # IDE (e.g. Android Studio) users:
@@ -45,4 +45,4 @@ ns_default_kotlinx_metadata_jvm_version=2.0.0
45
45
  ns_default_mockito_core_version=3.0.0
46
46
  ns_default_spotbugs_version=3.1.12
47
47
 
48
- ns_engine=JSC
48
+ ns_engine=QUICKJS
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nativescript/android",
3
3
  "description": "NativeScript for Android using Node-API",
4
- "version": "8.9.0-napi-jsc.11",
4
+ "version": "8.9.0-napi-quickjs.12",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/NativeScript/android.git"