{"id":2637,"date":"2018-04-14T12:30:19","date_gmt":"2018-04-14T04:30:19","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=2637"},"modified":"2018-04-14T12:30:19","modified_gmt":"2018-04-14T04:30:19","slug":"%e9%98%bf%e9%87%8c-arouter%ef%bc%88%e5%ae%89%e5%8d%93%e8%b7%af%e7%94%b1%e6%a1%86%e6%9e%b6%ef%bc%89%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=2637","title":{"rendered":"\u963f\u91cc ARouter\uff08\u5b89\u5353\u8def\u7531\u6846\u67b6\uff09\u6559\u7a0b"},"content":{"rendered":"<p>\n\t\u6700\u8fd1\u963f\u91cc\u53c8\u5f00\u6e90\u4e86\u4e00\u4e2a\u57fa\u4e8e Android \u7684\u8def\u7531\u6846\u67b6&nbsp;ARouter\u3002ARouter \u662f Android \u5e73\u53f0\u4e2d\u5bf9\u9875\u9762\u3001\u670d\u52a1\u63d0\u4f9b\u8def\u7531\u529f\u80fd\u7684\u4e2d\u95f4\u4ef6\u3002ARouter \u7684\u76ee\u6807\u662f &mdash;&mdash; \u7b80\u5355\u4e14\u591f\u7528\u3002\u672c\u6587\u5c06\u4ecb\u7ecd&nbsp;ARouter \u7684\u7528\u6cd5\u7b49\u3002\n<\/p>\n<p>\n\tARouter \u4e3b\u8981\u5206\u4e3a4\u4e2a\u6a21\u5757\uff1aarouter-api\u3001arouter-compiler\u3001arouter-annotation\u3001arouter-register\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"ARouter\" src=\"https:\/\/raw.githubusercontent.com\/alibaba\/ARouter\/master\/demo\/arouter-demo.gif\" \/>\n<\/p>\n<h2>\n\t\u529f\u80fd\u4ecb\u7ecd<br \/>\n<\/h2>\n<ol>\n<li>\n\t\t\u652f\u6301\u76f4\u63a5\u89e3\u6790\u6807\u51c6URL\u8fdb\u884c\u8df3\u8f6c\uff0c\u5e76\u81ea\u52a8\u6ce8\u5165\u53c2\u6570\u5230\u76ee\u6807\u9875\u9762\u4e2d\n\t<\/li>\n<li>\n\t\t\u652f\u6301\u591a\u6a21\u5757\u5de5\u7a0b\u4f7f\u7528\n\t<\/li>\n<li>\n\t\t\u652f\u6301\u6dfb\u52a0\u591a\u4e2a\u62e6\u622a\u5668\uff0c\u81ea\u5b9a\u4e49\u62e6\u622a\u987a\u5e8f\n\t<\/li>\n<li>\n\t\t\u652f\u6301\u4f9d\u8d56\u6ce8\u5165\uff0c\u53ef\u5355\u72ec\u4f5c\u4e3a\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6\u4f7f\u7528\n\t<\/li>\n<li>\n\t\t\u652f\u6301InstantRun\n\t<\/li>\n<li>\n\t\t\u652f\u6301MultiDex(Google\u65b9\u6848)\n\t<\/li>\n<li>\n\t\t\u6620\u5c04\u5173\u7cfb\u6309\u7ec4\u5206\u7c7b\u3001\u591a\u7ea7\u7ba1\u7406\uff0c\u6309\u9700\u521d\u59cb\u5316\n\t<\/li>\n<li>\n\t\t\u652f\u6301\u7528\u6237\u6307\u5b9a\u5168\u5c40\u964d\u7ea7\u4e0e\u5c40\u90e8\u964d\u7ea7\u7b56\u7565\n\t<\/li>\n<li>\n\t\t\u9875\u9762\u3001\u62e6\u622a\u5668\u3001\u670d\u52a1\u7b49\u7ec4\u4ef6\u5747\u81ea\u52a8\u6ce8\u518c\u5230\u6846\u67b6\n\t<\/li>\n<li>\n\t\t\u652f\u6301\u591a\u79cd\u65b9\u5f0f\u914d\u7f6e\u8f6c\u573a\u52a8\u753b\n\t<\/li>\n<li>\n\t\t\u652f\u6301\u83b7\u53d6Fragment\n\t<\/li>\n<li>\n\t\t\u5b8c\u5168\u652f\u6301Kotlin\u4ee5\u53ca\u6df7\u7f16(\u914d\u7f6e\u89c1\u6587\u672b \u5176\u4ed6#5)\n\t<\/li>\n<li>\n\t\t\u652f\u6301\u7b2c\u4e09\u65b9 App \u52a0\u56fa(\u4f7f\u7528 arouter-register \u5b9e\u73b0\u81ea\u52a8\u6ce8\u518c)\n\t<\/li>\n<\/ol>\n<h2>\n\t\u5178\u578b\u5e94\u7528<br \/>\n<\/h2>\n<ol>\n<li>\n\t\t\u4ece\u5916\u90e8URL\u6620\u5c04\u5230\u5185\u90e8\u9875\u9762\uff0c\u4ee5\u53ca\u53c2\u6570\u4f20\u9012\u4e0e\u89e3\u6790\n\t<\/li>\n<li>\n\t\t\u8de8\u6a21\u5757\u9875\u9762\u8df3\u8f6c\uff0c\u6a21\u5757\u95f4\u89e3\u8026\n\t<\/li>\n<li>\n\t\t\u62e6\u622a\u8df3\u8f6c\u8fc7\u7a0b\uff0c\u5904\u7406\u767b\u9646\u3001\u57cb\u70b9\u7b49\u903b\u8f91\n\t<\/li>\n<li>\n\t\t\u8de8\u6a21\u5757API\u8c03\u7528\uff0c\u901a\u8fc7\u63a7\u5236\u53cd\u8f6c\u6765\u505a\u7ec4\u4ef6\u89e3\u8026\n\t<\/li>\n<\/ol>\n<h2>\n\t\u57fa\u672c\u7528\u6cd5<br \/>\n<\/h2>\n<p>\n\t\u7b2c\u4e00\u6b65\uff1a\u6dfb\u52a0\u4f9d\u8d56\u548c\u914d\u7f6e\u3002\n<\/p>\n<pre class=\"brush:plain;\">\r\nandroid {\r\n    defaultConfig {\r\n\t...\r\n\tjavaCompileOptions {\r\n\t    annotationProcessorOptions {\r\n\t\targuments = [ moduleName : project.getName() ]\r\n\t    }\r\n\t}\r\n    }\r\n}\r\n\r\ndependencies {\r\n    \/\/ \u66ff\u6362\u6210\u6700\u65b0\u7248\u672c, \u9700\u8981\u6ce8\u610f\u7684\u662fapi\r\n    \/\/ \u8981\u4e0ecompiler\u5339\u914d\u4f7f\u7528\uff0c\u5747\u4f7f\u7528\u6700\u65b0\u7248\u53ef\u4ee5\u4fdd\u8bc1\u517c\u5bb9\r\n    compile &#039;com.alibaba:arouter-api:x.x.x&#039;\r\n    annotationProcessor &#039;com.alibaba:arouter-compiler:x.x.x&#039;\r\n    ...\r\n}\r\n\/\/ \u65e7\u7248\u672cgradle\u63d2\u4ef6(&lt; 2.2)\uff0c\u53ef\u4ee5\u4f7f\u7528apt\u63d2\u4ef6\uff0c\u914d\u7f6e\u65b9\u6cd5\u89c1\u6587\u672b&#039;\u5176\u4ed6#4&#039;\r\n\/\/ Kotlin\u914d\u7f6e\u53c2\u8003\u6587\u672b&#039;\u5176\u4ed6#5&#039;<\/pre>\n<p>\n\t\u7b2c\u4e8c\u6b65\uff0c\u6dfb\u52a0\u6ce8\u89e3\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\n\/\/ \u5728\u652f\u6301\u8def\u7531\u7684\u9875\u9762\u4e0a\u6dfb\u52a0\u6ce8\u89e3(\u5fc5\u9009)www.xttblog.com\r\n\/\/ \u8fd9\u91cc\u7684\u8def\u5f84\u9700\u8981\u6ce8\u610f\u7684\u662f\u81f3\u5c11\u9700\u8981\u6709\u4e24\u7ea7\uff0c\/xx\/xx\r\n@Route(path = &quot;\/test\/activity&quot;)\r\npublic class YourActivity extend Activity {\r\n    ...\r\n}<\/pre>\n<p>\n\t\u7b2c\u4e09\u6b65\uff0c\u521d\u59cb\u5316SDK\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\nif (isDebug()) {           \/\/ \u8fd9\u4e24\u884c\u5fc5\u987b\u5199\u5728init\u4e4b\u524d\uff0c\u5426\u5219\u8fd9\u4e9b\u914d\u7f6e\u5728init\u8fc7\u7a0b\u4e2d\u5c06\u65e0\u6548\r\n    ARouter.openLog();     \/\/ \u6253\u5370\u65e5\u5fd7\r\n    ARouter.openDebug();   \/\/ \u5f00\u542f\u8c03\u8bd5\u6a21\u5f0f(\u5982\u679c\u5728InstantRun\u6a21\u5f0f\u4e0b\u8fd0\u884c\uff0c\u5fc5\u987b\u5f00\u542f\u8c03\u8bd5\u6a21\u5f0f\uff01\u7ebf\u4e0a\u7248\u672c\u9700\u8981\u5173\u95ed,\u5426\u5219\u6709\u5b89\u5168\u98ce\u9669)\r\n}\/\/ \u4e1a\u4f59\u8349\uff1awww.xttblog.com\r\nARouter.init(mApplication); \/\/ \u5c3d\u53ef\u80fd\u65e9\uff0c\u63a8\u8350\u5728Application\u4e2d\u521d\u59cb\u5316<\/pre>\n<p>\n\t\u7b2c\u56db\u6b65\uff0c\u53d1\u8d77\u8def\u7531\u64cd\u4f5c\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\n\/\/ 1. \u5e94\u7528\u5185\u7b80\u5355\u7684\u8df3\u8f6c(\u901a\u8fc7URL\u8df3\u8f6c\u5728&#039;\u8fdb\u9636\u7528\u6cd5&#039;\u4e2d)\r\nARouter.getInstance().build(&quot;\/test\/activity&quot;).navigation();\r\n\/\/ \u4e1a\u4f59\u8349\uff1awww.xttblog.com\r\n\/\/ 2. \u8df3\u8f6c\u5e76\u643a\u5e26\u53c2\u6570\r\nARouter.getInstance().build(&quot;\/test\/1&quot;)\r\n\t\t\t.withLong(&quot;key1&quot;, 666L)\r\n\t\t\t.withString(&quot;key3&quot;, &quot;888&quot;)\r\n\t\t\t.withObject(&quot;key4&quot;, new Test(&quot;Jack&quot;, &quot;Rose&quot;))\r\n\t\t\t.navigation();<\/pre>\n<p>\n\t\u7b2c\u4e94\u6b65\uff0c\u6dfb\u52a0\u6df7\u6dc6\u89c4\u5219(\u5982\u679c\u4f7f\u7528\u4e86Proguard)\u3002\n<\/p>\n<pre class=\"brush:plain;\">\r\n-keep public class com.alibaba.android.arouter.routes.**{*;}\r\n-keep class * implements com.alibaba.android.arouter.facade.template.ISyringe{*;}\r\n\r\n# \u5982\u679c\u4f7f\u7528\u4e86 byType \u7684\u65b9\u5f0f\u83b7\u53d6 Service\uff0c\u9700\u6dfb\u52a0\u4e0b\u9762\u89c4\u5219\uff0c\u4fdd\u62a4\u63a5\u53e3\r\n-keep interface * implements com.alibaba.android.arouter.facade.template.IProvider\r\n\r\n# \u5982\u679c\u4f7f\u7528\u4e86 \u5355\u7c7b\u6ce8\u5165\uff0c\u5373\u4e0d\u5b9a\u4e49\u63a5\u53e3\u5b9e\u73b0 IProvider\uff0c\u9700\u6dfb\u52a0\u4e0b\u9762\u89c4\u5219\uff0c\u4fdd\u62a4\u5b9e\u73b0\r\n-keep class * implements com.alibaba.android.arouter.facade.template.IProvider<\/pre>\n<p>\n\t\u7b2c\u516d\u6b65\uff0c\u4f7f\u7528 Gradle \u63d2\u4ef6\u5b9e\u73b0\u8def\u7531\u8868\u7684\u81ea\u52a8\u52a0\u8f7d\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\napply plugin: &#039;com.alibaba.arouter&#039;\r\n\r\nbuildscript {\r\n    repositories {\r\n        jcenter()\r\n    }\r\n\r\n    dependencies {\r\n        classpath &quot;com.alibaba:arouter-register:1.0.0&quot;\r\n    }\r\n}<\/pre>\n<p>\n\t\u53ef\u9009\u4f7f\u7528\uff0c\u901a\u8fc7 ARouter \u63d0\u4f9b\u7684\u6ce8\u518c\u63d2\u4ef6\u8fdb\u884c\u8def\u7531\u8868\u7684\u81ea\u52a8\u52a0\u8f7d\uff0c\u9ed8\u8ba4\u901a\u8fc7\u626b\u63cf dex \u7684\u65b9\u5f0f \u8fdb\u884c\u52a0\u8f7d\u901a\u8fc7 gradle \u63d2\u4ef6\u8fdb\u884c\u81ea\u52a8\u6ce8\u518c\u53ef\u4ee5\u7f29\u77ed\u521d\u59cb\u5316\u65f6\u95f4\u89e3\u51b3\u5e94\u7528\u52a0\u56fa\u5bfc\u81f4\u65e0\u6cd5\u76f4\u63a5\u8bbf\u95ee dex \u6587\u4ef6\uff0c\u521d\u59cb\u5316\u5931\u8d25\u7684\u95ee\u9898\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8be5\u63d2\u4ef6\u5fc5\u987b\u642d\u914d api 1.3.0 \u4f7f\u7528\uff01<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=2637\">\u963f\u91cc ARouter\uff08\u5b89\u5353\u8def\u7531\u6846\u67b6\uff09\u6559\u7a0b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u963f\u91cc\u53c8\u5f00\u6e90\u4e86\u4e00\u4e2a\u57fa\u4e8e Android \u7684\u8def\u7531\u6846\u67b6&nbsp;ARouter\u3002ARouter \u662f Andro [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[891,1611,852,69,1319],"class_list":["post-2637","post","type-post","status-publish","format-standard","hentry","category-java","tag-android","tag-arouter","tag-html","tag-java","tag-replugin"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2637"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2637\/revisions"}],"predecessor-version":[{"id":2638,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2637\/revisions\/2638"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}