如何引入第三方jar包(以google play service为例

如何引入第三方jar包(以google play service为例) 用户评价:  / 1
好 

原文地址:http://forum.xda-developers.com/showthread.php?t=2421186

翻译:Android Studio 中文组(大锤译) 

在Android Studio(AS)的开发中,遇到引入外部类库或第三方jar包的情况,确实是件很恼人的事情。因为AS是基于Gradle构建,所以和传统的导入方式有些不一样。

笔者也曾为此头疼过好一阵,现在终于有了解决办法,拿出来和大家分享一下。

这里以导入Google Services library为例,具体操作步骤如下。

1. 打开你的buid.gradle文件。应该用哪一个呢?Project中的,还是Module中的?(如图所示,Module中的)

2 . 将google-play-services.jar这个jar包拷到指定的位置。原来可能是在这个目录下:$ANDROID-SDK/extras/google/google_play_services/libproject/google-play-services_lib/libs ,比如现在我把它放到了$GOOGLE_PLAY_LIB目录下。

 

3 . 如果你已经有了别的dependencies(如Android Studio Library),我们把它加到list当中去,也就是将你需要编译的部分,从dependencies中移到list里。

例如先前长这样:

List myDependencies = ["com.android.support:appcompat-v7:18.0.+"]
dependencies {
        //moved into List above, so there'll be nothing here.

 

4.  加入Google Play Library之后:

List myDependencies = ["com.android.support:appcompat-v7:18.0.+", 
fileTree (dir: '$GOOGLE_PLAY_LIB', includes: ['*.jar'])]

 

PS:不要忘了把$GOOGLE_PLAY_LIB 改成你本地的目录,如 E://Android/Development/Lib 

 

5.  修改dependencies里面的内容:

List myDependencies = ["com.android.support:appcompat-v7:18.0.+", 
fileTree (dir: 'E://Android/Development/Lib', includes: ['*.jar'])]
dependencies {
    compile myDependencies
} 

 

6.  然后就是耐心等待项目compile和make了。^_^

笔者成功的测试过Google Android Map v2,如果你有遇到问题,欢迎留言。 

 

=======以下是另一个网友留言,有更简便一些,不过得注意路径的问题========

只需要从SDK中下载 Google Repository & Google Play Services,然后在build.gradle文件中申明,如下所示:

dependencies {
compile('com.android.support:appcompat-v7:18.0.+')
compile('com.android.support:support-v4:13.0.0')
compile ('com.google.android.gms:play-services:3.2.25')
}

 

再或者,直接:compile files('libs/google-play-services.jar')

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值