如何引入第三方jar包(以google play service为例)
来源:互联网 发布:python搭建网站源码 编辑:程序博客网 时间:2024/05/22 12:31
在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')
- 如何引入第三方jar包(以google play service为例)
- 如何引入第三方jar包(以google play service为例)
- 如何引入第三方jar包(以google play service为例)
- 如何引入第三方jar包(以google play service为例
- android开发引入第三方Jar包---achartengine为例
- Android中如何引入第三方jar包
- Android.mk如何引入第三方jar包
- 如何在Android项目中引入第三方JAR包
- Android Studio如何引入第三方jar包
- android开发引入第三方Jar包---achartengine为例 【转】
- Android项目中如何正确的引入第三方jar包(工程)
- android引入第三方jar包步骤
- Android MK 引入第三方jar包
- android studio引入第三方jar包
- 创建jar并引入第三方包
- android studio引入第三方jar包
- eclipse中引入第三方jar包
- AndroidStudio引入第三方jar包操作
- 稀疏表示综述
- 入职第一天的自我学习之.net MVC书籍管理实例参考
- android Notification .
- 常用linux命令
- 2012年5月SAT香港真题解析
- 如何引入第三方jar包(以google play service为例)
- web.xml 中的listener、 filter、servlet 加载顺序及其详解
- table表格某一td内容太多导致样式混乱的解决方案
- WebRTC
- 在64位Ubuntu14.04LTS上编译和链接32位汇编程序(使用c标准库)需要如何配置配置环境
- Geoserver发布地图
- hive修改 表/分区语句
- iOS 输入手机号和验证码的TextField,使获取验证码,提交订单 按钮可用
- android顺序很重要