Skip to content

Latest commit

 

History

History
192 lines (175 loc) · 8.36 KB

08.Plugin.xml Guide(Plugin配置文件指南).md

File metadata and controls

192 lines (175 loc) · 8.36 KB

翻译自cordova官方文档(如果需要链接,请自行对照原文链接进行查看): https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html

Plugin.xml

Plugin.xml是用于设置你得插件,他包含很多元素为你的插件提供详细的设置。

	<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
			   id="cordova-plugin-splashscreen"
		  version="3.2.0">
	<!--
		plugin 标签是Plugin配置文件最顶层的元素
			xmlns:用于指定命名空间(namespace),当然也可以指定针对特定平台的命名空间比如
		        xmlns:android="http://schemas.android.com/apk/res/android"
		   	   id:用于设置plugin的识别id
          version:plugin的版本号
	-->
	
		<name>Splashscreen</name>
		<!--
			用于为plugin设定一个名字。
		-->
		
		<description>Cordova Splashscreen Plugin</description>
		<!--
			plugin的描述或者说明
		-->
		
		<license>Apache 2.0</license>
		<!--
			为plugin指定使用哪种开源许可license
		-->
		
		<keywords>cordova,splashscreen</keywords>
		<!--
			使用逗号分割,用于描述plugin的关键字。
		-->
		
		<author>Foo plugin author</author>
		<!--
			用于设置作者信息。
			# 这个是为了解释这个标签特地加入的,并不是splashscreen插件带的。
		-->
		
		<asset src="www/new-foo.js" target="js/experimental/foo.js" />
		<!--
			将特定js文件拷贝到工程指定目录。并且可以重命名。
			# 这个是为了解释这个标签特地加入的,并不是splashscreen插件带的。
		-->
		
		<repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen.git</repo>
		<!--
			plugin的描述或者说明
		-->
		
		<issue>https://issues.apache.org/jira/browse/CB/component/12320653</issue>

		<dependency id="cordova-plugin-someplugin" url="https://github.com/myuser/someplugin" commit="428931ada3891801" subdir="some/path/here" />
	    <dependency id="cordova-plugin-someplugin" version="1.0.1">
	    <!--
			用于声明该plugin会依赖其他plugin,通过id或者是url来指定依赖plugin的源。
		-->
		
		<engines>
			<engine name="cordova-android" version=">=3.6.0" /><!-- Requires CordovaPlugin.preferences -->
		</engines>
		<!--
			engines用于设置plugin适用的平台镜像版本
			engine用于设置具体支持的版本,name用于指定镜像平台,version用于设置版本号
			,如果不设置默认支持全平台全版本
			目前cordova支持的平台主要如下:
			.cordova
			.cordova-plugman
			.cordova-android
			.cordova-ios
			.cordova-blackberry10
			.cordova-wp8
			.cordova-windows
			.cordova-osx
			.windows-os
			.android-sdk (returns the highest Android api level installed)
			.windows-sdk (returns the native windows SDK version)
			.apple-xcode (returns the xcode version)
			.apple-ios (returns the highest iOS version installed)
			.apple-osx (returns the OSX version)
			.blackberry-ndk (returns the native blackberry SDK version)
		-->
		
		<js-module src="www/splashscreen.js" name="SplashScreen">
			<clobbers target="navigator.splashscreen" />
		</js-module>
		<!--
			js-module标签一般用于发布定义js接口的js文件。本例中,将www/splashscreen.js文件中定义的接口发布到
			window.navigator.splashscreen对象上,这样web端可以直接通过navigator.splashscreen对象来访问plugin
			的api。如果想替换掉window对象上指定接口还可以通过以下方式:
			<js-module src="socket.js" name="Socket">
				<merges target="chrome.socket" />
				# 使用merges标签,如果chrome.socket存在,那么用此plugin内的chrome.socket替换掉原有的。
			</js-module>
			<js-module src="socket.js" name="Socket">
				<runs/>
				# 使用runs标签你代码需要通过cordova.require去指定,并且不是安装到window对象上。
				这个标签用于安装模块或者是其他的时候使用。该标签和<clobbers/>或者<merges/>一起使用是多余的。
			</js-module>
		-->

		<!--
		platform用于指定plugin安装到哪些平台,这里主要介绍android和ios,如果没有指定平台,那么cordova会把plugin看
		做只提供javascript接口的plugin。
		         name:用于指定平台名字。
		  source-file:用于告诉plugin把config-file包含的内容安装到target里面。或者是target-dir里面。
		  header-file:同样也是用来将指定文件拷贝到指定目录下。
		resource-file:同样也是用于拷贝文件,不同的是这个配置用于拷贝非代码资源。
			      <resource-file src="FooPluginStrings.xml" target="res/values/FooPluginStrings.xml" />
		  config-file:指定需要设置的配置文件爱你,比如xml或者plist,添加进去的内容必须以xml的格式设置。
			      具体参见下面例子代码。其中parent用于指定在哪一个父元素下添加。
		plugins-plist:已经过时了。现在使用<config-file>来替代。
		     lib-file: 用于添加依赖包。
		             <lib-file src="src/BlackBerry10/native/device/libfoo.so" arch="device" />
		             src用于指定plugin下的文件路径,arch用于设置依赖包需要的架构比如x86,x64,
		             device-target用于设置目标设备win,phone,all.
		   framework:用于引入一个依赖framework。
			      <framework src="libsqlite3.dylib" />
			      <framework src="com.google.android.gms:play-services-gcm:+" />
			      <framework src="relative/path/rules.gradle" custom="true" type="gradleReference" />
			      <framework src="path/to/project/LibProj.csproj" custom="true" type="projectReference"/>
			      <framework src="src/windows/example.dll" arch="x64" />
		        info:提供一些额外信息。说明信息之类的。
		        hook:用于设置在cordova某些命令执行后需要执行的脚本比如
    		             <hook type="after_plugin_install" src="scripts/afterPluginInstall.js" />	
    		             具体参照[Hooks](https://cordova.apache.org/docs/en/latest/guide/appdev/hooks/index.html)
    	     uses-permission:用来声明plugin需要申请的权限,比如:
    			     <uses-permission android:name="my-app-id.permission.C2D_MESSAGE"/>
	          preference:用于在安装plugin的时候check用户设置的变量,如果变量的内容不正确,显示警告信息
			     <preference name="API_KEY" default="default-value" />
			     比如在statusbar插件中的设置
			     <config-file target="config.xml" parent="/*">
					<feature name="StatusBar">
						<param name="ios-package" value="CDVStatusBar" />
						<param name="onload" value="true" />
					</feature>
					<preference name="StatusBarOverlaysWebView" value="true" />
					<preference name="StatusBarStyle" value="lightcontent" />
			     </config-file>
		-->
		<!-- android -->
		<platform name="android">
			<!-- 修改AndroidManifest.xml文件 
		        <config-file target="AndroidManifest.xml" parent="/manifest">
		             <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
		        </config-file>-->
			<config-file target="res/xml/config.xml" parent="/*">
				<!--在androidn的config.xml中添加feature内的配置信息-->
				<feature name="SplashScreen">
					<param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen"/>
					<param name="onload" value="true"/>
				</feature>
			</config-file>
			<!--将指定文件安装到target-dir的位置-->
			<source-file src="src/android/SplashScreen.java" target-dir="src/org/apache/cordova/splashscreen" />
			<!--将依赖的jar添加到系统-->
            		<!--<source-file src="plugin_path/**.jar" target-dir="libs" />-->
		</platform>
		
		<!-- ios -->
		<platform name="ios">
			<config-file target="config.xml" parent="/*">
				<!--在config.xml中添加feature内的配置信息-->
				<feature name="SplashScreen">
					<param name="ios-package" value="CDVSplashScreen"/>
					<param name="onload" value="true"/>
				</feature>
			</config-file>
			<!--为了举例添加的例子代码-->
			<config-file target="helloworld-Info.plist" parent="CFBundleURLTypes">
				  <array>
					  <dict>
						  <key>PackageName</key>
						  <string>$PACKAGE_NAME</string>
					  </dict>
				  </array>
			</config-file>

			<header-file src="src/ios/CDVSplashScreen.h" />
			<source-file src="src/ios/CDVSplashScreen.m" />
			<header-file src="src/ios/CDVViewController+SplashScreen.h" />
			<source-file src="src/ios/CDVViewController+SplashScreen.m" />

			<framework src="CoreGraphics.framework" />
		</platform>
	</plugin>