{"id":44,"date":"2015-07-10T10:43:14","date_gmt":"2015-07-10T10:43:14","guid":{"rendered":"https:\/\/boochlin.com\/?p=44"},"modified":"2016-07-30T21:16:41","modified_gmt":"2016-07-30T21:16:41","slug":"android-runtime-resource-overlay","status":"publish","type":"post","link":"https:\/\/boochlin.com\/?p=44","title":{"rendered":"Android runtime resource overlay"},"content":{"rendered":"<h1>Android runtime resource overlay<\/h1>\n<p>&nbsp;<\/p>\n<p>\u6216\u8a31\u53ef\u4ee5\u5148\u770b\u770b<br \/>\n<a title=\"http:\/\/developer.sonymobile.com\/2014\/04\/22\/sony-contributes-runtime-resource-overlay-framework-to-android-code-example\/\" href=\"http:\/\/developer.sonymobile.com\/2014\/04\/22\/sony-contributes-runtime-resource-overlay-framework-to-android-code-example\/\" target=\"_blank\">http:\/\/developer.sonymobile.com\/2014\/04\/22\/sony-contributes-runtime-resource-overlay-framework-to-android-code-example\/<\/a><br \/>\n\u9019\u4f4d\u8001\u5144M\u00e5rten Kongstad\u7b97\u662f\u76ee\u524d\u6709\u6bd4\u8f03\u5b8c\u6574\u518d\u8ac7 runtime resources overlay \u7684\u7b2c\u4e00\u4eba<br \/>\n\u5982\u679c\u82f1\u6587\u9084\u884c\u7684\u8a71\u7684\u53ef\u4ee5\u76f4\u63a5\u770b\u539f\u6587<br \/>\n\u786c\u8981\u8aaa\u7684\u8a71\u6700\u597d\u6709\u5bebassetmanager \u7684\u6982\u5ff5\uff0c\u6703\u6bd4\u8f03\u7406\u89e3\u9019\u4e2d\u9593\u7684\u539f\u7406<br \/>\n\u53ef\u4ee5\u642d\u914d\u8001\u7f85\u5927\u5e2b\u7684\u5e7e\u7bc7\u6587\u7ae0\uff08\u8001\u7f85\u771f\u7684\u5f88\u731b\uff0c\u53ef\u60dc\u4ed6\u7684\u66f8\u6709\u9ede\u820a\u4e86\uff0c\u4e0d\u7136\u9084\u771f\u60f3\u8cb7\u4e00\u672c\uff09<br \/>\n<a title=\"http:\/\/blog.csdn.net\/luoshengyang\/article\/details\/8738877\" href=\"http:\/\/blog.csdn.net\/luoshengyang\/article\/details\/8738877\" target=\"_blank\">http:\/\/blog.csdn.net\/luoshengyang\/article\/details\/8738877<\/a><\/p>\n<p>\u6b63\u6587\u958b\u59cb<br \/>\n\u7e8c\u524d\u4e00\u7bc7 Android \u5be6\u4f5c data\/control \u5206\u96e2 &#8211; createPackageContext()<br \/>\n\u9019\u7a2e\u65b9\u6cd5\u9054\u5230\u5ba2\u88fd\u5316\u7684\u529f\u80fd\uff0c\u518d android l \u4e4b\u5f8c\u53ef\u4ee5\u4e0d\u7528\u641e\u7684\u90a3\u67d0\u9ebb\u7169<br \/>\n\u7531sony \u7684\u5718\u968a \u63d0\u51fa\u4e00\u5957\u65b0\u7684 resources match framework.<br \/>\nRuntime Resource Overlay (RRO) \uff0csony \u672c\u8eab\u4e5f\u540c\u6642\u5229\u7528\u65bc Xperia Themes.<br \/>\n\u6240\u4ee5\u5f88\u660e\u986f\u7684 \u9019\u5c31\u662f\u8981\u7528\u5728\u63db\u5716\u7247\uff0c\u80cc\u666f\u4e4b\u985e\u7684\u795e\u5175\u5229\u5668.<\/p>\n<p><!--more--><\/p>\n<h3>Original Mechanism<\/h3>\n<p>Resources in Android consist of three parts:<br \/>\n1. A symbolic name \u2013 package.type\/name, for example com.android.launcher.string\/hello_world.<br \/>\n2. A set of configuration constraints that must not be violated if this resource\u2019s value is to be used.<br \/>\n3. An actual value.<br \/>\n\u6839\u64da\u4ee5\u4e0a\u9019\u4e9b\u8cc7\u8a0a \u53ef\u4ee5\u81ea\u52d5\u6279\u914d\u5230\u6700\u9069\u5408\u7684\u6a5f\u5668\u72c0\u6cc1<br \/>\n<img decoding=\"async\" src=\"http:\/\/developer.android.com\/images\/resources\/res-selection-flowchart.png\" alt=\"how to match resource\" \/><\/p>\n<p>\u4e0a\u8ff0\u5339\u914d\u898f\u5247\u9019\u5c31\u4e0d\u8a73\u8ac7\u4e86(\u770b\u5b98\u7db2\u6216\u8001\u7f85\u6bd4\u8f03\u5feb)\uff0c\u76f4\u63a5\u89e3\u91cb\u5e95\u4e0b\u9019\u5f35\u5716\u7247<br \/>\n<img decoding=\"async\" src=\"http:\/\/developer-static.se-mc.com\/wp-content\/blogs.dir\/1\/files\/2014\/04\/vanilla-resource-lookup.png\" alt=\"getresoures\" \/><\/p>\n<p>\u5728android\u88e1\u958b\u767c\u4e2d\u5e38\u5e38\u7528\u5230\u7684\u8a9e\u6cd5<\/p>\n<pre>context.getresources().getdrawable(r.id.hello_world);\r\n<\/pre>\n<p>\u9019\u5c31\u662f\u6307\u5b9a resources \u53bb\u53d6\u8cc7\u6599<\/p>\n<p>\u63a5\u8005\u6b64 resources id \u8cc7\u6599\u6703\u50b3\u7d66 system \u7684 assetmanager\uff0c \u5229\u7528 id+package name +\u6a5f\u5668\u7684 configure(cfg)<br \/>\n\u9032\u884c\u6700\u9069\u5408\u7684\u8cc7\u6599\u6279\u914d\uff08\u7b2c\u4e00\u5f35\u5716\uff09\uff0c\u53d6\u5f97\u552f\u4e00\u7684id\u503c\uff080x7f\uff09\uff0c\u6700\u5f8c\u5229\u7528\u9019\u503c\u5230apk\u62ff\u51fa\u8cc7\u6e90\uff0c\u81f3\u65bc\u5de6\u908a\u7684 framework-res.apk \u5247\u662f android \u63d0\u4f9b\u7684\u539f\u751f\u7d20\u6750\uff0c\u8cc7\u6599\u7b49\uff0c\u53ef\u4ee5\u767c\u73feresource id\u90fd\u662f 0x01 \u958b\u982d<\/p>\n<p>\u5c31\u662f\u5229\u7528\u9019\u6a23\u7684\u6a5f\u5236\uff0c\u53ef\u4ee5\u8b93application \u6839\u64da\u4e0d\u540c\u7684\u6a5f\u5668\u72c0\u614b\u63d0\u4f9b\u5408\u9069\u7684\u8cc7\u6e90\uff0c\u9019\u4e5f\u662f\u70ba\u4f55\u5927\u90e8\u5206\u7684ap\u958b\u767c\u8005\u90fd\u6703\u5728res\/\u5e95\u4e0b\u8a2d\u8a08\u4e0d\u540c\u7684\u5716\u7247\u8cc7\u6e90\u6216\u662f\u8a9e\u7cfb\u5c0d\u61c9\uff0c\u800c\u5728\u6b64\u4e4b\u4e0a\uff0c\u6211\u60f3sony\u60f3\u8981\u66f4\u52a0\u9032\u4e00\u6b65\uff0c\u66f4\u5f48\u6027\u7684\u63d0\u4f9b\u9019\u4e9b\u8cc7\u6e90\u53bb\u5c0d\u61c9theme\u7684\u5c0d\u61c9\uff0c\u800c\u4e0d\u662f\u5728\u6bcf\u6b21\u66f4\u65b0\u624d\u63d0\u4f9b\u65b0\u7684\u6a23\u8c8c\uff0c\u56e0\u6b64\u63d0\u51fa\u4e86\u65b0\u7684runtime resources overlay\u7684\u6a5f\u5236\u7d66google<br \/>\n\u4ee5\u4fbf\u5728framework\u66fe\u5c31\u628a\u9019\u4e9b\u9ebb\u7169\u7684\u5916\u90e8\u8cc7\u6e90access\u7d66\u4f5c\u6389<\/p>\n<h3>How to use\u00a0Runtime resource overlay<\/h3>\n<p>\u524d\u9762\u6b77\u53f2\u8b1b\u4e86\u90a3\u67d0\u591a\uff0c\u5176\u5be6\u7528\u8d77\u4f86\u975e\u5e38\u822c\u55ae\u7d14\uff0c\u9664\u4e86\u4f60\u672c\u4f86\u5c31\u7528\u88ab\u8986\u84cb\u7684\u76ee\u6a19\uff0c\u4ee5launcher\u70ba\u4f8b\uff0c<br \/>\n(\u9019\u662f\u4e00\u500b\u5e0c\u671b\u5e38\u5e38\u8b8a\u66f4\u98a8\u683c\u7684app\uff0c\u6216\u662f\u60f3\u8981\u5ba2\u88fd\u5316\u7684\u90e8\u5206)<br \/>\n<a href=\"https:\/\/boochlin.com\/?p=41\">(\u53ef\u4ee5\u8df3\u5230\u9019\u7bc7\u6587\u7ae0\uff0c\u770b\u770b\u70ba\u4f55\u9700\u8981\u9019\u7a2e\u8981\u6c42)<\/a><\/p>\n<p>\u4e00\u500b\u5c08\u9580overlay\u5225\u4eba\u7684ap\uff0c\u4ee5\u4e0b\u70ba\u5fc5\u8981\u7684\u5e7e\u500b\u8981\u4ef6<br \/>\n1. Have an AndroidManifest.xml.<br \/>\n2. May be installed.<br \/>\n3. Are built using aapt.<\/p>\n<p>\u5728AndroidManifest\u52a0\u5165\u4f60\u60f3\u8981\u8986\u84cb\u7684\u5c0d\u8c61<\/p>\n<pre>\u00a0&lt;overlay android:priority=\"2\" android:targetPackage=\"com.example.android.launcher\"\/&gt;<\/pre>\n<p>\u56e0\u70ba\u540c\u6642\u53ef\u80fd\u6703\u6709\u597d\u5e7e\u500b\u60f3\u8981\u53bboverlay\u7684ap(resources1.apk , resources2.apk)\uff0c\u9019\u6642\u5019\u7cfb\u7d71\u5c31\u6703\u53bb\u6bd4\u5c0dpriority \u503c\uff0c\u8d8a\u9ad8\u7684\u70ba\u8d8a\u512a\u5148\uff0c\u5982\u679c\u6c92\u6709\u6307\u5b9apriority\u5247\u4ee5\u5f8c\u5b89\u88dd\u7684\u70ba\u4e3b\uff0c\u9664\u4e86\u9019\u6a23\uff0c\u4f60\u60f3overlay\u7684\u8cc7\u6e90\uff0c\u5fc5\u9808\u8ddf\u5c0d\u8c61\u64fa\u5728\u76f8\u540c\u7684\u5c0d\u61c9\u8def\u5f91\uff0c\u4e14\u6709\u76f8\u540c\u7684name.<\/p>\n<h3>Runtime resource \u00a0overlay\u00a0Mechanism<\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/developer-static.se-mc.com\/wp-content\/blogs.dir\/1\/files\/2014\/04\/multiple-overlays-resource-lookup.png\" alt=\"image_overlay\" \/><\/p>\n<p>\u4e0a\u8ff0\u9019\u5f35\u5716\u7684\u8def\u5f91\u8ddf\u7b2c\u4e8c\u5f35\u5716\u883b\u50cf\u7684\uff0c\u5c31\u53ea\u5dee\u5728\u627e\u8cc7\u6e90\u7684\u6642\u5019\u6703\u4e00\u500b\u4e00\u500boverlay\u7684apk\u90fd\u53bb\u6aa2\u7d22\u4e00\u6b21\uff0ctarget apk\u662f\u6700\u5f8c\u4e00\u500b\u627e\u7684\uff0c\u5176\u4ed6\u591a\u500boverlay apk \u5247\u6839\u64dapriority\u6c7a\u5b9a\u63db\u4e0a\u90a3\u4e00\u5f35\u5716<\/p>\n<h3>\u5b89\u5168\u6027\u5462?<\/h3>\n<p>\u9019\u5957\u529f\u80fd\u611f\u89ba\u975e\u5e38\u5a01\u731b\uff0c\u7562\u7adf\u53ef\u4ee5\u96a8\u610f\u4e82\u8986\u84cb\u5225\u4eba\u7684ap\u8cc7\u6e90\uff0c\u90a3\u4e0d\u5c31\u4ee3\u8868\u53ef\u4ee5\u60e1\u641e\u5225\u4eba\u7684ap\uff0c\u50cf\u662f welcome , \u6539\u6210shock\u7684\u5b57\u4e32\uff0c\u5176\u5be6\u9019\u4e5f\u6c92\u90a3\u67d0\u5bb9\u6613\uff0c\u7562\u7adf\u4f60\u8981\u77e5\u9053\u5176\u4ed6\u4eba\u7684ap package name(\u96d6\u7136\u4e0d\u96e3), \u9084\u6709 id \u5c0d\u61c9name<br \/>\n(\u5176\u5be6\u9019\u4e5f\u4e0d\u96e3\uff0c\u7562\u7adfdecompile \u90fd\u4e00\u5806\u4eba\u90fd\u5728\u6559\u4e86)\uff0c\u4e0a\u9762\u6211\u90fd\u8aaa\u4e86\u4e00\u5c0d\u4e0d\u96e3\u4e86\uff0c\u96e3\u9053google\u6703\u89ba\u5f97\u96e3\u55ce\uff0c\u6240\u4ee5\u4ed6\u76ee\u524d\u70ba\u4e86\u5b89\u5168\u6027\uff0c\u9650\u5236\u6240\u6709overlay apk\uff0c\u90fd\u6703\u653e\u5728device\u7684\/vendor\/overlay\uff0c\u800c\u9019\u500b\u76ee\u9304\u4e00\u822c\u958b\u767c\u8005\u662f\u6c92\u8fa6\u6cd5access\u7684(\u81f3\u5c11\u8981root)\u3002<br \/>\nvendor\u5011\u60f3\u8981\u5229\u7528google play \u7684\u66f4\u65b0\u6a5f\u5236\u4e5f\u5fc5\u9808\u78ba\u4fdd\u662f\u540c\u500bsign key\uff0c\u6240\u4ee5\u76ee\u524d\u770b\u8d77\u4f86\uff0c\u4e00\u822c\u958b\u767c\u8005\u9084\u662f\u4e0d\u592a\u80fd\u5229\u7528\u9019\u6a23\u7684\u6a5f\u5236<\/p>\n<h3>\u7e3d\u662f\u6709\u500b\u6975\u9650<\/h3>\n<p>\u60f3\u8981overlay\u7684\u6771\u897f\u767e\u767e\u7a2e\uff0c\u4f46\u662f\u9019\u6a5f\u5236\u4e5f\u6c92\u6709\u90a3\u67d0\u53b2\u5bb3<br \/>\n1. \u81f3\u5c11\u8981\u6709\u500bid\u5427\uff0c\u4e5f\u5c31\u662f\u8aaa\u53ea\u8981\u6709id\u5c31\u6709\u6a5f\u6703(integers, strings, drawable, arrays, and so on)<br \/>\n2. AndroidManifest.xml \u9019\u500b\u4e0d\u884c(\u540c\u4e0a)<br \/>\n3. overlay reference \u5230\u5176\u4ed6\u7684 reference(\u9019\u5f88\u96e3\u89e3\u91cb\uff0c\u7b49\u958b\u4e0b\u4e00\u7bc7)<\/p>\n<h3>try it.<\/h3>\n<p>\u6700\u5f8c\u4f60\u8eab\u70ba\u4e00\u500b\u958b\u767c\u8005\uff0c\u81ea\u5df1\u4e5f\u53bb\u62c9code\uff0c\u6216\u8005\u662f\u540c\u696d\u53bb\u62c9\u9ad8\u901a\uff0c\u767c\u54e5\u7684code\uff0c\u7136\u5f8c\u4e5f\u9075\u5b88\u4e0a\u8ff0\u7684\u898f\u5247\u3002\u767c\u73fe\u9084\u662f\u6c92\u6709\u9019\u6a5f\u5236\uff0c\u90a3\u8acb\u4f60\u4e00\u5b9a\u5148\u53bb\u78ba\u8a8doverlay\u7684id name \u76f8\u95dc\u898f\u5247(\u6211\u771f\u7684\u9047\u5230\u5f88\u591a\u4eba\u540d\u5b50\u6253\u932f)<\/p>\n<p>\u5982\u679c\u9084\u662f\u6c92\u554f\u984c\uff0c\u90a3\u61c9\u8a72\u5c31\u662fcode base \u6839\u672c\u6c92\u4e0a\u9019\u5e7e\u689dpatch<br \/>\n&#8212;-<br \/>\nruntime resources overlay patch<br \/>\n<a title=\"https:\/\/android-review.googlesource.com\/#\/c\/113651\/\" href=\"https:\/\/android-review.googlesource.com\/#\/c\/113651\/\" target=\"_blank\">https:\/\/android-review.googlesource.com\/#\/c\/113651\/<\/a><br \/>\n<a title=\"https:\/\/android-review.googlesource.com\/#\/c\/113652\/\" href=\"https:\/\/android-review.googlesource.com\/#\/c\/113652\/\" target=\"_blank\">https:\/\/android-review.googlesource.com\/#\/c\/113652\/<\/a><br \/>\n<a title=\"https:\/\/android-review.googlesource.com\/#\/c\/113653\/\" href=\"https:\/\/android-review.googlesource.com\/#\/c\/113653\/\" target=\"_blank\">https:\/\/android-review.googlesource.com\/#\/c\/113653\/<\/a><br \/>\n<a title=\"https:\/\/android-review.googlesource.com\/#\/c\/121589\/\" href=\"https:\/\/android-review.googlesource.com\/#\/c\/121589\/\" target=\"_blank\">https:\/\/android-review.googlesource.com\/#\/c\/121589\/<\/a><\/p>\n<p>\u7d50\u675f\uff0c\u4e0b\u4e00\u7bc7\u8003\u616e\u5beb\u9047\u5230\u7684\u5404\u7a2e\u7591\u96e3\u96dc\u75c7<\/p>\n<p>ref:<\/p>\n<p><a title=\"http:\/\/developer.sonymobile.com\/2014\/04\/22\/sony-contributes-runtime-resource-overlay-framework-to-android-code-example\/\" href=\"http:\/\/developer.sonymobile.com\/2014\/04\/22\/sony-contributes-runtime-resource-overlay-framework-to-android-code-example\/\" target=\"_blank\">http:\/\/developer.sonymobile.com\/2014\/04\/22\/sony-contributes-runtime-resource-overlay-framework-to-android-code-example\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android runtime resource overlay &nbsp; \u6216\u8a31\u53ef\u4ee5\u5148\u770b\u770b http:\/\/developer.sonymobile.com\/2014\/04\/22\/sony-cont&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[6,9,49],"_links":{"self":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/44"}],"collection":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=44"}],"version-history":[{"count":1,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/44\/revisions\/162"}],"wp:attachment":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}