{"id":7016,"date":"2026-02-27T10:28:22","date_gmt":"2026-02-27T02:28:22","guid":{"rendered":"https:\/\/t.n-years.com\/?p=7016"},"modified":"2026-02-27T10:28:22","modified_gmt":"2026-02-27T02:28:22","slug":"%e8%b7%a8%e8%af%ad%e8%a8%80%e5%bc%80%e5%8f%91%e5%88%86%e5%b1%82%e8%ae%be%e8%ae%a1","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=7016","title":{"rendered":"\u8de8\u8bed\u8a00\u5f00\u53d1\u5206\u5c42\u8bbe\u8ba1"},"content":{"rendered":"<blockquote>\n<p>Gemini \u751f\u6210\uff0c\u95ee\u9898\uff1a\u5bbf\u4e3b\u4e3b\u6d41\u8bed\u8a00\u662f \u539f\u751f\u5f00\u53d1\uff0c\u90e8\u5206 H5 \u4e0e Native \u7684\u4ea4\u4e92<\/p>\n<\/blockquote>\n<p>\u65e2\u7136\u5bbf\u4e3b\u73af\u5883\u662f <strong>\u539f\u751f + H5 \u6df7\u5408\u5f00\u53d1<\/strong>\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u9762\u4e34\u7684\u6311\u6218\u5176\u5b9e\u662f\u201c\u53cc\u5c42\u7a7f\u900f\u201d\uff1a<\/p>\n<ol>\n<li><strong>FFI \u5c42<\/strong>\uff1aNative\uff08Java\/Kotlin\/Swift\/OC\uff09\u8c03\u7528 C++ Core\u3002<\/li>\n<li><strong>Bridge \u5c42<\/strong>\uff1aH5\uff08JS\uff09\u8c03\u7528 Native \u73af\u5883\uff0c\u8fdb\u800c\u89e6\u53d1 C++ Core\u3002<\/li>\n<\/ol>\n<p>\u4e3a\u4e86\u4fdd\u969c\u201c\u9ad8\u6548\u5f00\u53d1\u201d\uff0c\u6838\u5fc3\u903b\u8f91\u5fc5\u987b\u9075\u5faa <strong>\u201c\u903b\u8f91\u4e0b\u6c89\uff0c\u63a5\u53e3\u6781\u7b80\u201d<\/strong> \u7684\u539f\u5219\u3002\u4e0d\u8981\u5728\u5404\u4e2a\u7aef\u53bb\u5199\u903b\u8f91\uff0c\u800c\u8981\u5c06 C++ \u4f5c\u4e3a\u552f\u4e00\u7684\u4e1a\u52a1\u903b\u8f91\u5bb9\u5668\u3002<\/p>\n<h3>1. \u67b6\u6784\u900f\u89c6\u56fe\uff1a\u6df7\u5408\u5e94\u7528\u6865\u63a5\u65b9\u6848<\/h3>\n<p>\u8fd9\u79cd\u67b6\u6784\u7684\u6838\u5fc3\u5728\u4e8e\u5c06 C++ Core \u5c01\u88c5\u6210\u4e00\u4e2a\u9ed1\u76d2\uff0cNative \u7aef\u4ec5\u4f5c\u4e3a\u201c\u80f6\u6c34\u201d\uff0c\u800c H5 \u5219\u662f\u901a\u8fc7\u80f6\u6c34\u5c42\u95f4\u63a5\u64cd\u4f5c\u9ed1\u76d2\u3002<\/p>\n<hr \/>\n<h3>2. \u6838\u5fc3\u8bbe\u8ba1\u7b56\u7565\uff1a\u5355\u6e90\u771f\u7406 (Single Source of Truth)<\/h3>\n<p>\u4e3a\u4e86\u4fdd\u969c\u5f00\u53d1\u6548\u7387\uff0c\u8bf7\u52a1\u5fc5\u6267\u884c\u4ee5\u4e0b\u67b6\u6784\u51b3\u7b56\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5c42\u6b21<\/th>\n<th>\u804c\u8d23<\/th>\n<th>\u5b9e\u73b0\u91cd\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>C++ Core<\/strong><\/td>\n<td>\u7f51\u7edc\u72b6\u6001\u673a\u3001\u534f\u8bae\u89e3\u6790\u3001\u52a0\u89e3\u5bc6\u3001\u91cd\u8bd5\u7b56\u7565<\/td>\n<td><strong>\u7edd\u5bf9\u4e0d\u53ef\u5305\u542b\u5e73\u53f0\u76f8\u5173\u4ee3\u7801<\/strong>\u3002\u6240\u6709\u903b\u8f91\u5728\u6b64\u95ed\u73af\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>Native Bridge<\/strong><\/td>\n<td>JNI (Android) \/ Obj-C++ (iOS)<\/td>\n<td>\u4ec5\u8d1f\u8d23\u7ebf\u7a0b\u5207\u6362\u3001\u6307\u9488\u8f6c\u6362\u3001\u5bf9\u8c61\u751f\u547d\u5468\u671f\u7ed1\u5b9a\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>H5 Bridge<\/strong><\/td>\n<td><code>WebViewJavascriptBridge<\/code> \/ \u81ea\u5b9a\u4e49 Scheme<\/td>\n<td>\u8d1f\u8d23 JSON \u89e3\u6790\uff0c\u5c06 H5 \u4e8b\u4ef6\u8f6c\u6362\u4e3a Native API \u8c03\u7528\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u505a\uff1f<\/h4>\n<p>\u5982\u679c\u4f60\u5728 Java \u548c Swift \u4e2d\u5404\u81ea\u5b9e\u73b0\u4e00\u904d\u903b\u8f91\uff08\u4f8b\u5982\u8bf7\u6c42\u91cd\u8bd5\u3001Token \u5237\u65b0\uff09\uff0c\u4e00\u65e6\u63a5\u53e3\u53d8\u66f4\uff0c\u4f60\u5f97\u540c\u6b65\u6539\u4e09\u5904\uff08Android, iOS, H5\uff09\u3002<strong>\u5c06\u903b\u8f91\u5168\u90e8\u6c89\u6dc0\u5728 C++ \u5c42\uff0c\u4e1a\u52a1\u5c42\u53ea\u8d1f\u8d23 UI \u53cd\u9988\uff0c\u8fd9\u5c31\u662f\u5f00\u53d1\u6548\u7387\u7684\u6700\u5927\u5316\u3002<\/strong><\/p>\n<hr \/>\n<h3>3. \u5982\u4f55\u4fdd\u969c H5 \u5230 Native \u7684\u9ad8\u6548\u8c03\u7528\uff1f<\/h3>\n<p>\u5728\u6df7\u5408\u5f00\u53d1\u4e2d\uff0c\u6700\u5fcc\u8bb3\u7684\u662f H5 \u9891\u7e41\u8c03\u7528 Native\u3002\u4f60\u53ef\u4ee5\u91c7\u7528 <strong>\u201c\u547d\u4ee4\u603b\u7ebf (Command Bus)\u201d<\/strong> \u6a21\u5f0f\uff1a<\/p>\n<ul>\n<li><strong>\u8bbe\u8ba1\u539f\u5219\uff1a<\/strong> \u4e0d\u8981\u4e3a\u6bcf\u4e2a\u7f51\u7edc\u63a5\u53e3\u90fd\u5199\u4e00\u4e2a JS Bridge \u65b9\u6cd5\u3002<\/li>\n<li><strong>\u5b9e\u65bd\u65b9\u6848\uff1a<\/strong> \u5efa\u7acb\u4e00\u4e2a\u901a\u7528\u7684 <code>ExecuteNetwork(command_json)<\/code> \u65b9\u6cd5\u3002<\/li>\n<li>H5 \u4f20\u5165\uff1a<code>{ &quot;method&quot;: &quot;GET&quot;, &quot;url&quot;: &quot;...&quot;, &quot;params&quot;: {...} }<\/code><\/li>\n<li>Native \u5c42\uff1a\u63a5\u6536 JSON -&gt; \u53cd\u5e8f\u5217\u5316 -&gt; \u76f4\u63a5\u4f20\u7ed9 C++ Core \u7684\u7edf\u4e00\u5165\u53e3\u3002<\/li>\n<li>\u8fd9\u6837\u4f60\u53ea\u9700\u8981\u7ef4\u62a4 <strong>\u4e00\u4e2a<\/strong> JS \u63a5\u53e3\uff0c\u6240\u6709\u7684\u7f51\u7edc\u8bf7\u6c42\u90fd\u8d70\u8fd9\u4e2a\u901a\u9053\uff0c\u7ef4\u62a4\u6210\u672c\u964d\u4f4e 90%\u3002<\/li>\n<\/ul>\n<h3>4. \u4ee3\u7801\u5b9e\u8df5\u5efa\u8bae (Pattern)<\/h3>\n<p>\u4e3a\u4e86\u786e\u4fdd\u5185\u5b58\u5b89\u5168\u4e14\u9ad8\u6548\uff0c\u8bf7\u53c2\u8003\u4ee5\u4e0b <strong>&quot;C++ -&gt; Native -&gt; JS&quot;<\/strong> \u7684\u6d41\u7a0b\u4ee3\u7801\u601d\u8def\uff1a<\/p>\n<pre><code class=\"language-cpp\">\/\/ C++ Core \u5c42\uff1a\u7edf\u4e00\u5165\u53e3\nvoid NetworkManager::OnCommand(const std::string&amp; json_cmd) {\n    \/\/ 1. \u89e3\u6790 JSON \u83b7\u5f97\u8bf7\u6c42\u6307\u4ee4\n    \/\/ 2. \u8c03\u7528 C++ \u5185\u90e8\u7684\u5e95\u5c42 socket \u6216 libcurl\n    \/\/ 3. \u5f02\u6b65\u56de\u8c03\u7ed3\u679c\n}\n\n\/\/ Android (JNI\u5c42)\uff1a\u4f5c\u4e3a\u6865\u63a5\u4e2d\u8f6c\u7ad9\nextern &quot;C&quot; JNIEXPORT void JNICALL Java_com_app_NativeBridge_dispatch(JNIEnv* env, jobject obj, jstring json) {\n    std::string cmd = jstringToString(env, json);\n    NetworkManager::Instance().OnCommand(cmd); \/\/ \u6d3e\u53d1\u7ed9 C++\n}\n<\/code><\/pre>\n<hr \/>\n<h3>5. \u987e\u95ee\u7684\u7279\u522b\u8b66\u793a (\u5751\u4e0e\u907f\u96f7)<\/h3>\n<ul>\n<li>\n<p><strong>WebView \u6ce8\u5165\u7684\u5b89\u5168\u5751\uff1a<\/strong> \u5f88\u591a H5 \u4ea4\u4e92\u901a\u8fc7 <code>addJavascriptInterface<\/code> \u6ce8\u5165\u3002\u6ce8\u610f\uff0cAndroid 4.2 \u4ee5\u4e0b\u6709\u8fdc\u7a0b\u4ee3\u7801\u6267\u884c\u6f0f\u6d1e\uff0c\u52a1\u5fc5\u9650\u5236\u6743\u9650\uff0c\u53ea\u66b4\u9732\u5fc5\u8981\u7684\u51fd\u6570\uff0c\u4e0d\u8981\u628a\u6574\u4e2a\u5bf9\u8c61\u6254\u7ed9 JS\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5e8f\u5217\u5316\u6027\u80fd\u635f\u8017\uff1a<\/strong> H5 \u548c Native \u4e4b\u95f4\u4f20\u9012\u6570\u636e\u901a\u5e38\u4f7f\u7528 JSON\u3002\u5982\u679c\u6570\u636e\u91cf\u5927\uff08\u5982\u957f\u6587\u672c\u3001\u5927\u5bf9\u8c61\uff09\uff0c\u9891\u7e41\u7684 <code>JSON.stringify<\/code> \u548c <code>JSON.parse<\/code> \u4f1a\u963b\u585e UI \u7ebf\u7a0b\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u6539\u8fdb\uff1a<\/strong> \u5bf9\u4e8e\u590d\u6742\u5927\u6570\u636e\uff0c\u4e0d\u8981\u8d70 JS \u6865\uff0c\u8d70 <strong>URL Schema<\/strong> \u6216 <strong>\u5185\u5b58\u5171\u4eab\uff08Memory Mapping\uff09<\/strong> \u65b9\u6848\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u7ebf\u7a0b\u963b\u585e\uff1a<\/strong> H5 \u7684\u8c03\u7528\u9ed8\u8ba4\u5728\u4e3b\u7ebf\u7a0b\u3002\u5982\u679c\u4f60\u7684 C++ \u7f51\u7edc\u5e93\u662f\u5728\u4e3b\u7ebf\u7a0b\u5904\u7406\u4e1a\u52a1\uff0cApp \u5fc5\u7136\u6389\u5e27\u3002<strong>\u5f3a\u5236\u5728 Native \u6865\u63a5\u5c42\u5c06\u4efb\u52a1\u629b\u5165\u5b50\u7ebf\u7a0b\u6267\u884c<\/strong>\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<p><strong>\u4e0b\u4e00\u6b65\u5efa\u8bae\uff1a<\/strong><\/p>\n<p>\u65e2\u7136\u4f60\u662f\u505a\u6df7\u5408\u5f00\u53d1\uff0c\u4f60\u76ee\u524d\u662f\u5426\u5df2\u7ecf\u9009\u7528\u4e86\u6210\u719f\u7684\u901a\u4fe1\u6846\u67b6\uff08\u5982 <code>WebViewJavascriptBridge<\/code> \u6216 <code>DSBridge<\/code>\uff09\uff0c\u8fd8\u662f\u51c6\u5907\u81ea\u7814\u8fd9\u5957\u4ea4\u4e92\u673a\u5236\uff1f<\/p>\n<p><strong>\u6211\u53ef\u4ee5\u4e3a\u4f60\u63d0\u4f9b\u4e00\u4efd\u57fa\u4e8e <code>Protobuf<\/code> \u7684 JS-to-Native \u9ad8\u6548\u901a\u4fe1\u534f\u8bae\u5b9a\u4e49\u6a21\u677f\uff0c\u5982\u679c\u4f60\u9700\u8981\u7684\u8bdd\uff0c\u8bf7\u544a\u8bc9\u6211\u3002<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gemini \u751f\u6210\uff0c\u95ee\u9898\uff1a\u5bbf\u4e3b\u4e3b\u6d41\u8bed\u8a00\u662f \u539f\u751f\u5f00\u53d1\uff0c\u90e8\u5206 H5 \u4e0e Native \u7684\u4ea4\u4e92 \u65e2\u7136\u5bbf\u4e3b\u73af\u5883\u662f \u539f\u751f&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=7016\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[135],"tags":[],"class_list":["post-7016","post","type-post","status-publish","format-standard","hentry","category-135"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/7016","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7016"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/7016\/revisions"}],"predecessor-version":[{"id":7017,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/7016\/revisions\/7017"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}