[Android]Android Studio导入第三方工程库,以PullToRefreshViewLibrary为例

来源:互联网 发布:自定义域名后缀 编辑:程序博客网 时间:2024/04/25 07:17

欢迎光临程序猿零食铺:https://shop66096489.taobao.com
  android studio支持利用gradle导入jar包,包括本地的和远程的,只要在相应module下的build.gradle下按照规则写好jar的位置即可,例如

dependencies {    compile files('libs/Android_Map_V2.5.0.jar')    compile files('libs/AMap_Services_V2.5.0.jar')    compile files('libs/Android_Location_V1.3.2.jar')    compile files('libs/Android_Navi_V1.1.2.jar')    compile files('libs/GetuiExt-2.0.3.jar')    compile files('libs/GetuiSdk2.4.1.0.jar')    compile files('libs/libammsdk.jar')    compile files('libs/Msc.jar')    compile files('libs/Rong_IMKit_v1_4_1.jar')    compile files('libs/swipemenulistview.jar')    compile files('libs/universal-image-loader-1.9.3.jar')    compile files('libs/zxing.jar')    compile project(':library')    compile project(':PullToZoomLibrary')}

  但是如果所要引用的不是简单的一个jar,而是带有资源文件的库工程,则需要稍微配置下,下面以导入PullToRefreshViewLibrary为例,说明如何导入库工程。
1.到github上下载包:
https://github.com/chrisbanes/Android-PullToRefresh
2.利用android studio新建一个工程 TestImportDemo
3.将Android-PullToRefresh 的库工程拷贝到TestImportDemo的根目录下面,以Project方式查看工程目录

工程目录

4.在settings.gradle加入 ‘:PullToRefreshLibrary’
这里写图片描述
5.同步gradle,此时会发现文件夹PullToRefreshLibrary上多了一个咖啡的标记
这里写图片描述
6.在主工程app下面的build.gradle中引入PullToRefreshLibrary

dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    compile 'com.android.support:appcompat-v7:22.2.0'    compile project(':PullToRefreshLibrary')}

7.修改PullToRefreshLibrary的目录结构,必须是以下结构,否则android studio将会报错
src下面是main,main下面有三个字文件(夹),分别是 java,res和AndroidManifest.xml
这里写图片描述
8.验证是否是否导入成功,只要在MainActivity中写入

PullToRefreshListView pullToRefreshListView =new PullToRefreshListView(this);

   不报错就证明导入成功了

0 0
原创粉丝点击