天天看點

Android build.gradle 中的 implementation api compile聲明

目錄

  • 聲明
    • 快速使用

聲明

如果你隻是為了快速了解該内容功能和使用方式投入運用快速上手那麼請看此處

快速使用

implementation:

假設有一個module為locationsdk,locationsdk中依賴了 gson

implementation 'com.google.code.gson:gson:2.8.2'
           

這樣,locationsdk中是可以引用(使用)到gson裡的代碼的

現在,我們的另一個module—>app依賴于locationsdk

implementation project(':locationsdk')
           

因為locationsdk使用的是implementation 指令依賴gson

是以app中是不能通路到gson的

但是如果locationsdk中是使用 api 來依賴的話

api 'com.google.code.gson:gson:2.8.2'
           

則與gradle3.0.0之前的 compile 指令的效果完全一樣,app的module也可以引用gson

上面這就是這三者的差別,喜歡的小夥伴動動手指 點贊的最帥(美)