Android Studio导入github上的项目or框架

举个栗子什么的说明最清楚了


第一步

在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里插入这么一段,然后执行

[java]  view plain copy
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"  
  3.     android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"  
  4.     android:paddingRight="@dimen/activity_horizontal_margin"  
  5.     android:paddingTop="@dimen/activity_vertical_margin"  
  6.     android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">  
  7.   
  8.     <TextView android:text="@string/hello_world" android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content" />  
  10.     <com.yalantis.pulltorefresh.library.PullToRefreshView  
  11.         android:id="@+id/pull_to_refresh"  
  12.         android:layout_width="match_parent"  
  13.         android:layout_height="match_parent">  
  14.   
  15.         <ListView  
  16.             android:id="@+id/list_view"  
  17.             android:divider="@null"  
  18.             android:dividerHeight="0dp"  
  19.             android:layout_width="match_parent"  
  20.             android:layout_height="match_parent" />  
  21.   
  22.     </com.yalantis.pulltorefresh.library.PullToRefreshView>  
  23. </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包拷进去就行了

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值