{"id":8238,"date":"2023-09-07T15:08:40","date_gmt":"2023-09-07T07:08:40","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=8238"},"modified":"2023-09-07T15:08:40","modified_gmt":"2023-09-07T07:08:40","slug":"android%e5%a4%9a%e6%b8%a0%e9%81%93%e6%89%93%e5%8c%85apk%e6%98%af%e4%bb%80%e4%b9%88%e6%84%8f%e6%80%9d%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/8238\/","title":{"rendered":"android\u591a\u6e20\u9053\u6253\u5305apk\u662f\u4ec0\u4e48\u610f\u601d\uff1f"},"content":{"rendered":"

\u624b\u673a\u6253\u5305apk\u5de5\u5177\u7eff\u8272\u7248<\/a> <\/p>\n

\u591a\u6e20\u9053\u6253\u5305\u662f\u6307\u5728\u53d1\u5e03Android\u5e94\u7528\u65f6\uff0c\u6839\u636e\u4e0d\u540c\u6e20\u9053\u7684\u9700\u6c42\u751f\u6210\u4e0d\u540c\u7684APK\u6587\u4ef6\uff0c\u4ee5\u5b9e\u73b0\u5728\u4e0d\u540c\u6e20\u9053\u5206\u53d1\u548c\u8fd0\u8425\u7684\u76ee\u7684\u3002\u4ee5\u4e0b\u662f\u5173\u4e8e\u591a\u6e20\u9053\u6253\u5305APK\u540d\u79f0\u7684\u539f\u7406\u548c\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n

\u5728Android\u5e94\u7528\u53d1\u5e03\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5f00\u53d1\u8005\u901a\u5e38\u4f1a\u9009\u62e9\u4e0d\u540c\u7684\u6e20\u9053\u8fdb\u884c\u5206\u53d1\u548c\u63a8\u5e7f\u3002\u4e0d\u540c\u7684\u6e20\u9053\u53ef\u80fd\u6709\u4e0d\u540c\u7684\u8981\u6c42\u548c\u6807\u8bc6\uff0c\u6bd4\u5982\u5e94\u7528\u7684\u540d\u79f0\u3001\u56fe\u6807\u3001\u63a8\u5e7f\u6e20\u9053\u7b49\u7b49\u3002\u4e3a\u4e86\u6ee1\u8db3\u4e0d\u540c\u6e20\u9053\u7684\u9700\u6c42\uff0c\u5f00\u53d1\u8005\u9700\u8981\u6839\u636e\u4e0d\u540c\u6e20\u9053\u751f\u6210\u4e0d\u540c\u7684APK\u6587\u4ef6\uff0c\u4ee5\u4fdd\u8bc1\u5e94\u7528\u5728\u5404\u4e2a\u6e20\u9053\u7684\u6b63\u5e38\u8fd0\u884c\u548c\u5c55\u793a\u3002<\/p>\n

\u591a\u6e20\u9053\u6253\u5305\u7684\u5b9e\u73b0\u539f\u7406\u662f\u901a\u8fc7\u5728Android Gradle\u6784\u5efa\u5de5\u5177\u4e2d\u914d\u7f6e\u4e0d\u540c\u7684Build Variants\u6765\u751f\u6210\u4e0d\u540c\u7684APK\u6587\u4ef6\u3002Build Variants\u662fGradle\u6784\u5efa\u5de5\u5177\u63d0\u4f9b\u7684\u4e00\u79cd\u65b9\u5f0f\uff0c\u7528\u4e8e\u5728\u540c\u4e00\u4e2a\u9879\u76ee\u4e2d\u751f\u6210\u4e0d\u540c\u7684\u6784\u5efa\u7248\u672c\u3002\u6bcf\u4e2aBuild Variant\u90fd\u6709\u72ec\u7acb\u7684\u914d\u7f6e\u6587\u4ef6\u548c\u8d44\u6e90\u6587\u4ef6\uff0c\u53ef\u4ee5\u6839\u636e\u4e0d\u540c\u7684\u9700\u6c42\u8fdb\u884c\u5b9a\u5236\u3002\u901a\u8fc7\u914d\u7f6e\u4e0d\u540c\u7684Build Variants\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u4e0d\u540c\u7684\u6e20\u9053\u751f\u6210\u4e0d\u540c\u7684APK\u6587\u4ef6\u3002<\/p>\n

\u5728Android Gradle\u6784\u5efa\u5de5\u5177\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728build.gradle\u6587\u4ef6\u4e2d\u914d\u7f6eproductFlavors\u6765\u5b9a\u4e49\u4e0d\u540c\u7684Build Variants\u3002\u6bcf\u4e2aproductFlavor\u90fd\u53ef\u4ee5\u6307\u5b9a\u4e0d\u540c\u7684\u5e94\u7528\u540d\u79f0\u548c\u5e94\u7528\u6807\u8bc6\uff0c\u4ee5\u53ca\u5176\u4ed6\u9700\u8981\u5b9a\u5236\u7684\u53c2\u6570\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u6e20\u9053\u5206\u522b\u914d\u7f6e\u4e0d\u540c\u7684\u5e94\u7528\u540d\u79f0\uff0c\u5e76\u5728\u4ee3\u7801\u4e2d\u5f15\u7528\u76f8\u5e94\u7684\u8d44\u6e90\u6587\u4ef6\u3002\u540c\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e\u4e0d\u540c\u7684buildTypes\u6765\u6307\u5b9a\u751f\u6210APK\u6587\u4ef6\u7684\u547d\u540d\u89c4\u5219\u548c\u5176\u4ed6\u76f8\u5173\u914d\u7f6e\u3002<\/p>\n

\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u7684build.gradle\u914d\u7f6e\u6587\u4ef6\uff0c\u6f14\u793a\u4e86\u5982\u4f55\u5b9a\u4e49\u4e0d\u540c\u7684productFlavors\u548cbuildTypes\u6765\u5b9e\u73b0\u591a\u6e20\u9053\u6253\u5305\uff1a<\/p>\n

“`groovy<\/p>\n

android {<\/p>\n

\/\/ …<\/p>\n

flavorDimensions “default”<\/p>\n

productFlavors {<\/p>\n

channelA {<\/p>\n

dimension “default”<\/p>\n

applicationIdSuffix “.channelA”<\/p>\n

resValue “string”, “app_name”, “Channel A”<\/p>\n

}<\/p>\n

channelB {<\/p>\n

dimension “default”<\/p>\n

applicationIdSuffix “.channelB”<\/p>\n

resValue “string”, “app_name”, “Channel B”<\/p>\n

}<\/p>\n

}<\/p>\n

buildTypes {<\/p>\n

debug {<\/p>\n

\/\/ ..\u6253\u5305\u79bb\u7ebf\u5b89\u5353apk<\/a>.<\/p>\n

}<\/p>\n

release {<\/p>\n

\/\/ …<\/p>\n

}<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u5728\u4e0a\u8ff0\u914d\u7f6e\u4e2d\uff0c\u901a\u8fc7\u5b9a\u4e49\u4e0d\u540c\u7684productFlavors\uff08channelA\u548cchannelB\uff09\u6765\u5b9e\u73b0\u591a\u6e20\u9053\u6253\u5305\u3002\u6bcf\u4e2aproductFlavor\u90fd\u5b9a\u4e49\u4e86\u4e0d\u540c\u7684applicationIdSuffix\uff08\u5e94\u7528\u6807\u8bc6\u7684\u540e\u7f00\uff09\u548cresValue\uff08\u5e94\u7528\u540d\u79f0\uff09\u3002\u5728\u6700\u7ec8\u751f\u6210\u7684APK\u6587\u4ef6\u4e2d\uff0c\u4f1a\u5c06\u4e0d\u540c\u7684\u5e94\u7528\u6807\u8bc6\u548c\u540d\u79f0\u5e94\u7528\u5230\u76f8\u5e94\u7684\u6e20\u9053\u3002<\/p>\n

\u5728Android Studio\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u9009\u62e9\u5bf9\u5e94\u7684Build Variants\u6765\u6784\u5efa\u4e0d\u540c\u7684\u6e20\u9053\u7248\u672c\u3002\u6bcf\u6b21\u6784\u5efa\u65f6\uff0cGradle\u4f1a\u6839\u636e\u9009\u62e9\u7684Build Variant\u751f\u6210\u5bf9\u5e94\u7684APK\u6587\u4ef6\uff0c\u5e76\u6839\u636e\u914d\u7f6e\u7684\u547d\u540d\u89c4\u5219\u7ed9APK\u6587\u4ef6\u547d\u540d\u3002<\/p>\n

\u603b\u7ed3\u6765\u8bf4\uff0c\u591a\u6e20\u9053\u6253\u5305APK\u540d\u79f0\u7684\u539f\u7406\u662f<\/p>\n

<\/figure>\n<\/p>\n

\u901a\u8fc7\u914d\u7f6e\u4e0d\u540c\u7684Build Variants\uff0c\u5728\u6784\u5efa\u8fc7\u7a0b\u4e2d\u6839\u636e\u6e20\u9053\u7684\u9700\u6c42\u751f\u6210\u4e0d\u540c\u7684APK\u6587\u4ef6\u3002\u901a\u8fc7\u5b9a\u4e49productFlavors\u548cbuildTypes\uff0c\u53ef\u4ee5\u5b9e\u73b0\u4e0d\u540c\u6e20\u9053\u7684\u5b9a\u5236\u5316\u9700\u6c42\uff0c\u5305\u62ec\u5e94\u7528\u540d\u79f0\u3001\u5e94\u7528\u6807\u8bc6\u7b49\u7b49\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u8fdb\u884c\u914d\u7f6e\uff0c\u5e76\u901a\u8fc7\u9009\u62e9\u4e0d\u540c\u7684Build Variants\u6765\u6784\u5efa\u548c\u53d1\u5e03\u4e0d\u540c\u6e20\u9053\u7684APK\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u591a\u6e20\u9053\u6253\u5305\u662f\u6307\u5728\u53d1\u5e03Android\u5e94\u7528\u65f6\uff0c\u6839\u636e\u4e0d\u540c\u6e20\u9053\u7684\u9700\u6c42\u751f\u6210\u4e0d\u540c\u7684APK\u6587\u4ef6\uff0c\u4ee5\u5b9e\u73b0\u5728\u4e0d\u540c\u6e20\u9053\u5206\u53d1\u548c\u8fd0\u8425\u7684\u76ee\u7684\u3002\u4ee5\u4e0b\u662f\u5173\u4e8e\u591a\u6e20\u9053\u6253\u5305APK\u540d\u79f0\u7684\u539f\u7406\u548c\u8be6\u7ec6\u4ecb\u7ecd\u3002\u5728Android\u5e94\u7528\u53d1\u5e03\u7684\u8fc7\u7a0b\u4e2d\uff0c<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[14562,10462,14563,171,780],"class_list":{"0":"post-8238","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-zuoapp","7":"tag-apk","8":"tag-10462","10":"tag-171","11":"tag-780"},"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/8238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=8238"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/8238\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=8238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=8238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=8238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}