{"rsdb":{"rid":"286743","subhead":"","postdate":"0","aid":"203287","fid":"76","uid":"1","topic":"1","content":"
\n
\n \u539f\u6587\u51fa\u5904\uff1a \n \u66fe\u662f\u653e\u725b\u5a03<\/a>\n <\/div> \n
\n

\"\"<\/a><\/p> \n

\u4e4b\u524d\u5bf9 Android Gradle \u6784\u5efa\u7684\u4f9d\u8d56\u4e00\u76f4\u50bb\u50bb\u5206\u4e0d\u6e05\uff0c\u8fd9\u6bb5\u65f6\u95f4\u6b63\u597d\u63a5\u5165\u96c6\u56e2\u7684\u4e00\u4e2a\u4e8c\u65b9\u5e93\uff0c\u8e29\u4e86\u5f88\u591a\u5751\uff0c\u4e5f\u987a\u5e26\u628a Gradle \u4f9d\u8d56\u8fd9\u5757\u641e\u6e05\u695a\u4e86\uff0c\u4e3b\u8981\u6574\u7406\u4e86\u4e0b Gradle \u4f9d\u8d56\u7684\u7c7b\u578b\u3001\u4f9d\u8d56\u914d\u7f6e\u3001\u5982\u4f55\u67e5\u770b\u4f9d\u8d56\u3001\u4f9d\u8d56\u51b2\u7a81\u5982\u4f55\u89e3\u51b3\u3002<\/span><\/p> \n

\u4f9d\u8d56\u7c7b\u578b<\/h3> \n

dependencies DSL \u6807\u7b7e\u662f\u6807\u51c6 Gradle API \u4e2d\u7684\u4e00\u90e8\u5206\uff0c\u800c\u4e0d\u662f Android Gradle \u63d2\u4ef6\u7684\u7279\u6027\uff0c\u6240\u4ee5\u5b83\u4e0d\u5c5e\u4e8e Android \u6807\u7b7e\u3002
\u4f9d\u8d56\u6709\u4e09\u79cd\u65b9\u5f0f\uff0c\u5982\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a<\/p> \n <\/div> \n

apply plugin: 'com.android.application'\r\n\r\nandroid { ... }\r\n\r\ndependencies {\r\n    \/\/ Dependency on a local library module\r\n    implementation project(":mylibrary")\r\n\r\n    \/\/ Dependency on local binaries\r\n    implementation fileTree(dir: 'libs', include: ['*.jar'])\r\n\r\n    \/\/ Dependency on a remote binary\r\n    implementation 'com.example.android:app-magic:12.3'\r\n}<\/pre> \n 

\u672c\u5730 library \u6a21\u5757\u4f9d\u8d56<\/strong><\/p> \n

implementation project(":mylibrary")<\/pre> \n 

\u8fd9\u79cd\u4f9d\u8d56\u65b9\u5f0f\u662f\u76f4\u63a5\u4f9d\u8d56\u672c\u5730\u5e93\u5de5\u7a0b\u4ee3\u7801\u7684\uff08\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cmylibrary \u7684\u540d\u5b57\u5fc5\u987b\u5339\u914d\u5728 settings.gradle \u4e2d include \u6807\u7b7e\u4e0b\u5b9a\u4e49\u7684\u6a21\u5757\u540d\u5b57\uff09\u3002<\/p> \n

\u672c\u5730\u4e8c\u8fdb\u5236\u4f9d\u8d56<\/strong><\/p> \n

implementation fileTree(dir: 'libs', include: ['*.jar'])<\/pre> \n 

\u8fd9\u79cd\u4f9d\u8d56\u65b9\u5f0f\u662f\u4f9d\u8d56\u5de5\u7a0b\u4e2d\u7684 module_name\/libs\/ \u76ee\u5f55\u4e0b\u7684 Jar \u6587\u4ef6\uff08\u6ce8\u610f Gradle \u7684\u8def\u5f84\u662f\u76f8\u5bf9\u4e8e build.gradle \u6587\u4ef6\u6765\u8bfb\u53d6\u7684\uff0c\u6240\u4ee5\u4e0a\u9762\u662f\u8fd9\u6837\u7684\u76f8\u5bf9\u8def\u5f84\uff09\u3002<\/p> \n

\u5982\u679c\u53ea\u60f3\u4f9d\u8d56\u5355\u4e2a\u7279\u5b9a\u672c\u5730\u4e8c\u8fdb\u5236\u5e93\uff0c\u53ef\u4ee5\u5982\u4e0b\u914d\u7f6e\uff1a<\/p> \n

implementation files('libs\/foo.jar', 'libs\/bar.jar')<\/pre> \n 

\u8fdc\u7a0b\u4e8c\u8fdb\u5236\u4f9d\u8d56<\/strong><\/p> \n

implementation 'com.example.android:app-magic:12.3'<\/pre> \n 

\u4e0a\u9762\u662f\u7b80\u5199\u7684\u65b9\u5f0f\uff0c\u8fd9\u79cd\u4f9d\u8d56\u5b8c\u6574\u7684\u5199\u6cd5\u5982\u4e0b\uff1a<\/p> \n

implementation group: 'com.example.android', name: 'app-magic', version: '12.3'<\/pre> \n 
\n

group\u3001name\u3001version\u5171\u540c\u5b9a\u4f4d\u4e00\u4e2a\u8fdc\u7a0b\u4f9d\u8d56\u5e93\u3002\u9700\u8981\u6ce8\u610f\u7684\u70b9\u662f\uff0cversion\u6700\u597d\u4e0d\u8981\u5199\u6210\u201d12.3+\u201d\u8fd9\u79cd\u65b9\u5f0f\uff0c\u9664\u975e\u6709\u660e\u786e\u7684\u9884\u671f\uff0c\u56e0\u4e3a\u975e\u9884\u671f\u7684\u7248\u672c\u66f4\u65b0\u4f1a\u5e26\u6765\u6784\u5efa\u95ee\u9898\u3002\u8fdc\u7a0b\u4f9d\u8d56\u9700\u8981\u5728repositories\u6807\u7b7e\u4e0b\u58f0\u660e\u8fdc\u7a0b\u4ed3\u5e93\uff0c\u4f8b\u5982jcenter()\u3001google()\u3001maven\u4ed3\u5e93\u7b49\u3002<\/p> \n

\u4f9d\u8d56\u914d\u7f6e<\/h3> \n

\u76ee\u524d Gradle \u7248\u672c\u652f\u6301\u7684\u4f9d\u8d56\u914d\u7f6e\u6709\uff1aimplementation\u3001api\u3001compileOnly\u3001runtimeOnly \u548c annotationProcessor\u3002\u5df2\u7ecf\u5e9f\u5f03\u7684\u914d\u7f6e\u6709\uff1acompile\u3001provided\u3001apk\u3001providedCompile\u3002\u6b64\u5916\u4f9d\u8d56\u914d\u7f6e\u8fd8\u53ef\u4ee5\u52a0\u4e00\u4e9b\u914d\u7f6e\u9879\uff0c\u4f8b\u5982 AndroidTestImplementation\u3001debugApi \u7b49\u7b49\u3002<\/span><\/p> \n

\u5e38\u7528\u7684\u662f implementation\u3001api\u3001compileOnly \u4e09\u4e2a\u4f9d\u8d56\u914d\u7f6e\uff0c\u542b\u4e49\u5982\u4e0b\uff1a<\/p> \n <\/div> \n

\n
    \n
  • implementation\uff1a\u4e0ecompile\u5bf9\u5e94\uff0c\u4f1a\u6dfb\u52a0\u4f9d\u8d56\u5230\u7f16\u8bd1\u8def\u5f84\uff0c\u5e76\u4e14\u4f1a\u5c06\u4f9d\u8d56\u6253\u5305\u5230\u8f93\u51fa\uff08aar\u6216apk\uff09\uff0c\u4f46\u662f\u5728\u7f16\u8bd1\u65f6\u4e0d\u4f1a\u5c06\u4f9d\u8d56\u7684\u5b9e\u73b0\u66b4\u9732\u7ed9\u5176\u4ed6module\uff0c\u4e5f\u5c31\u662f\u53ea\u6709\u5728\u8fd0\u884c\u65f6\u5176\u4ed6module\u624d\u80fd\u8bbf\u95ee\u8fd9\u4e2a\u4f9d\u8d56\u4e2d\u7684\u5b9e\u73b0\u3002\u4f7f\u7528\u8fd9\u4e2a\u914d\u7f6e\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u5347\u6784\u5efa\u65f6\u95f4\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u51cf\u5c11\u91cd\u65b0\u7f16\u8bd1\u7684module\u7684\u6570\u91cf\u3002\u5efa\u8bae\uff0c\u5c3d\u91cf\u4f7f\u7528\u8fd9\u4e2a\u4f9d\u8d56\u914d\u7f6e\u3002<\/li> \n
  • api\uff1a\u4e0e compile \u5bf9\u5e94\uff0c\u529f\u80fd\u5b8c\u5168\u4e00\u6837\uff0c\u4f1a\u6dfb\u52a0\u4f9d\u8d56\u5230\u7f16\u8bd1\u8def\u5f84\uff0c\u5e76\u4e14\u4f1a\u5c06\u4f9d\u8d56\u6253\u5305\u5230\u8f93\u51fa\uff08aar \u6216a pk\uff09\u3002\u4e0e implementation \u4e0d\u540c\uff0c\u8fd9\u4e2a\u4f9d\u8d56\u53ef\u4ee5\u4f20\u9012\uff0c\u5176\u4ed6 module \u65e0\u8bba\u5728\u7f16\u8bd1\u65f6\u548c\u8fd0\u884c\u65f6\u90fd\u53ef\u4ee5\u8bbf\u95ee\u8fd9\u4e2a\u4f9d\u8d56\u7684\u5b9e\u73b0\uff0c\u4e5f\u5c31\u662f\u4f1a\u6cc4\u6f0f\u4e00\u4e9b\u4e0d\u5e94\u8be5\u4e0d\u4f7f\u7528\u7684\u5b9e\u73b0\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0cA \u4f9d\u8d56 B\uff0cB \u4f9d\u8d56 C\uff0c\u5982\u679c\u90fd\u662f\u4f7f\u7528 api \u914d\u7f6e\u7684\u8bdd\uff0cA \u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 C \u4e2d\u7684\u7c7b\uff08\u7f16\u8bd1\u65f6\u548c\u8fd0\u884c\u65f6\uff09\u3002\u800c\u5982\u679c\u662f\u4f7f\u7528 implementation \u914d\u7f6e\u7684\u8bdd\uff0c\u5728\u7f16\u8bd1\u65f6\uff0cA \u65e0\u6cd5\u8bbf\u95ee C \u4e2d\u7684\u7c7b\u3002<\/li> \n
  • compileOnly\uff1a\u4e0e provided \u5bf9\u5e94\uff0cGradle \u628a\u4f9d\u8d56\u52a0\u5230\u7f16\u8bd1\u8def\u5f84\uff0c\u7f16\u8bd1\u65f6\u4f7f\u7528\uff0c\u4e0d\u4f1a\u6253\u5305\u5230\u8f93\u51fa\uff08aar \u6216 apk\uff09\u3002\u8fd9\u53ef\u4ee5\u51cf\u5c11\u8f93\u51fa\u7684\u4f53\u79ef\uff0c\u5728\u53ea\u5728\u7f16\u8bd1\u65f6\u9700\u8981\uff0c\u5728\u8fd0\u884c\u65f6\u53ef\u9009\u7684\u60c5\u51b5\uff0c\u5f88\u6709\u7528\u3002<\/li> \n
  • runtimeOnly\uff1a\u4e0e apk \u5bf9\u5e94\u3002Gradle\u6dfb\u52a0\u4f9d\u8d56\u53ea\u6253\u5305\u5230 apk\uff0c\u8fd0\u884c\u65f6\u4f7f\u7528\uff0c\u4f46\u4e0d\u4f1a\u6dfb\u52a0\u5230\u7f16\u8bd1\u8def\u5f84\u3002\u8fd9\u4e2a\u6ca1\u6709\u4f7f\u7528\u8fc7\u3002<\/li> \n
  • annotationProcessor\uff1a\u4e0e compile \u5bf9\u5e94\uff0c\u7528\u4e8e\u6ce8\u89e3\u5904\u7406\u5668\u7684\u4f9d\u8d56\u914d\u7f6e\uff0c\u8fd9\u4e2a\u6ca1\u7528\u8fc7\u3002<\/li> \n <\/ul> \n <\/div> \n
    \n
    \n

    \u67e5\u770b\u4f9d\u8d56\u6811<\/h3> \n

    \u53ef\u4ee5\u67e5\u770b\u5355\u4e2amodule\u6216\u8005\u8fd9\u4e2aproject\u7684\u4f9d\u8d56\uff0c\u901a\u8fc7\u8fd0\u884c\u4f9d\u8d56\u7684 Gradle \u4efb\u52a1\uff0c\u5982\u4e0b\uff1a<\/p> \n

      \n
    1. View -> Tools Windows -> Gradle\uff08\u6216\u8005\u70b9\u51fb\u53f3\u4fa7\u7684 Gradle \u680f\uff09\uff1b<\/li> \n
    2. \u5c55\u5f00 AppName -> Tasks -> Android\uff0c\u7136\u540e\u53cc\u51fb\u8fd0\u884c AndroidDependencies\u3002\u8fd0\u884c\u5b8c\uff0c\u5c31\u4f1a\u5728 Run \u7a97\u53e3\u6253\u51fa\u4f9d\u8d56\u6811\u4e86\u3002<\/li> \n <\/ol> \n

      \u4f9d\u8d56\u51b2\u7a81\u89e3\u51b3<\/h3> \n

      \u968f\u7740\u5f88\u591a\u4f9d\u8d56\u52a0\u5165\u5230\u9879\u76ee\u4e2d\uff0c\u96be\u514d\u4f1a\u51fa\u73b0\u4f9d\u8d56\u51b2\u7a81\uff0c\u51fa\u73b0\u4f9d\u8d56\u51b2\u7a81\u5982\u4f55\u89e3\u51b3\uff1f<\/p> \n

      \u5b9a\u4f4d\u51b2\u7a81<\/strong><\/p> \n

      \u4f9d\u8d56\u51b2\u7a81\u53ef\u80fd\u4f1a\u62a5\u7c7b\u4f3c\u4e0b\u9762\u7684\u9519\u8bef\uff1a<\/p> \n

      Program type already present com.example.MyClass<\/pre> \n  <\/div> \n <\/div> \n 
      \n \u901a\u8fc7\u67e5\u627e\u7c7b\u7684\u65b9\u5f0f\uff08command + O\uff09\u5b9a\u4f4d\u5230\u51b2\u7a81\u7684\u4f9d\u8d56\uff0c\u8fdb\u884c\u6392\u9664\u3002\n <\/div> \n
      \n

      \u5982\u4f55\u6392\u9664\u4f9d\u8d56<\/strong><\/p> \n <\/div> \n

      \n dependencies \u4e2d\u6392\u9664\uff08\u7ec6\u7c92\u5ea6\uff09\n <\/div> \n
      compile('com.taobao.android:accs-huawei:1.1.2@aar') {\r\n        transitive = true\r\n        exclude group: 'com.taobao.android', module: 'accs_sdk_taobao'\r\n}<\/pre> \n 

      \u5168\u5c40\u914d\u7f6e\u6392\u9664<\/p> \n

      configurations {\r\n    compile.exclude module: 'cglib'\r\n    \/\/\u5168\u5c40\u6392\u9664\u539f\u6709\u7684tnet jar\u5305\u4e0eso\u5305\u5206\u79bb\u7684\u914d\u7f6e\uff0c\u7edf\u4e00\u4f7f\u7528aar\u5305\u4e2d\u7684\u5185\u5bb9\r\n    all*.exclude group: 'com.taobao.android', module: 'tnet-jni'\r\n    all*.exclude group: 'com.taobao.android', module: 'tnet-so'\r\n}<\/pre> \n 

      \u7981\u7528\u4f9d\u8d56\u4f20\u9012<\/p> \n

      compile('com.zhyea:ar4j:1.0') {\r\n    transitive = false\r\n}\r\n\r\nconfigurations.all {\r\n    transitive = false\r\n}<\/pre> \n 

      \u8fd8\u53ef\u4ee5\u5728\u5355\u4e2a\u4f9d\u8d56\u9879\u4e2d\u4f7f\u7528 @jar \u6807\u8bc6\u7b26\u5ffd\u7565\u4f20\u9012\u4f9d\u8d56\uff1a<\/p> \n

      compile 'com.zhyea:ar4j:1.0@jar'<\/pre> \n 
      \n \u5f3a\u5236\u4f7f\u7528\u67d0\u4e2a\u7248\u672c\n <\/div> \n

      \u5982\u679c\u67d0\u4e2a\u4f9d\u8d56\u9879\u662f\u5fc5\u9700\u7684\uff0c\u800c\u53c8\u5b58\u5728\u4f9d\u8d56\u51b2\u7a81\u65f6\uff0c\u6b64\u65f6\u6ca1\u5fc5\u8981\u9010\u4e2a\u8fdb\u884c\u6392\u9664\uff0c\u53ef\u4ee5\u4f7f\u7528force\u5c5e\u6027\u6807\u8bc6\u9700\u8981\u8fdb\u884c\u4f9d\u8d56\u7edf\u4e00","orderid":"0","title":"\u4e00\u6587\u641e\u6e05Gradle\u4f9d\u8d56(\u4e00)","smalltitle":"","mid":"0","fname":"JAVA","special_id":"0","bak_id":"0","info":"0","hits":"406","pages":"2","comments":"0","posttime":"2019-01-11 02:08:41","list":"1547143721","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"http:\/\/incdn1.b0.upaiyun.com\/2019\/01\/3726e50d6c3d4557a56b2a905aa47dd9-300x211.jpg","ispic":"1","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u4e00\u6587<\/A> \u641e\u6e05<\/A> Gradle<\/A> \u4f9d\u8d56<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"47.106.78.186","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"\u4e00\u6587\u641e\u6e05Gradle\u4f9d\u8d56","lastview":"1711723159","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}