{"id":400,"date":"2023-02-25T10:46:39","date_gmt":"2023-02-25T02:46:39","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=400"},"modified":"2023-04-29T21:37:59","modified_gmt":"2023-04-29T13:37:59","slug":"dependency-changes-for-android-gradle-4-1-and-above-compile-api-and-implementation","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/dependency-changes-for-android-gradle-4-1-and-above-compile-api-and-implementation\/","title":{"rendered":"Android Gradle 4.1\u4ee5\u4e0a\u4f9d\u8d56\u53d8\u5316\uff1acompile->api\u548cimplementation"},"content":{"rendered":"<h2>\u73af\u5883\u51c6\u5907<\/h2>\n<p>\u5347\u7ea7Gradle\u63d2\u4ef6\u81f33.0.0\u53ca\u4ee5\u4e0a<\/p>\n<pre><code>dependencies {\n    classpath &#039;com.android.tools.build:gradle:3.1.3&#039;\n}<\/code><\/pre>\n<p><!-- more --><\/p>\n<ul>\n<li>Gradle\u7248\u672c\u5347\u7ea7\u52304.1\u53ca\u4ee5\u4e0a<\/li>\n<li><code>gradle-plugin<\/code>\u7248\u672c\u5347\u7ea7\u52303.0.0\u53ca\u4ee5\u4e0a<\/li>\n<\/ul>\n<h2>\u4f9d\u8d56\u4f7f\u7528api\u548cimplementation\uff0c\u5e9f\u5f03compile<\/h2>\n<h3>implementation\u7684\u201c\u8bbf\u95ee\u9694\u79bb\u201d\u53ea\u4f5c\u7528\u5728\u7f16\u8bd1\u671f<\/h3>\n<p>Gradle\u63d2\u4ef6\u5347\u7ea7\u52303.0.0\u4ee5\u4e0a\u6700\u5927\u7684\u533a\u522b\u662f\u4f9d\u8d56\u65b9\u5f0f\u7684\u6539\u53d8\uff1a<\/p>\n<p>![Gradle implementation\u7f16\u8bd1\u671f\u8bbf\u95ee\u9694\u79bb](<a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/www.yezhou.me\/AppBlog\/images\/Android\/Gradle\">http:\/\/www.yezhou.me\/AppBlog\/images\/Android\/Gradle<\/a> implementation\u7f16\u8bd1\u671f\u8bbf\u95ee\u9694\u79bb.jpg)<\/p>\n<p>implementation\u7684\u201c\u8bbf\u95ee\u9694\u79bb\u201d\u53ea\u4f5c\u7528\u5728\u7f16\u8bd1\u671f\u3002\u4ec0\u4e48\u610f\u601d\u5462\uff1f\u5982\u679clib C implementation\u4f9d\u8d56lib A 2.0\u7248\u672c\uff0clib B implementation\u4f9d\u8d56lib A 1.0\u7248\u672c\uff1a<\/p>\n<ul>\n<li>\u90a3\u4e48\u7f16\u8bd1\u671f\uff0clibC \u53ef\u8bbf\u95ee2.0\u7248\u672c\u7684libA \uff0clibB\u53ef\u8bbf\u95ee1.0\u7248\u672c\u7684libA\u3002\u4f46\u6700\u7ec8\u6253\u5230apk\u4e2d\u7684\u662f2.0\u7248\u672c\uff08\u901a\u8fc7\u4f9d\u8d56\u6811\u53ef\u770b\u5230\uff09<\/li>\n<li>\u5728\u8fd0\u884c\u671f\uff0clib B \u548clib C\u90fd\u53ef\u8bbf\u95eelib A\u76842.0\u7248\u672c\uff08\u56e0\u4e3aapk\u7684\u6240\u6709dex\u90fd\u4f1a\u653e\u5230classLoader\u7684dexPathList\u4e2d\uff09<\/li>\n<\/ul>\n<h3>\u4f7f\u7528implementation\u7684\u597d\u5904<\/h3>\n<p>\u5982\u679c\u9879\u76ee\u4e2d\u6709\u5f88\u591a\u7ea7\u8054\u7684\u5de5\u7a0b\u4f9d\u8d56\uff0c\u6bd4\u5982\u4e0a\u56fe\u4e2dlib A B C\u7684\u4f9d\u8d56\u662f\u5de5\u7a0b\u4f9d\u8d56\u3002\u5982\u679c\u4f7f\u7528\u7684\u4f9d\u8d56\u65b9\u5f0f\u662fcompile\/api\uff0c\u90a3\u4e48\u5f53lib A\u63a5\u53e3\u4fee\u6539\u540e\u91cd\u65b0\u7f16\u8bd1\u65f6\uff0c\u4f1a\u91cd\u65b0\u7f16\u8bd1lib A B C\uff08\u5373\u4f7flib C\u4e2d\u5e76\u6ca1\u6709\u7528\u5230\u4fee\u6539\u7684libA\u7684\u63a5\u53e3\uff09\u3002\u5982\u679c\u4f7f\u7528implementation\u4f9d\u8d56\uff0c\u56e0\u4e3a\u201c\u7f16\u8bd1\u671f\u9694\u79bb\u201d\u7684\u539f\u56e0\uff0c\u4e0d\u76f8\u5173\u7684lib\u5c31\u4e0d\u4f1a\u8fdb\u884c\u91cd\u65b0\u7f16\u8bd1\u3002<\/p>\n<p>\u5982\u679c\u9879\u76ee\u4e2d\u90fd\u662faar\u4f9d\u8d56\uff0c\u7f16\u8bd1\u51cf\u5c11\u65f6\u957f\u8fd9\u4e2a\u4f18\u70b9\u5c31\u6ca1\u6709\u4e86\uff08\u56e0\u4e3aaar\u5df2\u7ecf\u662f\u7f16\u8bd1\u597d\u7684\u5b57\u8282\u7801\uff09\u3002\u90a3\u4e48\u8fd8\u6709\u4ec0\u4e48\u7528\u5462\uff1f\u8fd8\u662f\u4ee5\u4e0a\u56fe\u4e3a\u4f8b\u3002\u4e4b\u524d\u6211\u4eec\u90fd\u662fcompile\u4f9d\u8d56\uff0c\u5982\u679clib B\u5df2\u7ecf\u4f9d\u8d56\u4e86lib A\uff0c\u90a3\u4e48\u5728lib C\u7684build.gradle\u4e2d\u5c31\u4e0d\u7528\u5199lib A\u7684\u4f9d\u8d56\u4e86\u3002\u4f46\u8fd9\u6837\u4f1a\u6709\u95ee\u9898\uff1a <\/p>\n<ul>\n<li>\u4ecelib C\u7684build.gradle\u7684\u4f9d\u8d56\u5217\u8868\u4e2d\u4e0d\u80fd\u5b8c\u6574\u7684\u77e5\u9053lib C\u90fd\u9700\u8981\u4f9d\u8d56\u54ea\u4e9blib\u3002<\/li>\n<li>\u5047\u8bbe\u9879\u76ee\u4e2d\u4f9d\u8d56\u7684lib A\u7684\u6700\u9ad8\u7248\u672c\u662f2.0\uff0c\u90a3\u4e48app\u8fd0\u884c\u65f6\u5c31\u662f\u4f7f\u7528\u7684\u8fd9\u4e2a2.0\u7248\u672c\u7684lib A\u3002\u8fd9\u65f6\u5019\u9700\u8981\u6253\u4e00\u4e2alib C\u7684aar\u3002lib C\u5982\u679c\u901a\u8fc7compile\u4f20\u9012\u4f9d\u8d56\u4e86lib A\uff0c\u6b64\u65f6\u4ecelib C\u7684build.gradle\u4e2d\u4e0d\u77e5\u9053lib C \u7f16\u8bd1\u65f6\u4f9d\u8d56\u7684\u662f\u54ea\u4e2a\u7248\u672c\u7684lib A\u3002\u5982\u679clib C \u6253\u5305aar\uff08\u7f16\u8bd1\uff09\u65f6\uff0c\u4f9d\u8d56\u7684\u4ecd\u7136libA 1.0\uff0c\u53ef\u80fd\u8fd9\u4e2aaar\u5c31\u6709\u95ee\u9898\u3002<br \/>\n\u6240\u4ee5\u4f7f\u7528implementation\u662f\u4e00\u79cd\u6bd4\u8f83\u89c4\u8303\u7684\u4f9d\u8d56\u505a\u6cd5\u3002\u867d\u7136\u53ef\u80fd\u9700\u8981\u591a\u5199\u4e00\u5199\u4f9d\u8d56\uff0c\u4f46\u662f\u9879\u76ee\u7684\u53ef\u8bfb\u6027\u662f\u6709\u5f88\u5927\u597d\u5904\u7684\uff08\u867d\u7136\u591a\u5199\u4e00\u4e9b\u4f9d\u8d56\uff0capk\u6253\u5305\u8fd0\u884c\u65f6\u4ecd\u7136\u662f\u91c7\u7528\u6700\u9ad8\u7248\u672c\u7684lib\uff0c\u6240\u4ee5\u5bf9\u8fd0\u884c\u4e0d\u5f71\u54cd\uff09\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u73af\u5883\u51c6\u5907 \u5347\u7ea7Gradle\u63d2\u4ef6\u81f33.0.0\u53ca\u4ee5\u4e0a dependencies { classpath &#038;#039 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[202],"tags":[64],"class_list":["post-400","post","type-post","status-publish","format-standard","hentry","category-android-build","tag-gradle"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/400","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=400"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/400\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}