举个栗子什么的说明最清楚了
第一步
在github上下载项目,就是那个压缩包啦,这里先随便下两个
https://github.com/Yalantis/Pull-to-Refresh.Rentals-Android
https://github.com/daimajia/AndroidSwipeLayout
我下载在桌面上
第二步
新建个工程
目前结构是这个样子滴
右击app,选择open module settings
这里说下module是神马东东
其实就是androidstudio和eclipse命名不同
eclipse的结构是workspace->Project对吧
AndroidStudio就是Project->Module
module就是对应eclipse的Project
而Project比如这里我们新建的ImportTest对应原来的workspace
get it?
而这个app是自动生成的
跳出这么个东西,点左上角的绿色+号
点击import exiting project
这里打开在github上下的那个压缩包,解压出来的文件夹,会识别到里面的模块,这里有两个,library和sample,library就是那个我们需要使用的框架,而sample是这个框架开发者做的基于这个框架的demo,所以看下面如果勾选了sample,library是必须勾选的,当然我们这里sample是没用的,不勾选,然后finish,就导入啦
然后结构就变成这样了,多了个library
看见build.gradle(app)了吗,打开,添加compile 'com.yalantis:pulltorefresh:1.0.0'
好啦,这个就算导入拉,library里面的代码我们就可以使用了
实现下咯
main_layout里插入这么一段,然后执行
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
- android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
- <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- <com.yalantis.pulltorefresh.library.PullToRefreshView
- android:id="@+id/pull_to_refresh"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ListView
- android:id="@+id/list_view"
- android:divider="@null"
- android:dividerHeight="0dp"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- </com.yalantis.pulltorefresh.library.PullToRefreshView>
- </RelativeLayout>
搞定啦
这个项目很简单啦
我刚才有下载两个项目,现在把另一个也导入
导入的library命名叫library2好了,因为不能冲突
艹艹艹艹艹,报错鸟
Error:(4, 0) Could not find property 'ANDROID_BUILD_SDK_VERSION' on project ':library2'.
没定义这个东东
好吧,那就定义吧
看到gradle.properties了吧,打开,添加
ANDROID_BUILD_MIN_SDK_VERSION=14
ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION=21.1.2
ANDROID_BUILD_SDK_VERSION=21
(对应自己的版本啦,改下版本号)
右上角try again点击
还有错
Error:No such property: GROUP for class: org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer
在library2的build.gradle里有这么一行,apply from: './gradle-mvn-push.gradle',注释掉
然后try again在构建下,搞定,这次是真的!
好啦,两个项目导进来啦,可以用人家的代码了
那如果是想要导入jar包呢?
app下有个libs文件夹,把jar包拷进去就行了