Sqlite 通过定义自定义插件',通过cmd行在Windows10Cordova项目中添加Windows运行时组件(包装类库);s xml不';行不通
我用cordova命令行创建了一个Windows通用项目。(创建新项目,添加平台Sqlite 通过定义自定义插件',通过cmd行在Windows10Cordova项目中添加Windows运行时组件(包装类库);s xml不';行不通,sqlite,cordova,uwp,windows-10,cordova-plugins,Sqlite,Cordova,Uwp,Windows 10,Cordova Plugins,我用cordova命令行创建了一个Windows通用项目。(创建新项目,添加平台windows) 构建项目并从cmd行运行它。很好 我的要求是创建自己的自定义插件,并通过npm命令行安装它 我的项目还需要使用Windows运行时组件访问本机代码 我在Visual Studio 2015中打开了上述项目 然后我添加了一个Windows运行时组件,还添加了Newtonsoft库()。我添加了以下服务类: public sealed class Service { public IAsyncO
windows
)
构建项目并从cmd行运行它。很好
我的要求是创建自己的自定义插件,并通过npm命令行安装它
我的项目还需要使用Windows运行时组件访问本机代码
我在Visual Studio 2015中打开了上述项目
然后我添加了一个Windows运行时组件,还添加了Newtonsoft库()。我添加了以下服务类:
public sealed class Service
{
public IAsyncOperation<string> Open(string param)
{
return OpenHelper(param).AsAsyncOperation();
}
private async Task<string> OpenHelper(string param)
{
try
{
JObject jObj = JObject.Parse(JArray.Parse(param)[0].ToString());
string message = jObj["message"].ToString();
return message;
}
catch (Exception ex)
{
return "fail";
}
}
}
在我的index.js中,我在设备就绪事件中调用了以下方法:
launcher.openFile(function (message) {
Windows.UI.Popups.MessageDialog(message).showAsync();
console.log(message);
}, function () {
});
仅供参考:我的自定义插件**\www**中的launcher.js也有以下代码结构:
cordova.define("cordova-test-plugin.Launcher", function(require, exports, module) {
var objWindowsLauncher = {
openFile: function(successCallback, errorCallback) {
cordova.exec(
successCallback,
errorCallback,
'LauncherProxy',
'open',
[{
"message": "Hello test message"
}]
);
}
}
module.exports = objWindowsLauncher;
});
到目前为止,它运作良好。当应用程序运行时,它会弹出“你好”测试消息
现在我为SQLite添加了一个新的类库项目。安装了SQLite网(包括SQLITE CS和SQLASTYNC.CS文件,从旧项目),添加NeNtOff.JSON DLL,SQLite为通用Windows平台,Visual C++ 2015运行时通用Windows平台。
通过右键单击引用并选择SQLite项目,将此SQLite引用(类库)添加到我以前的运行时组件项目中。
通过这样做,现在我可以在运行时组件中执行sqlite操作。我构建了这个运行时组件,因此它的新.winmd文件是在bin\x86\Debug中生成的。我复制了这个winmd文件,并将其放在我的自定义插件文件夹中,如上所述
我删除了插件,并重新添加了插件(cmdline安装),如上所述。这一次,项目应该和之前一样工作,但不工作
它抛出一个异常。
System.IO.FileNotFoundException:无法加载文件或程序集“SQLite,版本=1.0.0.0,区域性=中性,PublicKeyToken=null”或其依赖项之一。系统找不到指定的文件。
在MyRuntime.Service.d\u 1.MoveNext()上运行
在System.Runtime.CompilerServices.AsyncTaskMethodBuilder 1.启动[TStateMachine](TStateMachine&stateMachine)
另一种情况:
有时,我会在上述过程中遇到这种例外情况:
无法加载文件或程序集“Newtonsoft.Json,Version=9.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6eed”或其依赖项之一
信息
所有项目构建配置都在x86下
Newtonsoft的版本是:9.0.1,10.x.x
Cordova Windows 10项目、运行时组件和类库有:10.0.14393.0(目标版本)和10.0.10240.0(最低版本)
Cordova版本:7.0.1
Cordova Windows版本:5.0.0
插件安装和删除cmd:
cordova插件移除cordova测试插件
cordova插件添加..\plugins\cordova测试插件
我在这里与自定义插件共享了完整的项目
另外,我可以手动添加运行时组件引用并使其正常工作,但我想使用cmd-line接口,安装pluigns,从cmd-line接口构建和生成包,而无需与Visual Studio交互
请让我知道你的观点,我记得几个月前我开始工作的时候,它曾经工作过。(通过在plugin.xml(
)中定义.winmd文件,从cmd行添加引用)。它过去工作得很好。但最近我面临上述问题
更新1
我按照“猫王夏”的建议试过了。这似乎可以按预期加载运行时组件。我包括所有这些:
在my plugin.xml中,通过cmd行安装插件。创建SQLite数据库时仍然存在一些错误。我遇到system.dllnotfoundexception无法加载dll“sqlite3”
错误,原因如下:
问题是,SQLite.dll
和NewtonJson.dll
也应该作为参考添加到插件中。因此,您的plugin.xml应该如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-test-plugin"
version="0.1.0">
<name>Launcher</name>
<description>PhoneGap Plugin</description>
<license>MIT</license>
<keywords>phonegap,launcher</keywords>
<js-module src="www/launcher.js" name="Launcher">
<clobbers target="window.launcher" />
</js-module>
<!-- windows -->
<platform name="windows">
<js-module src="src/windows/Launcher.js" name="LauncherProxy">
<merges target="" />
</js-module>
<!-- <framework src="src/windows/lib/MyRuntime.winmd" custom="true" /> -->
<framework src="src/windows/lib/SQLite.dll" custom="true"/>
<framework src="src/windows/lib/MyRuntime.winmd" custom="true" />
<framework src="src/windows/lib/Newtonsoft.Json.dll" custom="true"/>
</platform>
</plugin>
发射装置
PhoneGap插件
麻省理工学院
phonegap,启动器
并将bin\x86\debug\
文件夹下的SQLite.dll
和Newtonsoft.Json.dll
复制到插件的src/windows/lib/
中。然后它就可以正常工作了。嗨,Elvis,你能告诉我在哪里可以找到SQLite.dll文件吗?这就是你获取MyRuntime.winmd.Hi@Elvis Xia的文件夹,我已经按照你的建议尝试过了。在我的plugin.xml文件中包含所有这些DLL。它似乎加载了运行时组件方法和Newtonsoft.dll,但在创建数据库时,仍然无法加载dll“sqlite3”
。我在上面的问题中添加了“更新1”。我是否仍然缺少plugin.xml文件中要包含的内容?我不知道您当前使用的是哪个SQLite库,但它显然依赖于sqlite3.dll
。您还需要找到dll
,并将其作为框架添加到plugin.xml
中。
cordova.define("cordova-test-plugin.Launcher", function(require, exports, module) {
var objWindowsLauncher = {
openFile: function(successCallback, errorCallback) {
cordova.exec(
successCallback,
errorCallback,
'LauncherProxy',
'open',
[{
"message": "Hello test message"
}]
);
}
}
module.exports = objWindowsLauncher;
});
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-test-plugin"
version="0.1.0">
<name>Launcher</name>
<description>PhoneGap Plugin</description>
<license>MIT</license>
<keywords>phonegap,launcher</keywords>
<js-module src="www/launcher.js" name="Launcher">
<clobbers target="window.launcher" />
</js-module>
<!-- windows -->
<platform name="windows">
<js-module src="src/windows/Launcher.js" name="LauncherProxy">
<merges target="" />
</js-module>
<!-- <framework src="src/windows/lib/MyRuntime.winmd" custom="true" /> -->
<framework src="src/windows/lib/SQLite.dll" custom="true"/>
<framework src="src/windows/lib/MyRuntime.winmd" custom="true" />
<framework src="src/windows/lib/Newtonsoft.Json.dll" custom="true"/>
</platform>
</plugin>