Skip to content

Commit 4b73906

Browse files
committed
after review with iva
1 parent 1effa72 commit 4b73906

File tree

1 file changed

+39
-36
lines changed

1 file changed

+39
-36
lines changed

PLUGINS.md

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ If the NativeScript framework does not expose a native API that you need, you ca
3939
* The plugin directory structure must comply with the specification described below.
4040
* The plugin must contain a valid `package.json` which complies with the specification described below.
4141
* 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)
42+
* (Android-only) If the plugin depends on native libraries, it must contain a valid include.gradle file, which describes the dependencies.
4343

4444
### Directory Structure
4545

@@ -51,7 +51,7 @@ my-plugin/
5151
├── package.json
5252
└── platforms/
5353
├── android/
54-
│ └── res/ (suggestion) + link
54+
│ └── res/
5555
│ └── AndroidManifest.xml
5656
└── ios/
5757
└── Info.plist
@@ -70,17 +70,18 @@ my-plugin/
7070
│ └── package.json
7171
└── platforms/
7272
├── android/
73-
│ └── res/ (suggestion) + link
73+
│ └── res/
7474
│ └── AndroidManifest.xml
7575
└── ios/
7676
└── Info.plist
7777
```
7878

7979
* `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).
8080
* `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.
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 build phase, the gradle build system will merge the plugin `AndroidManifest.xml` with the `AndroidManifest.xml` for your project (suggestion). 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). (suggestion)
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.
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': todo: add link
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.
8485

8586
NativeScript plugins which contain both native Android and iOS libraries might have the following directory structure.
8687

@@ -89,18 +90,20 @@ my-plugin/
8990
├── ...
9091
└── platforms/
9192
├── android/
92-
│ └── res/ (suggestion) + link
93-
│ └── MyLibrary.jar (add suggestion)
94-
│ └── MyLibrary.aar (suggestion)
95-
│ └── include.gradle (add suggestion)
93+
│ └── res/
94+
│ └── MyLibrary.jar
95+
│ └── MyLibrary.aar
96+
│ └── include.gradle
9697
│ └── AndroidManifest.xml
9798
└── ios/
9899
├── MyiOSLibrary.framework
99100
└── Info.plist
100101
```
101102

102-
* `platforms\android`: This directory contains any native Android libraries packaged as `*.jar` and '*.aar' packages. This directory can also contain res/ folder which contains all resources declared by the AndroidManifest.xml file. During the plugin installation, NativeScript CLI will configure the Android project in `platforms\android` to work with the plugin. (suggestion)
103-
* `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. todo: add link
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).
104107

105108
### Package.json Specification
106109

@@ -128,26 +131,28 @@ The following is an example of a `package.json` file for a NativeScript plugin w
128131
```
129132

130133
### Include.gradle Specification
131-
(suggestion)
132-
* The include.gradle file must contain it's own configuration.
133-
* The include.gradle file can optionally contain native dependencies it needs to build correctly.
134-
* If you have native dependencies be sure they can be found in [jcenter](https://bintray.com/bintray/jcenter) or as a default libraries on your machine (e.g. recycler view from sdk).
135-
* 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.
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.
136135

136+
* It must contain its own configuration (todo: link if you find).
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+
* todo: add link for android configuration
140+
* todo: add link dependencies configuration
141+
142+
> **IMPORTANT:** If you don't have an `include.gradle` file, at build time, gradle will create a default one containing all default elements.
143+
137144
#### Include.gradle Example
138-
(suggestion)
139145
```
140-
//default
141-
(android plugin for gradle specification link)
146+
//default elements
142147
android {
143148
productFlavors {
144-
"plugin-name" {
145-
dimension "plugin-name"
149+
"my-plugin" {
150+
dimension "my-plugin"
146151
}
147152
}
148153
}
149154
150-
//optional
155+
//optional elements
151156
dependencies {
152157
compile "groupName:pluginName:ver"
153158
}
@@ -177,13 +182,13 @@ The installation of a NativeScript plugin mimics the installation of an npm modu
177182

178183
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.
179184

180-
If the NativeScript CLI detects any native libraries in the plugin, (suggestion: must change only for ios) 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.
185+
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.
181186

182-
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.
187+
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.
183188

184-
> **TIP:** If you have not configured any platforms, when you run `$ tns platform add`, the NativeScript CLI will automatically prepare all installed plugins for any newly selected platform. (suggestion - explain better)
189+
> **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.
185190
186-
Finally, the CLI merges the plugin `Info.plist` file with `platforms\ios\Info.plist` in your project. Not necessary for android. (suggestion)
191+
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.
187192

188193
> **IMPORTANT:** Currently, the merging of the platform configuration files does not resolve any contradicting or duplicate entries.
189194
@@ -211,7 +216,7 @@ The following is an example of a plugin `AndroidManifest`, project `AndroidManif
211216
</manifest>
212217
```
213218

214-
**The Project Manifest Located in `platforms\android\`**
219+
**The Project Manifest Located in `platforms/android/`**
215220

216221
```XML
217222
<?xml version="1.0" encoding="utf-8"?>
@@ -249,7 +254,7 @@ The following is an example of a plugin `AndroidManifest`, project `AndroidManif
249254
</manifest>
250255
```
251256

252-
**The Merged Manifest Located in `platforms\android\`**
257+
**The Merged Manifest Located in `platforms/android/`**
253258

254259
```XML
255260
<?xml version="1.0" encoding="utf-8"?>
@@ -284,7 +289,7 @@ The following is an example of a plugin `AndroidManifest`, project `AndroidManif
284289

285290
### Manual Steps After Installation
286291

287-
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.
292+
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.
288293

289294
## Use a Plugin
290295

@@ -312,24 +317,22 @@ The removal of a NativeScript plugin mimics the removal of an npm module.
312317

313318
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.
314319

315-
> **IMPORTANT:** This operation does not remove files from the `platforms\ios` directories and native iOS libraries, and does not unmerge the `Info.plist` file. Regarding android, NativeScript CLI unmerges the AndroidManifest.xml file and takes care of removing any files located in 'platforms\android' concerning the plugin being removed. (suggestion android)
320+
> **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'.
316321
317322
### Manual Steps After Removal
318323

319-
//valid only for ios (suggestion)
320-
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. (only ios)
324+
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.
321325

322326
Next, you need to run the following command.
323327

324328
```Shell
325329
tns prepare <Platform>
326330
```
327331

328-
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.
332+
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.
329333

330334
> **TIP:** Instead of `$ tns prepare` you can run `$ tns build`, `$ tns run`, `$ tns deploy` or `$ tns emulate`. All these commands run `$ tns prepare`.
331335
332-
(suggestion: the following is optional for android)
333-
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.
336+
Next, open your `platforms/ios/Info.plist` file and remove any leftover entries from the plugin `Info.plist` file.
334337

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

0 commit comments

Comments
 (0)