Skip to content

Commit 8c039d0

Browse files
committed
updated plugins.md docs
1 parent 7217af9 commit 8c039d0

File tree

1 file changed

+49
-17
lines changed

1 file changed

+49
-17
lines changed

PLUGINS.md

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ A NativeScript plugin is any npm package, published or not, that exposes a nativ
2525
* `AndroidManifest.xml` and `Info.plist` which describe the permissions, features or other configurations required or used by your app for Android and iOS, respectively.
2626
* (Optional) Native Android libraries.
2727
* (Optional) Native iOS dynamic libraries.
28+
* (Optional) Android include.gradle configurations file. (sugestion)
2829

2930
The plugin must have the directory structure, described in the [Directory Structure](#directory-structure) section.
3031

@@ -33,11 +34,12 @@ The plugin must have the directory structure, described in the [Directory Struct
3334
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.
3435

3536
* 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")
3738
* 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.
3839
* The plugin directory structure must comply with the specification described below.
3940
* The plugin must contain a valid `package.json` which complies with the specification described below.
4041
* 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)
4143

4244
### Directory Structure
4345

@@ -50,6 +52,7 @@ my-plugin/
5052
└── platforms/
5153
├── android/
5254
│ └── AndroidManifest.xml
55+
│ └── include.gradle (suggestion)
5356
└── ios/
5457
└── Info.plist
5558
```
@@ -68,13 +71,15 @@ my-plugin/
6871
└── platforms/
6972
├── android/
7073
│ └── AndroidManifest.xml
74+
│ └── include.gradle (suggestion)
7175
└── ios/
7276
└── Info.plist
7377
```
7478

7579
* `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).
7680
* `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)
7883
* `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.
7984

8085
NativeScript plugins which contain both native Android and iOS libraries might have the following directory structure.
@@ -84,19 +89,21 @@ my-plugin/
8489
├── ...
8590
└── platforms/
8691
├── 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)
9299
│ └── AndroidManifest.xml
93100
└── ios/
94101
├── MyiOSLibrary.framework
95102
└── Info.plist
96103
```
97104

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)
100107
* `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.
101108

102109
### Package.json Specification
@@ -124,6 +131,31 @@ The following is an example of a `package.json` file for a NativeScript plugin w
124131
}
125132
```
126133

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+
127159
## Install a Plugin
128160

129161
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
148180

149181
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.
150182

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)
152184

153185
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.
154186

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)
156188
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)
158190

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)
160192
161193
#### AndroidManifest.xml Merge Example
162194

@@ -281,13 +313,13 @@ You must specify the plugin by the value for the `name` key in the plugin `packa
281313

282314
The removal of a NativeScript plugin mimics the removal of an npm module.
283315

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.
285317

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)
287319
288320
### Manual Steps After Removal
289321

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)
291323

292324
Next, you need to run the following command.
293325

@@ -299,6 +331,6 @@ Make sure to run the command for all platforms configured for the project. Durin
299331

300332
> **TIP:** Instead of `$ tns prepare` you can run `$ tns build`, `$ tns run`, `$ tns deploy` or `$ tns emulate`. All these commands run `$ tns prepare`.
301333
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)
303335

304336
Finally, make sure to update your code not to use the uninstalled plugin.

0 commit comments

Comments
 (0)