{"id":5792,"date":"2014-12-29T09:49:56","date_gmt":"2014-12-29T01:49:56","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=5792"},"modified":"2014-12-29T09:49:56","modified_gmt":"2014-12-29T01:49:56","slug":"android%e5%bf%ab%e9%80%9f%e8%87%aa%e5%8a%a8%e7%94%9f%e6%88%90%e6%b8%a0%e9%81%93%e5%8c%85%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/5792.html","title":{"rendered":"Android\u5feb\u901f\u81ea\u52a8\u751f\u6210\u6e20\u9053\u5305\u65b9\u6cd5"},"content":{"rendered":"<p>\u5982\u679c\u80fd\u76f4\u63a5\u4fee\u6539apk\u7684\u6e20\u9053\u53f7\uff0c\u800c\u4e0d\u9700\u8981\u518d\u91cd\u65b0\u7b7e\u540d\u80fd\u8282\u7701\u4e0d\u5c11\u6253\u5305\u7684\u65f6\u95f4\u3002\u5e78\u8fd0\u7684\u662f\u6211\u4eec\u627e\u5230\u4e86\u8fd9\u79cd\u65b9\u6cd5\u3002\u76f4\u63a5\u89e3\u538bapk\uff0c\u89e3\u538b\u540e\u7684\u6839\u76ee\u5f55\u4f1a\u6709\u4e00\u4e2aMETA-INF\u76ee\u5f55\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><a href=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2014\/12\/apk_packaging2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5793\" alt=\"apk_packaging2\" src=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2014\/12\/apk_packaging2.jpg\" width=\"211\" height=\"207\" srcset=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2014\/12\/apk_packaging2.jpg 211w, https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2014\/12\/apk_packaging2-152x150.jpg 152w\" sizes=\"auto, (max-width: 211px) 100vw, 211px\" \/><\/a><\/p>\n<p>\u5982\u679c\u5728META-INF\u76ee\u5f55\u5185\u6dfb\u52a0\u7a7a\u6587\u4ef6\uff0c\u53ef\u4ee5\u4e0d\u7528\u91cd\u65b0\u7b7e\u540d\u5e94\u7528\u3002\u56e0\u6b64\uff0c\u901a\u8fc7\u4e3a\u4e0d\u540c\u6e20\u9053\u7684\u5e94\u7528\u6dfb\u52a0\u4e0d\u540c\u7684\u7a7a\u6587\u4ef6\uff0c\u53ef\u4ee5\u552f\u4e00\u6807\u8bc6\u4e00\u4e2a\u6e20\u9053\u3002<\/p>\n<p>\u4e0b\u9762\u7684python\u4ee3\u7801\u7528\u6765\u7ed9apk\u6dfb\u52a0\u7a7a\u7684\u6e20\u9053\u6587\u4ef6\uff0c\u6e20\u9053\u540d\u7684\u524d\u7f00\u4e3amtchannel_\uff1a<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport zipfile\r\nzipped = zipfile.ZipFile(your_apk, 'a', zipfile.ZIP_DEFLATED)\r\nempty_channel_file = &quot;META-INF\/mtchannel_{channel}&quot;.format(channel=your_channel)\r\nzipped.write(your_empty_file, empty_channel_file)\r\n<\/pre>\n<p>\u6dfb\u52a0\u5b8c\u7a7a\u6e20\u9053\u6587\u4ef6\u540e\u7684\u76ee\u5f55\uff0cMETA-INFO\u76ee\u5f55\u591a\u4e86\u4e00\u4e2a\u540d\u4e3amtchannel_meituan\u7684\u7a7a\u6587\u4ef6\uff1a<\/p>\n<p><a href=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2014\/12\/apk_packaging3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5794\" alt=\"apk_packaging3\" src=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2014\/12\/apk_packaging3.jpg\" width=\"294\" height=\"234\" srcset=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2014\/12\/apk_packaging3.jpg 294w, https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2014\/12\/apk_packaging3-188x150.jpg 188w\" sizes=\"auto, (max-width: 294px) 100vw, 294px\" \/><\/a><\/p>\n<p>\u63a5\u4e0b\u6765\u5c31\u53ef\u4ee5\u5728Java\u4ee3\u7801\u4e2d\u8bfb\u53d6\u7a7a\u6e20\u9053\u6587\u4ef6\u540d\u4e86\uff1a<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic static String getChannel(Context context) {\r\n        ApplicationInfo appinfo = context.getApplicationInfo();\r\n        String sourceDir = appinfo.sourceDir;\r\n        String ret = &quot;&quot;;\r\n        ZipFile zipfile = null;\r\n        try {\r\n            zipfile = new ZipFile(sourceDir);\r\n            Enumeration&lt;?&gt; entries = zipfile.entries();\r\n            while (entries.hasMoreElements()) {\r\n                ZipEntry entry = ((ZipEntry) entries.nextElement());\r\n                String entryName = entry.getName();\r\n                if (entryName.startsWith(&quot;mtchannel&quot;)) {\r\n                    ret = entryName;\r\n                    break;\r\n                }\r\n            }\r\n        } catch (IOException e) {\r\n            e.printStackTrace();\r\n        } finally {\r\n            if (zipfile != null) {\r\n                try {\r\n                    zipfile.close();\r\n                } catch (IOException e) {\r\n                    e.printStackTrace();\r\n                }\r\n            }\r\n        }\r\n\r\n        String&#x5B;] split = ret.split(&quot;_&quot;);\r\n        if (split != null &amp;&amp; split.length &gt;= 2) {\r\n            return ret.substring(split&#x5B;0].length() + 1);\r\n\r\n        } else {\r\n            return &quot;&quot;;\r\n        }\r\n    }\r\n<\/pre>\n<p>\u8fd9\u6837\uff0c\u6bcf\u6253\u4e00\u4e2a\u6e20\u9053\u5305\u53ea\u9700\u590d\u5236\u4e00\u4e2aapk\uff0c\u5728META-INF\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u4f7f\u7528\u6e20\u9053\u53f7\u547d\u540d\u7684\u7a7a\u6587\u4ef6\u5373\u53ef\u3002\u8fd9\u79cd\u6253\u5305\u65b9\u5f0f\u901f\u5ea6\u975e\u5e38\u5feb\uff0c900\u591a\u4e2a\u6e20\u9053\u4e0d\u5230\u4e00\u5206\u949f\u5c31\u80fd\u6253\u5b8c\u3002<\/p>\n<p>\u8f6c\u81ea\uff1ahttp:\/\/tech.meituan.com\/mt-apk-packaging.html<\/p>\n<p>\u76f8\u5173\u4ee3\u7801\uff1ahttps:\/\/github.com\/GavinCT\/AndroidMultiChannelBuildTool<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u80fd\u76f4\u63a5\u4fee\u6539apk\u7684\u6e20\u9053\u53f7\uff0c\u800c\u4e0d\u9700\u8981\u518d\u91cd\u65b0\u7b7e\u540d\u80fd\u8282\u7701\u4e0d\u5c11\u6253\u5305\u7684\u65f6\u95f4\u3002\u5e78\u8fd0\u7684\u662f\u6211\u4eec\u627e\u5230\u4e86\u8fd9\u79cd\u65b9\u6cd5\u3002\u76f4\u63a5\u89e3\u538bap [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-5792","post","type-post","status-publish","format-standard","hentry","category-skill"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/5792","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=5792"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/5792\/revisions"}],"predecessor-version":[{"id":5795,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/5792\/revisions\/5795"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=5792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=5792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=5792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}