You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h1align="center">Node-API Android Runtime for NativeScript</h1>
3
2
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.
3
+
[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.
4
+
5
+
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.
6
+
7
+
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, QuickJS, Hermes, and JavaScriptCore.
5
8
6
9
<!-- TOC depthFrom:2 -->
7
10
8
11
-[Main Projects](#main-projects)
9
12
-[Helper Projects](#helper-projects)
10
-
-[Architecture Diagram](#architecture-diagram)
11
13
-[Build Prerequisites](#build-prerequisites)
12
14
-[How to build](#how-to-build)
13
15
-[How to run tests](#how-to-run-tests)
@@ -16,118 +18,108 @@ Contains the source code for the NativeScript's Android Runtime. [NativeScript](
16
18
17
19
<!-- /TOC -->
18
20
19
-
## Additional docs
20
-
Several Wiki pages describe some internal topics about the runtime [here](https://github.com/NativeScript/android-runtime/wiki)
21
+
## Project structure
21
22
22
-
## Main Projects
23
23
The repo is structured in the following projects (ordered by dependencies):
24
24
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.
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.
29
+
-[**napi-implementations**](test-app/runtime/src/main//cpp/napi/) - contains the implementation of the Node-API for each supported JS engine.
29
30
30
31
## Helper Projects
31
32
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.
33
+
-[**android-static-binding-generator**](android-static-binding-generator) - build tool that generates bindings based on the user's javascript code.
34
+
-[**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
35
35
-
## Architecture Diagram
36
-
The NativeScript Android Runtime architecture can be summarized in the following diagram.
Following are the minimal prerequisites to build the runtime package.
39
39
40
-
For more details on how it works, read the [documentation](https://v7.docs.nativescript.org/core-concepts/android-runtime/overview).
40
+
- Install the latest [Android Studio](https://developer.android.com/studio/index.html).
41
+
- From the SDK Manager (Android Studio -> Tools -> Android -> SDK Manager) install the following components:
41
42
42
-
## Build Prerequisites
43
-
Following are the minimal prerequisites to build the runtime package.
43
+
- Android API Level 23, 24, 25, 26, 27
44
+
- Android NDK
45
+
- Android Support Repository
46
+
- Download Build Tools
47
+
- CMake
48
+
- LLDB
44
49
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`
50
+
## How to Build
54
51
55
-
## Working with the Runtime in Android Studio
52
+
Clone the repo:
56
53
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.
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.
58
+
Install the jsparser dependencies:
60
59
61
-
## How to Build
60
+
```Shell
61
+
cd test-app/build-tools/jsparser
62
+
npm install
63
+
```
62
64
63
-
* Install dependencies from NPM:
65
+
Set the following environment variables:
64
66
65
-
```Shell
66
-
cd test-app/build-tools/jsparser
67
-
npm install
68
-
```
67
+
-`JAVA_HOME` such that `$JAVA_HOME/bin/java` points to your Java executable
68
+
-`ANDROID_HOME` pointing to where you have installed the Android SDK
69
+
-`ANDROID_NDK_HOME` pointing to the version of the Android NDK needed for this version of NativeScript
69
70
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
71
+
Run command
74
72
75
-
* Run command
73
+
Windows:
76
74
77
-
Windows:
75
+
```Shell
76
+
gradlew -Pengine=V8
77
+
```
78
78
79
-
```Shell
80
-
gradlew -Pengine=V8
81
-
```
79
+
Mac/Linux:
82
80
83
-
Mac/Linux:
81
+
```Shell
82
+
./gradlew -Pengine=V8
83
+
```
84
84
85
-
```Shell
86
-
./gradlew -Pengine=V8
87
-
```
88
85
You can pass in `QUICKJS`, `HERMES`, `JSC` or `V8` to compile the runtime with the respective JS engine.
89
86
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.
87
+
- 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
88
+
- 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.
92
89
93
90
`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.
94
91
95
92
## How to Run Tests
96
93
97
-
* Go to subfolder test-app after you built the runtime.
98
-
* Start an emulator or connect a device.
94
+
- Go to subfolder test-app after you built the runtime.
95
+
- Start an emulator or connect a device.
96
+
97
+
- Run command
99
98
100
-
``Note: Keep in mind the device or emulator needs to have an sdcard mounted.``
101
-
* Run command
102
99
```Shell
103
100
gradlew runtests
104
101
```
105
102
106
-
## How to Connect the Inspector
103
+
## Working with the Runtime in Android Studio
107
104
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.)
- 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.
106
+
107
+
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.
108
+
109
+
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`.
123
110
124
111
## 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).
126
112
113
+
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).
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).
122
+
123
+
## License
124
+
125
+
This project is licensed under the Apache License Version 2.0. See the [LICENSE file](LICENSE) for more info.
0 commit comments