本机模块在 nativescript 中无法正常工作
native modules are not working correctly in nativescript
我正在尝试使用这个 android 包在 nativescript 中制作模糊效果。
https://github.com/wasabeef/Blurry
所以在 nativescript 中包含了我在 app.gradle 中的编译 /app/App_Resources/Android/app。gradle
然后重建一切正常,构建良好。
但是当我开始使用该库时,我尝试 console.dir(global['jp'])
因为库导入语句应该是
import jp.wasabeef.blurry.Blurry;
所以我开始查看要调用的函数是否存在,所以这来自 console.dir
JS: === dump(): dumping members ===
JS: {
JS: "wasabeef": {
JS: "blurry": {
JS: "R": "R()function () { [native code] }"
JS: }
JS: }
JS: }
JS: === dump(): dumping function and properties names ===
JS: === dump(): finished ===
所以,如您所见,应该让我访问该库的最后一个函数不存在。
我真的很想知道为什么我也尝试自己制作一个 android 包来使用它 return 我想要的功能但同样的问题最后一个功能没有出现。
我也在 nativescript 中搜索了一个插件,我找到了这个 https://www.npmjs.com/package/nativescript-blur
但是,它实际上并没有像文档中所说的那样产生实际模糊,当我尝试使用它时发生了同样的问题,我得到了这个错误。
JS: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'init' of undefined
JS: TypeError: Cannot read property 'init' of undefined
JS: at new Blur (file:///data/data/org.nativescript.test2/files/app/tns_modules/nativescript-blur/blur.js:8:39)
JS: at Object.<anonymous> (file:///data/data/org.nativescript.test2/files/app/home/home.component.js:5:12)
JS: at require (<anonymous>:1:266)
JS: at Object.<anonymous> (file:///data/data/org.nativescript.test2/files/app/home/home-routing.module.js:5:24)
JS: at require (<anonymous>:1:266)
JS: at Object.<anonymous> (file:///data/data/org.nativescript.test2/files/app/home/home.module.js:5:29)
JS: at require (<anonymous>:1:266)
JS: at file:///data/data/org.nativescript.test2/files/app/tns_modules/tns-core-modules/globals/globals.js:92:32
JS: at new ZoneAwarePromise (file:///data/data/org.nativescript.test2/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:777:29)
JS: at Object.import (file:///data/data/org.nativescript.test2/files/app/tns_modules/tns-core-modules/globals/globals.js:90:16)
JS: at SystemJsNgModuleLoader.loadAndCompile (file:///data/data/org.nativescript.test2/files/app/tns_modules/@angular/core/bundles/core.umd.js:6596:29)
JS: at SystemJsNgModuleLoader.load (file:///data/data/org.nativescript.test2/files/app/tns_modules/@angular/core/bundles/core.umd.js:6580:60)
JS: at RouterConfigLoader.loadModuleFactory (file:///data/data/org.nativescript.test2/files/app/tns_modules/@angular/router/bundles/router.umd.js:4611:72)
JS: at RouterConfigLoader.load (file:///data/data/org.nativescript.test2/files/app/tns_modules/@angular/router/bundles/router.umd.js:4591:52)
JS: at MergeMapSubscriber.project (file:///data/data/org.nativescript.test2/files/app/tns_modules/@angular/router/bundles/router.umd.js:2083:74)
所以,当我检查 node_modules 中的错误位置时,我发现 init 是包名称中的最后一个函数,该库使用与我尝试使用的包相同的大小写以上。
此外,我已经在 angular 空白模板和 javascript 空白模板中尝试过此操作,假设在全局包含库时存在任何差异。
我的 nativescript cli 版本是:3.4.3
- 我使用的是 android 版本 6
的模拟器
我不知道为什么会出现这个奇怪的问题,我是 nativescript 的新手。请有人告诉我如何解决这个问题,或者至少用一个使用我上面提到的包的示例应用程序来回答。
谢谢
我发现答案很奇怪,当 nativescript 由于某种原因重建时它没有正确构建它。
所以,作为这个问题 https://github.com/davecoffin/nativescript-blur/issues/5
解决方案说
您只需要:
做
tns platform remove android
然后做
tns run android
现在应该可以正常工作了。希望它能帮助遇到这种错误的人
我正在尝试使用这个 android 包在 nativescript 中制作模糊效果。
https://github.com/wasabeef/Blurry
所以在 nativescript 中包含了我在 app.gradle 中的编译 /app/App_Resources/Android/app。gradle
然后重建一切正常,构建良好。
但是当我开始使用该库时,我尝试 console.dir(global['jp']) 因为库导入语句应该是
import jp.wasabeef.blurry.Blurry;
所以我开始查看要调用的函数是否存在,所以这来自 console.dir
JS: === dump(): dumping members ===
JS: {
JS: "wasabeef": {
JS: "blurry": {
JS: "R": "R()function () { [native code] }"
JS: }
JS: }
JS: }
JS: === dump(): dumping function and properties names ===
JS: === dump(): finished ===
所以,如您所见,应该让我访问该库的最后一个函数不存在。 我真的很想知道为什么我也尝试自己制作一个 android 包来使用它 return 我想要的功能但同样的问题最后一个功能没有出现。
我也在 nativescript 中搜索了一个插件,我找到了这个 https://www.npmjs.com/package/nativescript-blur
但是,它实际上并没有像文档中所说的那样产生实际模糊,当我尝试使用它时发生了同样的问题,我得到了这个错误。
JS: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'init' of undefined
JS: TypeError: Cannot read property 'init' of undefined
JS: at new Blur (file:///data/data/org.nativescript.test2/files/app/tns_modules/nativescript-blur/blur.js:8:39)
JS: at Object.<anonymous> (file:///data/data/org.nativescript.test2/files/app/home/home.component.js:5:12)
JS: at require (<anonymous>:1:266)
JS: at Object.<anonymous> (file:///data/data/org.nativescript.test2/files/app/home/home-routing.module.js:5:24)
JS: at require (<anonymous>:1:266)
JS: at Object.<anonymous> (file:///data/data/org.nativescript.test2/files/app/home/home.module.js:5:29)
JS: at require (<anonymous>:1:266)
JS: at file:///data/data/org.nativescript.test2/files/app/tns_modules/tns-core-modules/globals/globals.js:92:32
JS: at new ZoneAwarePromise (file:///data/data/org.nativescript.test2/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:777:29)
JS: at Object.import (file:///data/data/org.nativescript.test2/files/app/tns_modules/tns-core-modules/globals/globals.js:90:16)
JS: at SystemJsNgModuleLoader.loadAndCompile (file:///data/data/org.nativescript.test2/files/app/tns_modules/@angular/core/bundles/core.umd.js:6596:29)
JS: at SystemJsNgModuleLoader.load (file:///data/data/org.nativescript.test2/files/app/tns_modules/@angular/core/bundles/core.umd.js:6580:60)
JS: at RouterConfigLoader.loadModuleFactory (file:///data/data/org.nativescript.test2/files/app/tns_modules/@angular/router/bundles/router.umd.js:4611:72)
JS: at RouterConfigLoader.load (file:///data/data/org.nativescript.test2/files/app/tns_modules/@angular/router/bundles/router.umd.js:4591:52)
JS: at MergeMapSubscriber.project (file:///data/data/org.nativescript.test2/files/app/tns_modules/@angular/router/bundles/router.umd.js:2083:74)
所以,当我检查 node_modules 中的错误位置时,我发现 init 是包名称中的最后一个函数,该库使用与我尝试使用的包相同的大小写以上。
此外,我已经在 angular 空白模板和 javascript 空白模板中尝试过此操作,假设在全局包含库时存在任何差异。
我的 nativescript cli 版本是:3.4.3
- 我使用的是 android 版本 6 的模拟器
我不知道为什么会出现这个奇怪的问题,我是 nativescript 的新手。请有人告诉我如何解决这个问题,或者至少用一个使用我上面提到的包的示例应用程序来回答。
谢谢
我发现答案很奇怪,当 nativescript 由于某种原因重建时它没有正确构建它。 所以,作为这个问题 https://github.com/davecoffin/nativescript-blur/issues/5 解决方案说
您只需要:
做
tns platform remove android
然后做
tns run android
现在应该可以正常工作了。希望它能帮助遇到这种错误的人