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
+55-22
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,7 @@ A NativeScript plugin is any npm package, published or not, that exposes a nativ
24
24
* One or more CommonJS modules that expose a native API via a unified JavaScript API. For more information about Common JS modules, see the [CommonJS Wiki](http://wiki.commonjs.org/wiki/CommonJS).
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.
@@ -38,6 +39,7 @@ If the NativeScript framework does not expose a native API that you need, you ca
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-only) If the plugin depends on native libraries, it must contain a valid include.gradle file, which describes the dependencies.
41
43
42
44
### Directory Structure
43
45
@@ -49,6 +51,7 @@ my-plugin/
49
51
├── package.json
50
52
└── platforms/
51
53
├── android/
54
+
│ └── res/
52
55
│ └── AndroidManifest.xml
53
56
└── ios/
54
57
└── Info.plist
@@ -67,15 +70,18 @@ my-plugin/
67
70
│ └── package.json
68
71
└── platforms/
69
72
├── android/
73
+
│ └── res/
70
74
│ └── AndroidManifest.xml
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.
78
-
*`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.
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 build, gradle 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 modifies the native Android configuration of your NativeScript project. For example, native dependencies, build types and configurations. For more information about the format of `include.gradle`, see [include.gradle file](#includegradle-specification).
83
+
*`platforms/android/res`: (Optional) This directory contains resources declared by the `AndroidManifest.xml` file. You can look at the folder structure [here](http://developer.android.com/guide/topics/resources/providing-resources.html#ResourceTypes).
84
+
*`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
85
80
86
NativeScript plugins which contain both native Android and iOS libraries might have the following directory structure.
81
87
@@ -84,20 +90,20 @@ my-plugin/
84
90
├── ...
85
91
└── platforms/
86
92
├── android/
87
-
│ ├── libs/
88
-
│ │ └── MyLibrary.jar
89
-
│ ├── MyAndroidLibrary/
90
-
│ │ ├── ...
91
-
│ │ └── project.properties
93
+
│ └── res/
94
+
│ └── MyLibrary.jar
95
+
│ └── MyLibrary.aar
96
+
│ └── include.gradle
92
97
│ └── AndroidManifest.xml
93
98
└── ios/
94
99
├── MyiOSLibrary.framework
95
100
└── Info.plist
96
101
```
97
102
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.
100
-
*`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.
103
+
*`platforms/android`: This directory contains any native Android libraries packaged as `*.jar` and '*.aar' packages. These native libraries can reside in the root of this directory or in a user-created sub-directory. During the plugin installation, the NativeScript CLI will configure the Android project in `platforms/android` to work with the plugin.
104
+
*`platforms/android/res`: (Optional) This directory contains resources declared by the `AndroidManifest.xml` file. You can look at the folder structure [here](http://developer.android.com/guide/topics/resources/providing-resources.html#ResourceTypes).
105
+
*`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.
106
+
* `platforms/android/include.gradle': This file modifies the native Android configuration of your NativeScript project. For example, native dependencies, build types and configurations. For more information about the format of 'include.gradle', see [include.gradle file](#includegradle-specification).
101
107
102
108
### Package.json Specification
103
109
@@ -124,6 +130,33 @@ The following is an example of a `package.json` file for a NativeScript plugin w
124
130
}
125
131
```
126
132
133
+
### Include.gradle Specification
134
+
Every NativeScript plugin, which contains native Android dependencies, should contain a valid 'incluide.gradle' file in the root of its 'platforms/android' directory. This `include.gradle` file must meet the following requirements.
135
+
136
+
* It must contain its own configuration.
137
+
* It might contain native dependencies required to build the plugin properly.
138
+
* Any native dependencies should be available in [jcenter](https://bintray.com/bintray/jcenter) or from the Android SDK installed on your machine.
139
+
> **IMPORTANT:**[Link to all configurations](http://developer.android.com/tools/building/configuring-gradle.html).
140
+
141
+
> **IMPORTANT:** If you don't have an `include.gradle` file, at build time, gradle will create a default one containing all default elements.
142
+
143
+
#### Include.gradle Example
144
+
```
145
+
//default elements
146
+
android {
147
+
productFlavors {
148
+
"my-plugin" {
149
+
dimension "my-plugin"
150
+
}
151
+
}
152
+
}
153
+
154
+
//optional elements
155
+
dependencies {
156
+
compile "groupName:pluginName:ver"
157
+
}
158
+
```
159
+
127
160
## Install a Plugin
128
161
129
162
To install a plugin for your project, inside your project, run the following command.
@@ -148,13 +181,13 @@ The installation of a NativeScript plugin mimics the installation of an npm modu
148
181
149
182
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
183
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.
184
+
If the NativeScript CLI detects any native iOS libraries in the plugin, it copies the library files to the `lib/ios` folder in your project and configures the iOS-specific projects in `platforms/ios` to work with the library.
152
185
153
-
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.
186
+
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
187
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.
188
+
> **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 newly added platform.
156
189
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.
190
+
Finally, the CLI merges the plugin `Info.plist` file with `platforms/ios/Info.plist`in your project. The plugin `AndroidManifest.xml`will be merged with `platforms/android/AndroidManifest.xml` later, at build time.
158
191
159
192
> **IMPORTANT:** Currently, the merging of the platform configuration files does not resolve any contradicting or duplicate entries.
160
193
@@ -182,7 +215,7 @@ The following is an example of a plugin `AndroidManifest`, project `AndroidManif
182
215
</manifest>
183
216
```
184
217
185
-
**The Project Manifest Located in `platforms\android\`**
218
+
**The Project Manifest Located in `platforms/android/`**
186
219
187
220
```XML
188
221
<?xml version="1.0" encoding="utf-8"?>
@@ -220,7 +253,7 @@ The following is an example of a plugin `AndroidManifest`, project `AndroidManif
220
253
</manifest>
221
254
```
222
255
223
-
**The Merged Manifest Located in `platforms\android\`**
256
+
**The Merged Manifest Located in `platforms/android/`**
224
257
225
258
```XML
226
259
<?xml version="1.0" encoding="utf-8"?>
@@ -255,7 +288,7 @@ The following is an example of a plugin `AndroidManifest`, project `AndroidManif
255
288
256
289
### Manual Steps After Installation
257
290
258
-
After the installation is complete, you need to open `platforms\android\AndroidManifest.xml` and `platforms\ios\Info.plist` in your project and inspect them for duplicate or contradicting entries. Make sure to preserve the settings required by the plugin. Otherwise, your app might not build or it might not work as expected, when deployed on device.
291
+
After the installation is complete, you need to open `platforms/android/AndroidManifest.xml` and `platforms/ios/Info.plist` in your project and inspect them for duplicate or contradicting entries. Make sure to preserve the settings required by the plugin. Otherwise, your app might not build or it might not work as expected, when deployed on device.
259
292
260
293
## Use a Plugin
261
294
@@ -281,24 +314,24 @@ You must specify the plugin by the value for the `name` key in the plugin `packa
281
314
282
315
The removal of a NativeScript plugin mimics the removal of an npm module.
283
316
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.
317
+
The NativeScript CLI removes any plugin files from the `node_modules` directory in the root of your project. 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
318
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.
319
+
> **IMPORTANT:**For iOS, this operation does not remove files from the `platforms/ios` directories and native iOS libraries, and does not unmerge the `Info.plist` file. For Android, this operation unmerges the `AndroidManifest.xml` file and takes care of removing any plugin files located in 'platforms/android'.
287
320
288
321
### Manual Steps After Removal
289
322
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.
323
+
After the plugin removal is complete, make sure to remove any leftover native iOS library files from the `lib/ios` directory in the root of the project.Update the iOS-specific projects in `platforms/ios` to remove any dependencies on the removed native libraries.
291
324
292
325
Next, you need to run the following command.
293
326
294
327
```Shell
295
328
tns prepare <Platform>
296
329
```
297
330
298
-
Make sure to run the command for all platforms configured for the project. During this operation, the NativeScript CLI will remove any leftover plugin files from your `platforms\android` and `platforms\ios`directories.
331
+
Make sure to run the command for all platforms configured for the project. During this operation, the NativeScript CLI will remove any leftover plugin files from your `platforms/ios`directory.
299
332
300
333
> **TIP:** Instead of `$ tns prepare` you can run `$ tns build`, `$ tns run`, `$ tns deploy` or `$ tns emulate`. All these commands run `$ tns prepare`.
301
334
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.
335
+
Next, open your `platforms/ios/Info.plist`file and remove any leftover entries from the plugin `Info.plist`file.
303
336
304
337
Finally, make sure to update your code not to use the uninstalled plugin.
0 commit comments