{"id":166,"date":"2024-01-02T16:44:52","date_gmt":"2024-01-02T08:44:52","guid":{"rendered":"https:\/\/hjwzs.xyz\/?p=166"},"modified":"2024-01-02T16:44:52","modified_gmt":"2024-01-02T08:44:52","slug":"%e5%ae%a2%e6%88%b7%e7%ab%af%e8%b7%a8%e7%ab%af%e7%9a%84%e5%8f%a6%e4%b8%80%e7%a7%8d%e5%b0%9d%e8%af%95%ef%bc%9ago-mobile","status":"publish","type":"post","link":"https:\/\/hjwzs.xyz\/?p=166","title":{"rendered":"\u5ba2\u6237\u7aef\u8de8\u7aef\u7684\u53e6\u4e00\u79cd\u5c1d\u8bd5\uff1aGo mobile"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4f17\u6240\u5468\u77e5\uff0c <strong>flutter<\/strong> \u662f <strong>Google<\/strong> \u5728 2018 \u5e74\u53d1\u5e03\uff0c\u7528\u4e8e\u539f\u751f\u8de8\u7aef\uff08\u5f53\u7136 2.0 \u53ef\u4ee5\u505a\u66f4\u591a\u7684\u4e8b\u60c5~\uff09\u6846\u67b6\uff0c\u57fa\u4e8e <strong>Dart<\/strong> \u8bed\u8a00\u5f00\u53d1\u3002\u5f88\u591a\u4eba\u90fd\u5f88\u5947\u602a\uff0c\u56e0\u4e3a\u5728\u8fd9\u6bb5\u65f6\u95f4\u5185\uff0c2012\u5e74\u6b63\u5f0f\u53d1\u5e03\u7684 <strong>Go<\/strong> \u4e00\u76f4\u662f <strong>Google<\/strong> \u4e3b\u63a8\uff0c\u4e3a\u4ec0\u4e48 <strong>flutter<\/strong> \u8fd9\u4e2a\u5f00\u6e90\u6846\u67b6\u4f1a\u4f7f\u7528\u540d\u4e0d\u89c1\u7ecf\u4f20\u7684 <strong>Dart<\/strong> \u4f5c\u4e3a\u5f00\u53d1\u8bed\u8a00\u5462\uff1f\u662f <strong>Go<\/strong> \u4e0d\u80fd\u8fdb\u884c\u8de8\u7aef\u5f00\u53d1\u4e48\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u5b9e\u65e9\u57282012\u5e74\uff0c <strong>Google<\/strong> \u5c31\u5728 <strong>Github<\/strong> \u4e0a\u5f00\u6e90\u4e86\u57fa\u4e8e <strong>Go<\/strong> \u7684\u8de8\u7aef\u5f00\u6e90\u89e3\u51b3\u65b9\u6848 <a href=\"https:\/\/github.com\/golang\/mobile\">golang\/mobile<\/a> \u5e76\u4e14\u6301\u7eed\u7ef4\u62a4\u3002\u4f46\u662f\u5bf9\u4e8e\u8fd9\u4e2a\u5df2\u7ecf\u5f00\u6e90\u4e869\u5e74\u7684\u201c\u8001\u9879\u76ee\u201d\uff0c <strong>Google<\/strong> \u5b98\u65b9\u5374\u5728 <strong>Readme<\/strong> \u4e2d\u4ecd\u7136\u6807\u6ce8\u8fd9\u4e2a\u65b9\u6848\u4ecd\u7136\u662f\u4e00\u4e2a\u5b9e\u9a8c\u6027\u7684\u9879\u76ee\u3002\u5bf9\u4e8e\u8fd9\u4e2a\u9879\u76ee\u7b14\u8005\u751a\u662f\u611f\u5174\u8da3\uff0c\u8fd1\u671f\u4fbf\u6765\u8c03\u7814\u4e00\u756a\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7f16\u8bd1\u5230 Android<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e\u5982\u4f55\u4e0e\u79fb\u52a8\u5e94\u7528\u96c6\u6210\uff0c <a href=\"https:\/\/github.com\/golang\/mobile\">golang\/mobile<\/a> \u5df2\u7ecf\u63d0\u4f9b\u4e862\u79cd\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>all-in\uff0c\u5373\u6574\u4e2aApp\u90fd\u4f7f\u7528 <strong>golang<\/strong> \u6784\u5efa<\/li>\n\n\n\n<li>SDK\uff0c\u90e8\u5206\u4ee3\u7801\u4f7f\u7528 <strong>golang<\/strong> \u6784\u5efa\uff0cApp\u53ef\u4ee5\u901a\u8fc7\u96c6\u6210 <strong>framework<\/strong> \u6216\u8005 <strong>aar<\/strong> \u8fdb\u884c<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u5148\u6765\u5c1d\u8bd5 <strong>all-in<\/strong> \u7684\u65b9\u5f0f\uff0c\u7b14\u8005\u4f7f\u7528\u7684 macOS \u7cfb\u7edf\uff0c\u5728\u5df2\u7ecf\u5b89\u88c5\u597d <strong>golang<\/strong> \u8fd0\u884c\u65f6\u7684\u57fa\u7840\u4e0a\uff0c\u53ea\u8981\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u5c31\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4f7f\u7528 <strong>gomobile<\/strong> \u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$ go get golang.org\/x\/mobile\/cmd\/gomobile<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531\u4e8e\u4e0d\u9700\u8981\u8003\u8651\u7b7e\u540d\u7b49\u7e41\u7410\u4e8b\u9879\uff0c\u6211\u4eec\u4f7f\u7528 <a href=\"https:\/\/github.com\/golang\/mobile\">golang\/mobile<\/a> \u6784\u5efa\u4e00\u4e2a <strong>apk<\/strong> \u8bd5\u8bd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b98\u65b9\u5df2\u7ecf\u63d0\u4f9b\u4e86\u7b80\u5355\u7684Demo\u4f4d\u4e8e <a href=\"https:\/\/golang.org\/x\/mobile\/example\">https:\/\/golang.org\/x\/mobile\/example<\/a> \u53ef\u4ee5\u76f4\u63a5 <strong>git clone<\/strong> \u4e0b\u6765\uff0c\u8fdb\u5165 <strong>example<\/strong> \u76ee\u5f55\u540e\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u4e0b\u8f7d\u4f9d\u8d56\u3002<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$ go get -d golang.org\/x\/mobile\/example\/basic<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u968f\u540e\uff0c\u4f7f\u7528 <strong>gomobile build<\/strong> \u76f4\u63a5\u5c06\u793a\u4f8b\u4ee3\u7801\u6253\u5305\u6210\u4e00\u4e2a <strong>apk<\/strong> \u3002<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$ gomobile build -target=android golang.org\/x\/mobile\/example\/basic<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\u6267\u884c\u8fd9\u4e00\u6b65\u7684\u65f6\u5019\uff0c\u7ec8\u7aef\u7f3a\u76f4\u63a5\u62a5\u9519\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">gomobile: ~\/Library\/Android\/sdk\/ndk-bundle\/toolchains\/llvm\/prebuilt\/darwin-x86_64\/bin\/arm-linux-androideabi-nm \/var\/folders\/09\/4vfx52xs0r5_0dl7s5g8qchr0000gn\/T\/gomobile-work-745714058\/lib\/armeabi-v7a\/libbasic.so: fork\/exec ~\/Library\/Android\/sdk\/ndk-bundle\/toolchains\/llvm\/prebuilt\/darwin-x86_64\/bin\/arm-linux-androideabi-nm: no such file or directory<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fdb\u5165 <strong>~\/Library\/Android\/sdk\/ndk-bundle\/toolchains\/llvm\/prebuilt\/darwin-x86_64\/bin\/<\/strong> \u8fd9\u4e2a\u76ee\u5f55\u770b\u4e86\u4e0b\u786e\u5b9e\u4e0d\u5b58\u5728 <strong>arm-linux-androideabi-nm<\/strong> \u8fd9\u4e2a\u6587\u4ef6\u3002\u4ece\u6587\u4ef6\u8def\u5f84\u6765\u770b <strong>gomobile<\/strong> \u5e94\u8be5\u662f\u901a\u8fc7 <strong>NDK<\/strong> \u7684\u65b9\u5f0f\u8fdb\u884c\u7f16\u8bd1\uff0c\u5728\u53c2\u8003\u4e86<a href=\"https:\/\/github.com\/golang\/go\/issues\/16268\">\u76f8\u5173\u7684ISSUE<\/a>\u540e\uff0c\u7b14\u8005\u4e0b\u8f7d\u4e86 android-ndk-r12b-linux-x86_64.zip \u8fd9\u4e2a\u7248\u672c\u7684NDK\u5e76\u4e14\u5c06 <strong>arm-linux-androideabi-nm<\/strong> \u590d\u5236\u5230\u4e86\u62a5\u9519\u7684\u8def\u5f84\uff0c\u7ee7\u7eed\u6267\u884c <strong>gomobile build<\/strong> \u5374\u53d1\u73b0\u8fd8\u662f\u62a5\u9519\u3002<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">gomobile: ~\/Library\/Android\/sdk\/ndk-bundle\/toolchains\/llvm\/prebuilt\/darwin-x86_64\/bin\/aarch64-linux-android-nm \/var\/folders\/09\/4vfx52xs0r5_0dl7s5g8qchr0000gn\/T\/gomobile-work-553399005\/lib\/arm64-v8a\/libbasic.so: fork\/exec ~\/Library\/Android\/sdk\/ndk-bundle\/toolchains\/llvm\/prebuilt\/darwin-x86_64\/bin\/aarch64-linux-android-nm: no such file or directory<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u539f\u6765\u662f\u7f3a\u5931\u53e6\u4e00\u4e2aCPU\u67b6\u6784\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5728 android-ndk-r12b-linux-x86_64\u4e2d\u627e\u5230\u540c\u540d\u6587\u4ef6\uff0c\u76f4\u63a5\u590d\u5236\u5230\u62a5\u9519\u8def\u5f84\u540e\u5c31\u53ef\u4ee5\u4e86\u3002\u4f46\u662f\u6267\u884c\u8fd8\u662f\u62a5\u9519\uff0c\u63d0\u793a\u7f3a\u5c11 <strong>i686-linux-android-nm<\/strong> \u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u7ecf\u8fc7\u4e86\u53cd\u590d\u6298\u817e\uff0c\u67e5\u9605\u4e86\u51e0\u4e2a\u5c0f\u65f6\u8d44\u6599\uff0c\u5bf9\u6bd4\u4e86\u51e0\u4e2aNDK Bundle\u540e\uff0c\u7ec8\u4e8e\u53d1\u73b0\u95ee\u9898\u6240\u5728\u3002\u7531\u4e8e\u7b14\u8005\u4f7f\u7528\u7684\u7cfb\u7edf\u662f <strong>macOS Big Sur 11.2.1<\/strong> \uff0cAndroid Studio\u53ea\u6709Beta\u7248\u53ef\u4ee5\u5f88\u597d\u7684\u652f\u6301\u8fd9\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u3002\u4f46\u662f <strong>Android Studio 4.2 Preview<\/strong> \u7684 <strong>SDK Manager<\/strong> \u4e2d\u9ed8\u8ba4\u4e0b\u8f7d\u7684NDK\uff08\u7248\u672c\u53f7 23.0.7196353-beta2\uff09\u5c45\u7136\u4e0d\u662f\u5b8c\u6574\u7248\uff0c\u7f3a\u5c11\u4e86\u5f88\u591a\u5305\u62ec <strong>nm<\/strong> \u3001 <strong>objcopy<\/strong> \u7b49\u91cd\u8981\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u6240\u4ee5\u53ea\u9700\u8981\u5728 <strong>SDK Manager<\/strong> \u52fe\u9009 <strong>Show Package Details<\/strong> \uff0c\u5c55\u5f00 <strong>NDK(Side by side)<\/strong> \u540e\u9009\u62e9\u7a33\u5b9a\u7248 <strong>21.4.7075529<\/strong> \u5b89\u88c5\u5373\u53ef\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img.hjwzs.xyz\/images\/2024\/01\/02\/mmQ1.png\" alt=\"image-20210406224426421\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b89\u88c5\u540e\uff0c\u5982\u679c\u4f60\u7535\u8111\u4e0aNDK\u7684\u73af\u5883\u53d8\u91cf\u5173\u8054\u4e86\u7248\u672c\uff0c\u9700\u8981\u8bb0\u5f97\u5728 <strong>~\/.bash_profile<\/strong> \uff08\u6216\u8005 <strong>~\/.zshrc<\/strong> \uff0c\u770b\u4f60\u4f7f\u7528\u7684shell\uff09\u4e2d\u4fee\u6539NDK\u7684\u7248\u672c\u8def\u5f84\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">export ANDROID_NDK_HOME=$ANDROID_HOME\/ndk\/21.4.7075529\n# \u4fee\u6539\u540e\u6267\u884c source ~\/.bash_profile<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u518d\u6b21\u6267\u884c <strong>gomobile build<\/strong> \u540e\u4fbf\u53ef\u4ee5\u5728\u76ee\u5f55\u4e2d\u770b\u5230\u5df2\u7ecf\u7f16\u8bd1\u751f\u6210\u4e86 <strong>basic.apk<\/strong> \u3002 \u5c06\u8fd9\u4e2a <strong>apk<\/strong> \u62d6\u5165AVD\uff0c\u8fd0\u884c <strong>Basic<\/strong> \u8fd9\u4e2aApp\u5c31\u53ef\u4ee5\u770b\u5230\u5b98\u65b9Demo\u7684\u6548\u679c\u5566~<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img.hjwzs.xyz\/images\/2024\/01\/02\/mF72.png\" alt=\"image-20210406224838552\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4f17\u6240\u5468\u77e5\uff0c flutter \u662f Google \u5728 2018 \u5e74\u53d1\u5e03\uff0c\u7528\u4e8e\u539f\u751f\u8de8\u7aef\uff08\u5f53\u7136 2.0 \u53ef\u4ee5\u505a\u66f4\u591a\u7684\u4e8b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[7,9],"class_list":["post-166","post","type-post","status-publish","format-standard","hentry","category-experience-sharing","tag-golang","tag-mobile"],"_links":{"self":[{"href":"https:\/\/hjwzs.xyz\/index.php?rest_route=\/wp\/v2\/posts\/166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hjwzs.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hjwzs.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hjwzs.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hjwzs.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=166"}],"version-history":[{"count":2,"href":"https:\/\/hjwzs.xyz\/index.php?rest_route=\/wp\/v2\/posts\/166\/revisions"}],"predecessor-version":[{"id":168,"href":"https:\/\/hjwzs.xyz\/index.php?rest_route=\/wp\/v2\/posts\/166\/revisions\/168"}],"wp:attachment":[{"href":"https:\/\/hjwzs.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hjwzs.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hjwzs.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}