{"id":339,"date":"2022-04-07T14:25:43","date_gmt":"2022-04-07T06:25:43","guid":{"rendered":"https:\/\/fugary.com\/?p=339"},"modified":"2022-04-07T14:25:43","modified_gmt":"2022-04-07T06:25:43","slug":"cordova%e7%9a%84android%e6%8f%92%e4%bb%b6%e5%bc%80%e5%8f%91","status":"publish","type":"post","link":"https:\/\/fugary.com\/?p=339","title":{"rendered":"Cordova\u7684Android\u63d2\u4ef6\u5f00\u53d1"},"content":{"rendered":"<p>\u6700\u8fd1\u4f7f\u7528<code>cordova<\/code>\u5f00\u53d1\u6df7\u5408<code>APP<\/code>\uff0c\u4e0d\u8fc7\u6709\u4e9b\u529f\u80fd\u53ea\u4f7f\u7528<code>H5<\/code>\u5b9e\u73b0\u4e0d\u4e86\uff0c\u56e0\u6b64\u9700\u8981\u7528\u539f\u751f\u4ee3\u7801\u5f00\u53d1\uff0c\u7136\u540e\u5305\u88c5\u6210<code>cordova<\/code>\u63d2\u4ef6\u3002<\/p>\n<p>\u76ee\u524d\u6765\u770b<code>cordova<\/code>\u63d2\u4ef6\u8bbe\u8ba1\u8fd8\u662f\u5f88\u6709\u95ee\u9898\u7684\uff0c\u5f00\u53d1\u5f88\u4e0d\u65b9\u4fbf\uff0c\u603b\u4e0d\u80fd\u7528\u8bb0\u4e8b\u672c\u5f00\u53d1\u5427\uff0c\u4f9d\u8d56\u7b49\u4fe1\u606f\u90fd\u6ca1\u6709\u3002<\/p>\n<p><strong>\u6bd4\u8f83\u597d\u7684\u5f00\u53d1\u65b9\u5f0f\u662f\u5bfc\u5165\u5230\u4e00\u4e2a\u5df2\u7ecf\u5b58\u5728\u7684<code>cordova<\/code>\u9879\u76ee\u4e2d\uff0c\u5728\u9879\u76ee\u4e2d\u5f00\u53d1\uff0c\u8fd9\u91cc\u5f00\u53d1\u7684<code>android<\/code>\u5e73\u53f0\u63d2\u4ef6\u3002<\/strong><\/p>\n<h3>\u521b\u5efa\u63d2\u4ef6<\/h3>\n<h4>\u5b89\u88c5plugman<\/h4>\n<p>\u9996\u5148\u9700\u8981\u5b89\u88c5<code>plugman<\/code>\uff0c<code>plugman<\/code>\u662f<code>cordova<\/code>\u63d0\u4f9b\u7684\u63d2\u4ef6\u5f00\u53d1\u5de5\u5177\uff0c\u6bd4\u8f83\u65b9\u4fbf\u521b\u5efa\u63d2\u4ef6\uff0c\u6dfb\u52a0\u63d2\u4ef6\u5e73\u53f0\u7b49\u3002<\/p>\n<pre><code class=\"language-sh\">npm install -g plugman<\/code><\/pre>\n<h4>\u521b\u5efa\u63d2\u4ef6<\/h4>\n<p>\u4f7f\u7528<code>plugman<\/code>\u521b\u5efa\u4e00\u4e2a\u63d2\u4ef6<code>cordova-plugin-jpush-custom<\/code><\/p>\n<pre><code class=\"language-sh\"># \u521b\u5efa\u63d2\u4ef6\nplugman create --name JPushCustomPlugin --plugin_id cordova-plugin-jpush-custom --plugin_version 1.0.0\n# \u6dfb\u52a0Android\u5e73\u53f0\ncd JPushCustomPlugin\nplugman platform add --platform_name android\n# \u521b\u5efapackage.json\uff0c\u586b\u5199\u57fa\u672c\u4fe1\u606f\u5c31\u53ef\u4ee5\nplugman createpackagejson .<\/code><\/pre>\n<p>\u9879\u76ee\u521b\u5efa\u5b8c\u6bd5\u3002<\/p>\n<h3>\u5f00\u53d1\u63d2\u4ef6<\/h3>\n<p>\u57fa\u672c\u7684\u9879\u76ee\u7ed3\u6784\u5df2\u7ecf\u6709\u4e86\uff0c\u683c\u5f0f\u5316<code>plugin.xml<\/code>\uff0c\u4fee\u6539\u5305\u540d\u548c\u6620\u5c04\uff0c\u65b9\u4fbf\u540e\u9762\u5bfc\u5165\u5230<code>cordova<\/code>\u9879\u76ee\u4e2d<\/p>\n<h4>\u4fee\u6539plugin.xml<\/h4>\n<p>\u4fee\u6539<code>plugin.xml<\/code><\/p>\n<pre><code class=\"language-xml\">&lt;?xml version=&#039;1.0&#039; encoding=&#039;utf-8&#039;?&gt;\n&lt;plugin id=&quot;cordova-plugin-jpush-custom&quot; version=&quot;1.0.0&quot; xmlns=&quot;http:\/\/apache.org\/cordova\/ns\/plugins\/1.0&quot;\n        xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;&gt;\n    &lt;name&gt;JPushCustomPlugin&lt;\/name&gt;\n    &lt;js-module name=&quot;JPushCustomPlugin&quot; src=&quot;www\/JPushCustomPlugin.js&quot;&gt;\n        &lt;clobbers target=&quot;cordova.plugins.JPushCustomPlugin&quot;\/&gt;\n    &lt;\/js-module&gt;\n    &lt;platform name=&quot;android&quot;&gt;\n        &lt;config-file parent=&quot;\/*&quot; target=&quot;res\/xml\/config.xml&quot;&gt;\n            &lt;feature name=&quot;JPushCustomPlugin&quot;&gt;\n                &lt;param name=&quot;android-package&quot; value=&quot;com.xxxxx.app.plugin.custom.JPushCustomPlugin&quot;\/&gt;\n            &lt;\/feature&gt;\n        &lt;\/config-file&gt;\n        &lt;config-file parent=&quot;\/*&quot; target=&quot;AndroidManifest.xml&quot;&gt;&lt;\/config-file&gt;\n        &lt;source-file src=&quot;src\/android\/JPushCustomPlugin.java&quot;\n                     target-dir=&quot;src\/com\/xxxxx\/app\/plugin\/custom&quot;\/&gt;\n    &lt;\/platform&gt;\n&lt;\/plugin&gt;<\/code><\/pre>\n<p>\u4e3b\u8981\u4fee\u6539\u4e0b\u56fe\u7684\u4e24\u4e2a\u5730\u65b9\u3002<\/p>\n<p><div class='fancybox-wrapper' data-fancybox='post-images' href='https:\/\/git.mengqingpo.com:8888\/fugary\/blogpic\/uploads\/2193c8cf761c28a57b1adac41beffc3c\/202204061642768.png'><img src=\"https:\/\/git.mengqingpo.com:8888\/fugary\/blogpic\/uploads\/2193c8cf761c28a57b1adac41beffc3c\/202204061642768.png\" alt=\"image-20220406164214711\" \/><\/div><\/p>\n<p>\u7136\u540e\u63d2\u4ef6<code>JPushCustomPlugin.java<\/code>\u7684\u5305\u540d\u4e5f\u8981\u6539\u6389<\/p>\n<p><div class='fancybox-wrapper' data-fancybox='post-images' href='https:\/\/git.mengqingpo.com:8888\/fugary\/blogpic\/uploads\/f7b8148fa9e035070fe6d321bb9121c9\/202204061757990.png'><img src=\"https:\/\/git.mengqingpo.com:8888\/fugary\/blogpic\/uploads\/f7b8148fa9e035070fe6d321bb9121c9\/202204061757990.png\" alt=\"image-20220406175732910\" \/><\/div><\/p>\n<h4>\u5b9a\u4e49JS\u5bf9\u8c61<\/h4>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u5bf9\u5e94\u7684\u63d2\u4ef6\u53ef\u4ee5\u5728\u9875\u9762\u4e0a\u4f7f\u7528<code>window.cordova.plugins.JPushCustomPlugin<\/code>\u8bbf\u95ee\u5230<\/p>\n<pre><code class=\"language-xml\">&lt;js-module name=&quot;JPushCustomPlugin&quot; src=&quot;www\/JPushCustomPlugin.js&quot;&gt;\n    &lt;clobbers target=&quot;cordova.plugins.JPushCustomPlugin&quot;\/&gt;\n&lt;\/js-module&gt;<\/code><\/pre>\n<p>\u53ef\u4ee5\u4fee\u6539<code>clobbers<\/code>\u7684<code>target<\/code>\u503c\u6765\u5b9a\u4e49\u63d2\u4ef6\u5bf9\u8c61\u7684\u4f4d\u7f6e\uff0c\u5982\u53ef\u4ee5\u5b9a\u4e49\u4e3a<code>&lt;clobbers target=&quot;JPushCustomPlugin&quot;\/&gt;<\/code>\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u4f7f\u7528<code>window.JPushCustomPlugin<\/code>\u8bbf\u95ee\u4e86\u3002<\/p>\n<p>\u5982\u679c\u6709\u591a\u4e2a<code>js<\/code>\u6587\u4ef6\u5c31\u9700\u8981\u591a\u4e2a<code>&lt;js-module&gt;<\/code>\uff0c\u591a\u4e2a<code>Java<\/code>\u6587\u4ef6\u5c31\u9700\u8981\u591a\u4e2a<code>&lt;source-file&gt;<\/code>\u3002<\/p>\n<h4>\u6dfb\u52a0\u5230cordova\u9879\u76ee<\/h4>\n<p><code>cd<\/code>\u5230\u81ea\u5df1\u7684<code>cordova<\/code>\u9879\u76ee\u4e2d\uff0c\u518d\u6839\u636e\u76f8\u5bf9\u8def\u5f84\u4ee5\u94fe\u63a5\u65b9\u5f0f\u6dfb\u52a0\u521a\u521a\u521b\u5efa\u7684\u63d2\u4ef6<\/p>\n<pre><code class=\"language-sh\"># cd\u5230\u81ea\u5df1\u7684cordova\u9879\u76ee\n# \u5b89\u88c5\u5230cordova\u9879\u76ee\u4e2d\uff08\u6839\u636e\u5b9e\u9645\u8def\u5f84\uff09\ncordova plugin add .\/plugin_custom\/JPushCustomPlugin\/ --link<\/code><\/pre>\n<p>\u7136\u540e\u518d\u5728Android Studio\u4e2d\u6253\u5f00\u81ea\u5df1\u7684cordova\u9879\u76ee\uff0c\u53c2\u8003\u65b0\u5efaCordova\u9879\u76ee\uff1a<a href=\"https:\/\/fugary.com\/?p=251\">https:\/\/fugary.com\/?p=251<\/a><\/p>\n<p>\u751f\u6210\u7684\u4ee3\u7801\u9ed8\u8ba4\u5df2\u7ecf\u63d0\u4f9b\u4e86\u4e00\u4e2a\u53eb\u505acoolMethod\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\u505a\u6d4b\u8bd5\uff0c\u4fee\u6539<code>index.js<\/code>\u6d4b\u8bd5\u3002<\/p>\n<p><code>index.js<\/code>\u7684\u4f4d\u7f6e\u662f<code>src\/main\/assets\/www\/js\/index.js<\/code><\/p>\n<p><div class='fancybox-wrapper' data-fancybox='post-images' href='https:\/\/git.mengqingpo.com:8888\/fugary\/blogpic\/uploads\/9f7f7ae7b9506699a988edb6b12f2d12\/202204070949140.png'><img src=\"https:\/\/git.mengqingpo.com:8888\/fugary\/blogpic\/uploads\/9f7f7ae7b9506699a988edb6b12f2d12\/202204070949140.png\" alt=\"image-20220407094949978\" \/><\/div><\/p>\n<pre><code class=\"language-js\">document.addEventListener(&#039;deviceready&#039;, onDeviceReady, false);\nfunction onDeviceReady() {\n    \/\/ Cordova is now initialized. Have fun!\n    console.log(&#039;Running cordova-&#039; + cordova.platformId + &#039;@&#039; + cordova.version);\n    document.getElementById(&#039;deviceready&#039;).classList.add(&#039;ready&#039;);\n    cordova.plugins.JPushCustomPlugin.coolMethod(&#039;\u6d4b\u8bd5\u6d88\u606f&#039;, function(msg){\n        console.info(msg);\n    });\n}<\/code><\/pre>\n<p>\u5728\u6a21\u62df\u5668\u4e2d\u8fd0\u884c\uff0c\u7136\u540e\u518d\u5728<code>chrome:\/\/inspect<\/code>\u4e2d\u67e5\u770b\uff0c\u7528\u6cd5\u53ef\u4ee5\u53c2\u8003\uff1a<a href=\"https:\/\/fugary.com\/?p=322\">https:\/\/fugary.com\/?p=322<\/a><\/p>\n<p><div class='fancybox-wrapper' data-fancybox='post-images' href='https:\/\/git.mengqingpo.com:8888\/fugary\/blogpic\/uploads\/abb72f454f0697f3f082767fb86e9c6b\/202204070946998.png'><img src=\"https:\/\/git.mengqingpo.com:8888\/fugary\/blogpic\/uploads\/abb72f454f0697f3f082767fb86e9c6b\/202204070946998.png\" alt=\"image-20220407094555771\" \/><\/div><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u6d4b\u8bd5\u6210\u529f\u4e86\uff0c\u53ef\u4ee5\u5f00\u53d1\u81ea\u5df1\u7684\u65b9\u6cd5\u4e86\u3002<\/p>\n<h3>\u5e38\u89c1\u95ee\u9898<\/h3>\n<p>\u8bb0\u5f55\u4e0b\u9047\u5230\u7684\u51e0\u4e2a\u95ee\u9898<\/p>\n<h4>\u5b89\u88c5\u63d2\u4ef6link\u9519\u8bef<\/h4>\n<p>\u62a5\u9519\u4fe1\u606f\u5982\u4e0b\uff0c\u63d0\u793a\u662f\u6587\u4ef6\u521b\u5efa\u94fe\u63a5\u5931\u8d25<\/p>\n<pre><code class=\"language-sh\">Installing &quot;cordova-plugin-jpush-custom&quot; for android\nError during processing of action! Attempting to revert...\nFailed to install &#039;cordova-plugin-jpush-custom&#039;: Error: Uh oh!\nEPERM: operation not permitted, symlink &#039;..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\\n......<\/code><\/pre>\n<p>\u4e00\u822c\u90fd\u662f\u6743\u9650\u95ee\u9898\uff0c<code>cordova<\/code>\u8fd9\u91cc\u662f\u56e0\u4e3a<code>android<\/code>\u5e73\u53f0\u5f15\u8d77\uff0c\u9700\u8981\u91cd\u65b0\u6dfb\u52a0\u4e00\u6b21<code>android<\/code>\u5e73\u53f0<\/p>\n<pre><code class=\"language-sh\">cordova platform rm android\ncordova platform add android<\/code><\/pre>\n<h4>Android Studio\u7f16\u8bd1\u95ee\u9898<\/h4>\n<p>\u5982\u679cAndroid Studio\u4e2d\u51fa\u73b0\u4e00\u7247\u7ea2\uff0c\u6ca1\u6709\u8ba4\u51fa\u76f8\u5173\u7684<code>Class<\/code>\uff0c\u53ef\u4ee5\u6e05\u7406\u4e0b\u7f13\u5b58\uff1a<\/p>\n<p><div class='fancybox-wrapper' data-fancybox='post-images' href='https:\/\/git.mengqingpo.com:8888\/fugary\/blogpic\/uploads\/7bad15fcb7ce0c2b59c7a2e49d4f4529\/202204061823465.png'><img src=\"https:\/\/git.mengqingpo.com:8888\/fugary\/blogpic\/uploads\/7bad15fcb7ce0c2b59c7a2e49d4f4529\/202204061823465.png\" alt=\"image-20220406182341351\" \/><\/div><\/p>\n<pre><code class=\"language-sh\">Cannot resolve symbol &#039;CordovaPlugin&#039;\nCannot resolve symbol &#039;CallbackContext&#039;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u4f7f\u7528cordova\u5f00\u53d1\u6df7\u5408APP\uff0c\u4e0d\u8fc7\u6709\u4e9b\u529f\u80fd\u53ea\u4f7f\u7528H5\u5b9e\u73b0\u4e0d\u4e86\uff0c\u56e0\u6b64\u9700\u8981\u7528\u539f\u751f\u4ee3\u7801\u5f00\u53d1\uff0c\u7136\u540e\u5305\u88c5\u6210cor [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[26,36,73,72],"_links":{"self":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/339"}],"collection":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=339"}],"version-history":[{"count":1,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/339\/revisions"}],"predecessor-version":[{"id":340,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/339\/revisions\/340"}],"wp:attachment":[{"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}