{"id":1861,"date":"2023-03-29T22:09:57","date_gmt":"2023-03-29T14:09:57","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1861"},"modified":"2023-04-22T09:07:47","modified_gmt":"2023-04-22T01:07:47","slug":"tinkerpatch-support-for-flavors-and-reinforcement","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/29\/tinkerpatch-support-for-flavors-and-reinforcement\/","title":{"rendered":"TinkerPatch\u5bf9Flavors\u53ca\u52a0\u56fa\u7684\u652f\u6301"},"content":{"rendered":"<h2>\u5bf9Flavors\u7684\u652f\u6301<\/h2>\n<p>\u5982\u679c\u53ea\u662f\u591a\u6e20\u9053\u7684\u9700\u6c42\uff0c\u5efa\u8bae\u4e0d\u8981\u4f7f\u7528Flavor\u3002\u591aflavor\u5fc5\u987b\u5728\u540e\u53f0\u5efa\u7acb\u76f8\u5e94\u7684\u57fa\u7ebf\u5de5\u7a0b(\u5982\u4e0b\u4f8b\u5b50\u7684\u547d\u540d\u89c4\u5219\u4e3a\uff1a<code>appVersion_flavorName<\/code>)\uff0c\u6bcf\u6b21\u751f\u6210\u8865\u4e01\u65f6\u4e5f\u5fc5\u987b\u5bf9\u5e94\u7684\u751f\u6210\u591a\u4e2a\u5206\u522b\u4e0a\u4f20\u3002<\/p>\n<p><!-- more --><\/p>\n<p>TinkerPatch\u589e\u52a0\u4e86<code>tinkerPatchAllFlavorsDebug<\/code>\u548c<code>tinkerPatchAllFlavorsRelease<\/code>\u7528\u4e8e\u4e00\u6b21\u6027\u751f\u6210\u6240\u6709<code>flavors<\/code>\u7684<code>Patch<\/code>\u5305\u3002<\/p>\n<p>\u5982\u679c\u53ea\u662f\u591a\u6e20\u9053\u7684\u9700\u6c42\uff0c\u5efa\u8bae\u4e0d\u8981\u4f7f\u7528flavor\u7684\u65b9\u5f0f\u3002\u9996\u5148\u5176\u6253\u5305\u5f88\u6162\uff0c\u5176\u6b21\u9700\u8981\u7ef4\u62a4\u591a\u4e2a\u57fa\u7ebf\u5305\uff0c\u540e\u671f\u7ef4\u62a4\u6210\u672c\u4e5f\u5f88\u5927\u3002Tinker\u5b98\u65b9\u63a8\u8350<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/mcxiaoke\/packer-ng-plugin\" title=\"packer-ng-plugin\">packer-ng-plugin<\/a>\u6216\u8005<code>walle<\/code>\u6765\u8fdb\u884c\u591a\u6e20\u9053\u6253\u5305\uff0c\u5176\u4e2d<code>walle<\/code>\u662f\u652f\u6301\u6700\u65b0\u7684<code>SchemaV2<\/code>\u7b7e\u540d\u7684\u3002<\/p>\n<p>\u5177\u4f53\u53ef\u4ee5\u53c2\u7167\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/TinkerPatch\/tinkerpatch-flavors-sample\" title=\"tinkerpatch-flavors-sample\">tinkerpatch-flavors-sample<\/a><\/p>\n<p>\u5728<code>TinkerPatchSupport<\/code>\u4e2d\u6dfb\u52a0\u5982\u4e0b\u5b57\u6bb5\uff1a<\/p>\n<pre><code class=\"language-java\">\/** \n * \u82e5\u6709\u7f16\u8bd1\u591aflavors\u9700\u6c42\uff0c\u53ef\u5728flavors\u4e2d\u8986\u76d6\u4ee5\u4e0b\u53c2\u6570\n * \u4e5f\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7tinkerPatchAllFlavorDebug\/tinkerPatchAllFlavorRelease\uff0c\u4e00\u6b21\u7f16\u8bd1\u6240\u6709\u7684flavor\u8865\u4e01\u5305\n * \u6ce8\u610f\u7684\u662f\uff1a\u9664\u975e\u4e0d\u540c\u7684flavor\u4ee3\u7801\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u4e0d\u7136\u5efa\u8bae\u91c7\u7528zip comment\u6216\u8005\u6587\u4ef6\u65b9\u5f0f\u751f\u6210\u6e20\u9053\u4fe1\u606f\n **\/\nproductFlavors {\n    flavor {\n        flavorName = &quot;flavor1&quot;\n        \/\/ \u540e\u53f0\u9700\u8981\u6309\u7167\u6bcf\u4e2aflavor\u7684appVersion\u6765\u5efa\u7acb\u72ec\u7acb\u7684\u5de5\u7a0b\uff0c\u5e76\u5355\u72ec\u4e0b\u53d1\u8865\u4e01\n        appVersion = &quot;${tinkerpatchSupport.appVersion}_${flavorName}&quot;\n\n        pathPrefix = &quot;${bakPath}\/${baseInfo}\/${flavorName}${buildType}\/&quot;\n        name = &quot;${project.name}-${flavorName}${buildType}&quot;\n\n        baseApkFile = &quot;${pathPrefix}\/${name}.apk&quot;\n        baseProguardMappingFile = &quot;${pathPrefix}\/${name}-mapping.txt&quot;\n        baseResourceRFile = &quot;${pathPrefix}\/${name}-R.txt&quot;\n    }\n\n    flavor {\n        flavorName = &quot;flavor2&quot;\n        \/\/ \u540e\u53f0\u9700\u8981\u6309\u7167\u6bcf\u4e2aflavor\u7684appVersion\u6765\u5efa\u7acb\u72ec\u7acb\u7684\u5de5\u7a0b\uff0c\u5e76\u5355\u72ec\u4e0b\u53d1\u8865\u4e01\n        appVersion = &quot;${tinkerpatchSupport.appVersion}_${flavorName}&quot;\n\n        pathPrefix = &quot;${bakPath}\/${baseInfo}\/${flavorName}${buildType}\/&quot;\n        name = &quot;${project.name}-${flavorName}${buildType}&quot;\n\n        baseApkFile = &quot;${pathPrefix}\/${name}.apk&quot;\n        baseProguardMappingFile = &quot;${pathPrefix}\/${name}-mapping.txt&quot;\n        baseResourceRFile = &quot;${pathPrefix}\/${name}-R.txt&quot;\n    }\n}<\/code><\/pre>\n<h2>\u5bf9\u52a0\u56fa\u7684\u652f\u6301<\/h2>\n<h3>\u57fa\u672c\u914d\u7f6e<\/h3>\n<p>\u8fd9\u91cc\u9ed8\u8ba4\u6709\u540c\u65f6\u751f\u6210\u52a0\u56fa\u6e20\u9053\u4e0e\u975e\u52a0\u56fa\u6e20\u9053\u7684\u9700\u6c42\uff0c\u5982\u679c\u53ea\u662f\u5355\u4e00\u9700\u8981\u52a0\u56fa\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728\u914d\u7f6e\u4e2d\u5f00\u542f<code>protectedApp = true<\/code>\u5373\u53ef<\/p>\n<p>\u53ef\u4ee5\u53c2\u8003<code>tinkerpatch.gradle<\/code>\u6587\u4ef6\uff0c\u5177\u4f53\u5de5\u7a0b\u53ef\u4ee5\u53c2\u7167<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/TinkerPatch\/tinkerpatch-flavors-sample\" title=\"tinkerpatch-flavors-sample\">tinkerpatch-flavors-sample<\/a><\/p>\n<pre><code class=\"language-java\">productFlavors {\n    flavor {\n        flavorName = &quot;protect&quot;\n        appVersion = &quot;${tinkerpatchSupport.appVersion}_${flavorName}&quot;\n\n        pathPrefix = &quot;${bakPath}\/${baseInfo}\/${flavorName}-${variantName}\/&quot;\n        name = &quot;${project.name}-${flavorName}-${variantName}&quot;\n\n        baseApkFile = &quot;${pathPrefix}\/${name}.apk&quot;\n        baseProguardMappingFile = &quot;${pathPrefix}\/${name}-mapping.txt&quot;\n        baseResourceRFile = &quot;${pathPrefix}\/${name}-R.txt&quot;\n\n        \/** \u5f00\u542f\u52a0\u56fa\u5f00\u5173\uff0c\u4e0a\u4f20\u6b64flavor\u7684apk\u5230\u52a0\u56fa\u7f51\u7ad9\u8fdb\u884c\u52a0\u56fa **\/\n        protectedApp = true\n    }\n\n    flavor {\n        flavorName = &quot;flavor1&quot;\n        appVersion = &quot;${tinkerpatchSupport.appVersion}_${flavorName}&quot;\n\n        pathPrefix = &quot;${bakPath}\/${baseInfo}\/${flavorName}-${variantName}\/&quot;\n        name = &quot;${project.name}-${flavorName}-${variantName}&quot;\n\n        baseApkFile = &quot;${pathPrefix}\/${name}.apk&quot;\n        baseProguardMappingFile = &quot;${pathPrefix}\/${name}-mapping.txt&quot;\n        baseResourceRFile = &quot;${pathPrefix}\/${name}-R.txt&quot;\n    }\n}<\/code><\/pre>\n<h3>\u52a0\u56fa\u6b65\u9aa4<\/h3>\n<ul>\n<li>\u751f\u6210\u5f00\u542f<code>protectedApp = true<\/code>\u7684\u57fa\u7840\u5305\uff08\u8fd9\u91cc\u5047\u8bbe\u6b64APK\u540d\u4e3a\uff1a<code>protected.apk<\/code>\uff09<\/li>\n<li>\u4e0a\u4f20<code>protected.apk<\/code>\u5230\u76f8\u5e94\u7684\u52a0\u56fa\u7f51\u7ad9\u8fdb\u884c\u52a0\u56fa\uff0c\u5e76\u53d1\u5e03\u5e94\u7528\u5e02\u573a(\u8bf7\u9075\u5faa\u5404\u4e2a\u52a0\u56fa\u7f51\u7ad9\u6b65\u9aa4\uff0c\u4e00\u822c\u4e3a\u4e0b\u8f7d\u52a0\u56fa\u5305-&gt;\u91cd\u65b0\u7b7e\u540d-&gt;\u53d1\u5e03\u91cd\u7b7e\u540d\u52a0\u56fa\u5305)<\/li>\n<li>\u5728<code>tinkerPatch<\/code>\u540e\u53f0\u6839\u636e<code>appVersion<\/code>\u5efa\u7acb\u76f8\u5e94\u7684App\u7248\u672c(\u6bd4\u5982\u8fd9\u91cc2\u4e2a<code>flavor<\/code>\uff0c\u5c31\u9700\u8981\u5efa\u7acb2\u4e2aApp\u7248\u672c\u3002App\u7248\u672c\u5373\u4e3a\u5404\u81ea<code>flavor<\/code>\u4e2d\u914d\u7f6e\u7684appVersion)<\/li>\n<li>\u57fa\u4e8e\u5404\u4e2a<code>flavor<\/code>\u7684\u57fa\u7840\u5305\uff08\u8fd9\u91cc\u7684\u57fa\u7840\u5305\u662f\u7b2c\u4e00\u6b65\u4e2d\u751f\u6210\u7684\u672a\u52a0\u56fa\u7684\u7248\u672c\uff09\u751f\u6210\u76f8\u5e94<code>patch<\/code>\u5305\uff0c\u5e76\u4e0a\u4f20\u81f3\u76f8\u5e94\u7684App\u7248\u672c\u4e2d\uff0c\u5373\u5b8c\u6210\u8865\u4e01\u53d1\u5e03<\/li>\n<\/ul>\n<h3>\u652f\u6301\u5217\u8868<\/h3>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u52a0\u56fa\u5382\u5546<\/th>\n<th style=\"text-align: left;\">\u6d4b\u8bd5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\u4e50\u52a0\u56fa<\/td>\n<td style=\"text-align: left;\">Tested<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u7231\u52a0\u5bc6<\/td>\n<td style=\"text-align: left;\">Tested<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u6886\u6886\u52a0\u56fa<\/td>\n<td style=\"text-align: left;\">Tested<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">360\u52a0\u56fa<\/td>\n<td style=\"text-align: left;\">Tested<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u5176\u4ed6<\/td>\n<td style=\"text-align: left;\">\u8bf7\u81ea\u884c\u6d4b\u8bd5\uff0c\u53ea\u8981\u6ee1\u8db3\u4e0b\u9762\u89c4\u5219\u7684\u90fd\u53ef\u4ee5\u652f\u6301<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u91cc\u662f\u5426\u652f\u6301\u52a0\u56fa\uff0c\u9700\u8981\u52a0\u56fa\u5382\u5546\u660e\u786e\u4ee5\u4e0b\u4e24\u70b9\uff1a<\/p>\n<ul>\n<li>\u4e0d\u80fd\u63d0\u524d\u5bfc\u5165\u7c7b<\/li>\n<li>\u5728<code>art<\/code>\u5e73\u53f0\u82e5\u8981\u7f16\u8bd1<code>oat<\/code>\u6587\u4ef6\uff0c\u9700\u8981\u5c06\u5185\u8054\u53d6\u6d88<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5bf9Flavors\u7684\u652f\u6301 \u5982\u679c\u53ea\u662f\u591a\u6e20\u9053\u7684\u9700\u6c42\uff0c\u5efa\u8bae\u4e0d\u8981\u4f7f\u7528Flavor\u3002\u591aflavor\u5fc5\u987b\u5728\u540e\u53f0\u5efa\u7acb\u76f8\u5e94\u7684\u57fa\u7ebf [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[311],"tags":[465],"class_list":["post-1861","post","type-post","status-publish","format-standard","hentry","category-android-advance","tag-tinker"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1861"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1861\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}