2013-07-23

簡易版Android Studio導入外部library流程

以下用gson-2.2.4.jar測試:

(1) 複製.jar到要導入的Module目錄下,Android Studio會自動抓到對應檔案:


(2) 在Android Studio的Project視窗中,右鍵點.jar,選add as library

(3) 隨便要取甚麼名字,不贅述,然後開啟Module內的build.gradle,在dependencies中加入這段(.jar的檔名可以從左邊copy...):
compile files('/libs/gson-2.2.4.jar')

[  至此已經可以正常使用,以下為選用流程,自行參考  ]

(4) 對整個專案做一次cleanup的build (是在Project的目錄下,非Module)


(5) 如果多個檔案要加入,有些比較快的輸入格式,對整個樹枝狀目錄或複數檔案
compile fileTree(dir: 'libs', include: '*.jar')
compile files('libs/001.jar', 'libs/002.jar')

(6) 有個建議是說可以透過mavenCentral()網路下載進行compile,取代掉compile files那段,改成:
compile 'com.google.code.gson:gson:2.2.4'
目前透過(6) compile正常使用中

沒有留言:

張貼留言