|
| 1 | +PLUGINS |
| 2 | +========= |
| 3 | + |
| 4 | +NativeScript plugin is a npm package that consist of the following: |
| 5 | + |
| 6 | +* Metadata about the package itself: name, version, supported runtime versions, etc. |
| 7 | +* CommonJS module(one or many) that expose the native API via a single JavaScript API. |
| 8 | +* Native libraries and resources. |
| 9 | + |
| 10 | +A package json file has the following structure: |
| 11 | +``` |
| 12 | +{ |
| 13 | + "name": "myplugin", |
| 14 | + "version": "0.0.1", |
| 15 | + "nativescript": { |
| 16 | + "platforms": { |
| 17 | + "ios": "1.0.0", |
| 18 | + "android": "1.1.0" |
| 19 | + } |
| 20 | + } |
| 21 | +} |
| 22 | +``` |
| 23 | +`nativescript` key is a mandatory section for a NativeScript plugin. `platforms` section describes the supported runtime versions for each platform. |
| 24 | + |
| 25 | +A plugin directory has the following structure: |
| 26 | +``` |
| 27 | +myPlugin/ |
| 28 | +-- index.js |
| 29 | +-- package.json |
| 30 | +-- platforms |
| 31 | + -- Android |
| 32 | + -- myjar.jar |
| 33 | + -- Android.manifest |
| 34 | + -- iOS |
| 35 | + -- myFramework.framework |
| 36 | + -- Info.plist |
| 37 | +``` |
| 38 | + |
| 39 | +You can use `platforms` folder and place platform specific files in each platform directory. |
| 40 | + |
| 41 | +Here is an example. |
| 42 | + |
| 43 | +Let you say that you have the following `Android.manifest` file in `platforms\android\` folder in your plugin: |
| 44 | +``` |
| 45 | +<?xml version="1.0" encoding="UTF-8"?> |
| 46 | +<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 47 | + package="com.example.android.basiccontactables" |
| 48 | + android:versionCode="1" |
| 49 | + android:versionName="1.0" > |
| 50 | + |
| 51 | + <uses-sdk |
| 52 | + android:minSdkVersion="19" |
| 53 | + android:targetSdkVersion="21" /> |
| 54 | + |
| 55 | + <uses-permission android:name="android.permission.READ_CONTACTS"/> |
| 56 | + <uses-permission android:name="android.permission.INTERNET" /> |
| 57 | + <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> |
| 58 | + <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> |
| 59 | + <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> |
| 60 | + <uses-permission android:name="com.example.towntour.permission.MAPS_RECEIVE" /> |
| 61 | + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> |
| 62 | + <uses-permission android:name="android.permission.CALL_PHONE" /> |
| 63 | + <uses-permission android:name="android.permission.READ_PHONE_STATE" /> |
| 64 | + <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> |
| 65 | +
|
| 66 | + <application |
| 67 | + android:name="com.tns.NativeScriptApplication" |
| 68 | + android:allowBackup="true" |
| 69 | + android:icon="@drawable/icon" |
| 70 | + android:label="@string/app_name" |
| 71 | + android:theme="@style/AppTheme" > |
| 72 | + <activity |
| 73 | + android:name="com.tns.NativeScriptActivity" |
| 74 | + android:label="@string/title_activity_kimera" |
| 75 | + android:configChanges="keyboardHidden|orientation|screenSize"> |
| 76 | + |
| 77 | + <intent-filter> |
| 78 | + <action android:name="android.intent.action.MAIN" /> |
| 79 | + <action android:name="android.intent.action.EDIT" /> |
| 80 | + <action android:name="android.intent.action.VIEW" /> |
| 81 | +
|
| 82 | + <category android:name="android.intent.category.LAUNCHER" /> |
| 83 | + </intent-filter> |
| 84 | + </activity> |
| 85 | + </application> |
| 86 | + |
| 87 | +</manifest> |
| 88 | +``` |
| 89 | + |
| 90 | +and the default `Android.manifest` file in your app in `platforms\android\` folder. |
| 91 | +``` |
| 92 | +<?xml version="1.0" encoding="utf-8"?> |
| 93 | +<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 94 | + package="org.nativescript.test" |
| 95 | + android:versionCode="1" |
| 96 | + android:versionName="1.0" > |
| 97 | +
|
| 98 | + <uses-sdk |
| 99 | + android:minSdkVersion="17" |
| 100 | + android:targetSdkVersion="17" /> |
| 101 | + |
| 102 | + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> |
| 103 | + <uses-permission android:name="android.permission.INTERNET"/> |
| 104 | + |
| 105 | + <application |
| 106 | + android:name="com.tns.NativeScriptApplication" |
| 107 | + android:allowBackup="true" |
| 108 | + android:icon="@drawable/icon" |
| 109 | + android:label="@string/app_name" |
| 110 | + android:theme="@style/AppTheme" > |
| 111 | + <activity |
| 112 | + android:name="com.tns.NativeScriptActivity" |
| 113 | + android:label="@string/title_activity_kimera" |
| 114 | + android:configChanges="keyboardHidden|orientation|screenSize"> |
| 115 | + |
| 116 | + <intent-filter> |
| 117 | + <action android:name="android.intent.action.MAIN" /> |
| 118 | +
|
| 119 | + <category android:name="android.intent.category.LAUNCHER" /> |
| 120 | + </intent-filter> |
| 121 | + </activity> |
| 122 | + </application> |
| 123 | +
|
| 124 | +</manifest> |
| 125 | +``` |
| 126 | + |
| 127 | +The produced result xml will be: |
| 128 | +``` |
| 129 | +<?xml version="1.0" encoding="utf-8"?> |
| 130 | +<manifest |
| 131 | + xmlns:android="http://schemas.android.com/apk/res/android" package="org.nativescript.test" android:versionCode="1" android:versionName="1.0"> |
| 132 | + <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="21"/> |
| 133 | + <uses-permission android:name="android.permission.READ_CONTACTS"/> |
| 134 | + <uses-permission android:name="android.permission.INTERNET"/> |
| 135 | + <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> |
| 136 | + <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/> |
| 137 | + <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> |
| 138 | + <uses-permission android:name="com.example.towntour.permission.MAPS_RECEIVE"/> |
| 139 | + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
| 140 | + <uses-permission android:name="android.permission.CALL_PHONE"/> |
| 141 | + <uses-permission android:name="android.permission.READ_PHONE_STATE"/> |
| 142 | + <!-- |
| 143 | + Some comment here |
| 144 | + --> |
| 145 | + <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> |
| 146 | + <application android:name="com.tns.NativeScriptApplication" android:allowBackup="true" android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/AppTheme"> |
| 147 | + <activity android:name="com.tns.NativeScriptActivity" android:label="@string/title_activity_kimera" android:configChanges="keyboardHidden|orientation|screenSize"> |
| 148 | + <intent-filter> |
| 149 | + <action android:name="android.intent.action.MAIN"/> |
| 150 | + <action android:name="android.intent.action.EDIT"/> |
| 151 | + <action android:name="android.intent.action.VIEW"/> |
| 152 | + <category android:name="android.intent.category.LAUNCHER"/> |
| 153 | + </intent-filter> |
| 154 | + </activity> |
| 155 | + </application> |
| 156 | +</manifest> |
| 157 | +``` |
| 158 | + |
| 159 | + |
0 commit comments