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
Copy file name to clipboardExpand all lines: PLUGINS.md
+49-17Lines changed: 49 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,7 @@ A NativeScript plugin is any npm package, published or not, that exposes a nativ
25
25
*`AndroidManifest.xml` and `Info.plist` which describe the permissions, features or other configurations required or used by your app for Android and iOS, respectively.
The plugin must have the directory structure, described in the [Directory Structure](#directory-structure) section.
30
31
@@ -33,11 +34,12 @@ The plugin must have the directory structure, described in the [Directory Struct
33
34
If the NativeScript framework does not expose a native API that you need, you can develop a plugin which exposes the required functionality. When you develop a plugin, keep in mind the following requirements.
34
35
35
36
* The plugin must be a valid npm package.
36
-
* The plugin must expose a built-in native API or a native API available via custom native libraries.
37
+
* The plugin must expose a built-in native API or a native API available via custom native libraries. (why "must")
37
38
* The plugin must be written in JavaScript or TypeScript and must comply with the CommonJS specification. If written in TypeScript, make sure to include the compiled `JavaScript` file in your plugin.
38
39
* The plugin directory structure must comply with the specification described below.
39
40
* The plugin must contain a valid `package.json` which complies with the specification described below.
40
41
* If the plugin requires any permissions, features or other configuration specifics, it must contain `AndroidManifest.xml` and `Info.plist` file which describe them.
42
+
* (android speciffic) If the plugin has native dependencies, it must contain include.gralde file, which describe them. (suggestion)
41
43
42
44
### Directory Structure
43
45
@@ -50,6 +52,7 @@ my-plugin/
50
52
└── platforms/
51
53
├── android/
52
54
│ └── AndroidManifest.xml
55
+
│ └── include.gradle (suggestion)
53
56
└── ios/
54
57
└── Info.plist
55
58
```
@@ -68,13 +71,15 @@ my-plugin/
68
71
└── platforms/
69
72
├── android/
70
73
│ └── AndroidManifest.xml
74
+
│ └── include.gradle (suggestion)
71
75
└── ios/
72
76
└── Info.plist
73
77
```
74
78
75
79
*`index.js`: This file is the CommonJS module which exposes the native API. You can use platform-specific `*.platform.js` files. For example: `index.ios.js` and `index.android.js`. During the plugin installation, the NativeScript CLI will copy the platform resources to the `tns_modules` subdirectory in the correct platform destination in the `platforms` directory of your project.<br/>Alternatively, you can give any name to this CommonJS module. In this case, however, you need to point to this file by setting the `main` key in the `package.json` for the plugin. For more information, see [Folders as Modules](https://nodejs.org/api/modules.html#modules_folders_as_modules).
76
80
*`package.json`: This file contains the metadata for your plugin. It sets the supported runtimes, the plugin name and version and any dependencies. The `package.json` specification is described in detail below.
77
-
*`platforms\android\AndroidManifest.xml`: This file describes any specific configuration changes required for your plugin to work. For example: required permissions. For more information about the format of `AndroidManifest.xml`, see [App Manifest](http://developer.android.com/guide/topics/manifest/manifest-intro.html).<br/>During the plugin installation, the NativeScript CLI will merge the plugin `AndroidManifest.xml` with the `AndroidManifest.xml` for your project. The NativeScript CLI will not resolve any contradicting or duplicate entries during the merge. After the plugin is installed, you need to manually resolve such issues.
81
+
*`platforms\android\AndroidManifest.xml`: This file describes any specific configuration changes required for your plugin to work. For example: required permissions. For more information about the format of `AndroidManifest.xml`, see [App Manifest](http://developer.android.com/guide/topics/manifest/manifest-intro.html).<br/>During the plugin installation, the NativeScript CLI will merge the plugin `AndroidManifest.xml` with the `AndroidManifest.xml` for your project. The NativeScript CLI will not resolve any contradicting or duplicate entries during the merge. After the plugin is installed, you need to manually resolve such issues.
82
+
*`platforms\android\include.gradle': This file can change the native configuration.For example native dependencies, build types and configurations. For more information about the format of 'include.gradle', see [include.gradle file](#includegradle-specification). (remove) .<br/>During the plugin installation, the NativeScript CLI will merge the plugin `AndroidManifest.xml` with the `AndroidManifest.xml` for your project. (remove) (suggestion)
78
83
*`platforms\ios\Info.plist`: This file describes any specific configuration changes required for your plugin to work. For example: required permissions. For more information about the format of `Info.plist`, see [About Information Property List Files](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html).<br/>During the plugin installation, the NativeScript CLI will merge the plugin `Info.plist` with the `Info.plist` for your project. The NativeScript CLI will not resolve any contradicting or duplicate entries during the merge. After the plugin is installed, you need to manually resolve such issues.
79
84
80
85
NativeScript plugins which contain both native Android and iOS libraries might have the following directory structure.
@@ -84,19 +89,21 @@ my-plugin/
84
89
├── ...
85
90
└── platforms/
86
91
├── android/
87
-
│ ├── libs/
88
-
│ │ └── MyLibrary.jar
89
-
│ ├── MyAndroidLibrary/
90
-
│ │ ├── ...
91
-
│ │ └── project.properties
92
+
│ ├── libs/ (remove suggestion)
93
+
│ │ └── MyLibrary.jar (remove suggestion)
94
+
│ ├── MyAndroidLibrary/ (remove suggestion)
95
+
│ │ ├── ... (remove suggestion)
96
+
│ │ └── project.properties (remove suggestion)
97
+
│ └── MyLibrary.jar (add suggestion)
98
+
│ └── include.gradle (add suggestion)
92
99
│ └── AndroidManifest.xml
93
100
└── ios/
94
101
├── MyiOSLibrary.framework
95
102
└── Info.plist
96
103
```
97
104
98
-
*`platforms\android\libs`: This directory contains any native Android libraries packaged as `*.jar` packages. During the plugin installation, the NativeScript CLI will copy these files to `lib\Android` in your project and will configure the Android project in `platforms\android` to work with the library.
99
-
*`platforms\android\MyAndroidLibrary`: This directory contains a native Android library with a `project.properties` file. During the plugin installation, the NativeScript CLI will copy these files to `lib\Android` in your project and will configure the Android project in `platforms\android` to work with the library.
105
+
*`platforms\android\libs`: This directory contains any native Android libraries packaged as `*.jar` packages. During the plugin installation, the NativeScript CLI will copy these files to `lib\Android` in your project and will configure the Android project in `platforms\android` to work with the library. (remove suggestion)
106
+
*`platforms\android\MyAndroidLibrary`: This directory contains a native Android library with a `project.properties` file. During the plugin installation, the NativeScript CLI will copy these files to `lib\Android` in your project and will configure the Android project in `platforms\android` to work with the library. (remove suggestion)
100
107
*`platforms\ios`: This directory contains native iOS dynamic libraries (`.framework`). During the plugin installation, the NativeScript CLI will copy these files to `lib\iOS` in your project and will configure the Android project in `platforms\ios` to work with the library.
101
108
102
109
### Package.json Specification
@@ -124,6 +131,31 @@ The following is an example of a `package.json` file for a NativeScript plugin w
124
131
}
125
132
```
126
133
134
+
### Include.gradle Specification
135
+
136
+
* The include.gradle file must contain it's own configuration.
137
+
* The include.gradle file can optionally contain native dependencies it needs to build correctly.
138
+
* If you have native dependencies be sure they can be found in [jcenter](https://bintray.com/bintray/jcenter).
139
+
* If you haven't got an include.gradle file in the specified place, a default one will be created at build time, including all default elements.
140
+
141
+
#### Include.gradle Example
142
+
143
+
```
144
+
//default
145
+
android {
146
+
productFlavors {
147
+
"plugin-name" {
148
+
dimension "plugin-name"
149
+
}
150
+
}
151
+
}
152
+
153
+
//optional
154
+
dependencies {
155
+
compile "groupName:pluginName:ver"
156
+
}
157
+
```
158
+
127
159
## Install a Plugin
128
160
129
161
To install a plugin for your project, inside your project, run the following command.
@@ -148,15 +180,15 @@ The installation of a NativeScript plugin mimics the installation of an npm modu
148
180
149
181
The NativeScript CLI takes the plugin and installs it to the `node_modules` directory in the root of your project. During this process, the NativeScript CLI resolves any dependencies described in the plugin `package.json` file and adds the plugin to the project `package.json` file in the project root.
150
182
151
-
If the NativeScript CLI detects any native libraries in the plugin, it copies the library files to the `lib/<platform>` folder in your project and configures the platform-specific projects in `platforms/<platform>` to work with the library.
183
+
If the NativeScript CLI detects any native libraries in the plugin, it copies the library files to the `lib/<platform>` folder in your project and configures the platform-specific projects in `platforms/<platform>` to work with the library. (remove suggestion)
152
184
153
185
Next, the NativeScript CLI runs a partial `prepare` operation for the plugin for all platforms configured for the project. During this operation, the CLI copies only the plugin to the `tns_modules` subdirectories in the `platforms\android` and `platform\ios` directories in your project. If your plugin contains platform-specific `JS` files, the CLI copies them to the respective platform subdirectory and renames them by removing the platform modifier.
154
186
155
-
> **TIP:** If you have not configured any platforms, when you run `$ tns platform add`, the NativeScript CLI will automatically prepare all installed plugins for the selected platform.
187
+
> **TIP:** If you have not configured any platforms, when you run `$ tns platform add`, the NativeScript CLI will automatically prepare all installed plugins for the selected platform. (suggestion - remove or explain better)
156
188
157
-
Finally, the CLI merges the plugin `AndroidManifest.xml` and `Info.plist` files with `platforms\android\AndroidManifest.xml` and `platforms\ios\Info.plist` in your project.
189
+
Finally, the CLI merges the plugin `AndroidManifest.xml` and `Info.plist` files with `platforms\android\AndroidManifest.xml` and `platforms\ios\Info.plist` in your project. (remove suggestion - it doesn't merge anymore)
158
190
159
-
> **IMPORTANT:** Currently, the merging of the platform configuration files does not resolve any contradicting or duplicate entries.
191
+
> **IMPORTANT:** Currently, the merging of the platform configuration files does not resolve any contradicting or duplicate entries. (remove suggestion - it does with 1.5)
160
192
161
193
#### AndroidManifest.xml Merge Example
162
194
@@ -281,13 +313,13 @@ You must specify the plugin by the value for the `name` key in the plugin `packa
281
313
282
314
The removal of a NativeScript plugin mimics the removal of an npm module.
283
315
284
-
The NativeScript CLI removes any plugin files from the `node_modules` directory in the root of your project and removes any native Android libraries which have been added during the plugin installation. During this process, the NativeScript CLI removes any dependencies described in the plugin `package.json` file and removes the plugin from the project `package.json` file in the project root.
316
+
The NativeScript CLI removes any plugin files from the `node_modules` directory in the root of your project and removes any native Android libraries which have been added during the plugin installation (remove suggestion). During this process, the NativeScript CLI removes any dependencies described in the plugin `package.json` file and removes the plugin from the project `package.json` file in the project root.
285
317
286
-
> **IMPORTANT:** This operation does not remove files from the `platforms\android` and `platforms\ios` directories and native iOS libraries, and does not unmerge the `AndroidManifest.xml` and `Info.plist` files.
318
+
> **IMPORTANT:** This operation does not remove files from the `platforms\android` and `platforms\ios` directories and native iOS libraries, and does not unmerge the `AndroidManifest.xml` and `Info.plist` files. (remove suggestion - it does with 1.5)
287
319
288
320
### Manual Steps After Removal
289
321
290
-
After the plugin removal is complete, make sure to remove any leftover native library files from the `<lib>` directory in the root of the project.Update the platform-specific projects in `platforms\<platform>` to remove any dependencies on the removed native libraries.
322
+
After the plugin removal is complete, make sure to remove any leftover native library files from the `<lib>` directory in the root of the project.Update the platform-specific projects in `platforms\<platform>` to remove any dependencies on the removed native libraries. (remove suggestion)
291
323
292
324
Next, you need to run the following command.
293
325
@@ -299,6 +331,6 @@ Make sure to run the command for all platforms configured for the project. Durin
299
331
300
332
> **TIP:** Instead of `$ tns prepare` you can run `$ tns build`, `$ tns run`, `$ tns deploy` or `$ tns emulate`. All these commands run `$ tns prepare`.
301
333
302
-
Next, open your `platforms\android\AndroidManifest.xml` and `platforms\ios\Info.plist` files and remove any leftover entries from the plugin `AndroidManifest.xml` and `Info.plist` files.
334
+
Next, open your `platforms\android\AndroidManifest.xml` and `platforms\ios\Info.plist` files and remove any leftover entries from the plugin `AndroidManifest.xml` and `Info.plist` files. (remove suggestion)
303
335
304
336
Finally, make sure to update your code not to use the uninstalled plugin.
0 commit comments