Android Studio 简介及导入 jar 包和第三方开源库方法

Android Studio 简介

几天前的晚上突然又想使用 Android Studio,结果竟然把之前无法攻克的问题全都解决了,包括之前很困扰的第三方开源库的引入问题,现在也都很轻松了,所以 eclipse 的工作几乎都可以转移过去。并且试用了一晚上,比 eclipse 强大多了!看来,eclipse For Java & Android 的地位毫无疑问终将被 IntelliJ IDEA 所取代,而 Android Studio 也正是基于 IntelliJ IDEA 开发的,并且我的驱动力主要是,开源社区都越来越偏向 Android Studio 了,不管是第三方库还是一些开源项目,都在朝着这个方向,因此做安卓的话,肯定要尽早使用 AS。

之前和龙妹在 Android Studio 0.4 版本折腾了一晚上,都没能完全搞定完整的项目转移,其中最大的障碍就是一些开源库难以导入使用。这一次谷歌更新了新版 0.8 版本,不仅支持最新的 Android L,而且懂得了 gradle 之后导入 jar 包以及开源库也变得简单了。

导入 jar 包及第三方开源库教程

jar

导入 jar 包的方式非常简单,就是在项目中的 libs 中放入你需要导入的 jar 包,QQ截图20140710123408然后右键你的 jar 文件,选择“add as a library”即可在你的项目中使用这个 jar 包了。 这个方式虽然简单,但用处很大,不仅仅能导入一些普通 jar 包,还可以作为一些不支持 Android Studio 的开源库的使用的解决方案,就是说,你把你需要使用的开源库的 jar 包拿出来,导进来即可,因为通常我们使用开源库并不会去修改其源代码。其 jar 包你可以自己用 eclipse 生成,也可以在开源库地址找到,因为一般都会同时提供 release 版本。

但如果 gradle 中已经有如下代码:

compile fileTree(include: ['*.jar'], dir: 'libs')

就不用再 add 了,Sync 一下 gradle 就可以了。

添加远程开源库

可以无需将开源库下载下来,进入你的项目(一般是 app 目录),编辑 build.gradle 文件。添加如下图的内容即可:

QQ截图20140710124614

该内容你可以在你使用的开源库的 README.md 中获得,如我使用的 FlatUI 这个开源库,在其 GitHub 页面上你可得以下内容:

QQ截图20140710124843

这个帮助内容就是你写到项目 build.gradle 中的内容,注意,不要误写到外层的全局 build.gradle 中去。 总的来说,就是这么两步,其余都不用做,就可以在你的项目中使用这个开源库了。现在的开源库 README.md 中,如果作者使用的是 Android Studio 都会写上这么一个指引的。

添加本地开源库

将开源库下载下来,放置在与 app 目录同级的目录下,然后编辑 setting.gradle 文件,加入:”:开源库文件夹名”。如:我在 app 同级的目录下放置了 volley 的开源库文件夹,然后编辑  setting.gradle,内容改为:

include ':app', ':volley'

然后再回到你的 app 目录下的 build.gradle 文件,在 dependencies { }节点下加入:

compile project(':volley')

这样以后,你就可以在你的代码中引用那个保存在你本地的开源库(其实叫 Module )啦~~

  1. 博主。请教个问题。如果有一个library的项目A,它引入了其它包,比如OkHttp3, 然后怎样才能在引入A的时候自动的引入OkHttp3,举个例子:我在项目中引入Retrofit2,然后Retrofit会自动引入OkHttp3

  2. Pingback: where to buy social signals

  3. 你好,app中无法调用module中的jar包类,请问知道为什么吗。哪位大神了解的也请告知一下,谢谢

  4. 博主,sdk23中已经删除了HttpClient这个类,直接把volley源码拷贝出来粘贴到项目里已经回报错了,但是通过compile ‘com.mcxiaoke.volley:library:1.0.19’把volley引入项目是可以正常使用的,您知道这是什么原因么?

  5. Pingback: what is new

  6. Pingback: what is new

  7. Pingback: read more

  8. Pingback: read more

  9. Pingback: read more

  10. Pingback: read more

  11. Pingback: click here

  12. Pingback: click here

  13. Pingback: click here

  14. Pingback: click here

  15. Pingback: have a peek at these guys

  16. Pingback: have a peek at these guys

  17. Pingback: news

  18. Pingback: navigate to this website

  19. Pingback: this page

  20. Pingback: my response

  21. Pingback: original site

  22. Pingback: check here

  23. Pingback: browse this site

  24. Pingback: click here now

  25. Pingback: read this article

  26. Pingback: Bonuses

  27. Pingback: find this

  28. Pingback: a fantastic read

  29. Pingback: Homepage

  30. Pingback: how to get bigger boobs in a week

  31. Pingback: see it here

  32. Pingback: find more info

  33. Pingback: click to read more

  34. Pingback: imp source

  35. Pingback: my company

  36. Pingback: great post to read

  37. Pingback: this website

  38. Pingback: how to get bigger boobs without surgery

  39. Pingback: how to get bigger boobs naturally

  40. Pingback: see here

  41. Pingback: Get More Info

  42. Pingback: useful reference

  43. Pingback: get redirected here

  44. Pingback: my review here

  45. Pingback: click site

  46. Pingback: More about the author

  47. Pingback: check my blog

  48. Pingback: read more

  49. Pingback: sperrys gift cards

  50. Pingback: mitogen

  51. Pingback: discover this info here

  52. Pingback: explanation

  53. Pingback: try this web-site

  54. Pingback: official statement

  55. Pingback: you could look here

  56. Pingback: Get the facts

  57. Pingback: More hints

  58. Pingback: why not try these out

  59. Pingback: i thought about this

  60. Pingback: my response

  61. Pingback: browse this site

  62. Pingback: find this

  63. Pingback: Homepage

  64. Pingback: i thought about this

  65. Pingback: useful reference

  66. Pingback: More about the author

  67. Pingback: quality article

  68. Pingback: quality article

  69. Pingback: insight

  70. Pingback: where to look

  71. Pingback: what to do

  72. Pingback: continue reading

  73. Pingback: figure out

  74. Pingback: find

  75. Pingback: important

  76. Pingback: read more

  77. Pingback: click here

  78. Pingback: Give Her Makeup.com

  79. Pingback: learn now

  80. Pingback: best news

  81. Pingback: best value

  82. Pingback: More hints

  83. Pingback: Clicking Here

  84. Pingback: her latest blog

  85. Pingback: official site

  86. Pingback: check this link right here now

  87. Pingback: more news

  88. Pingback: read more

  89. Pingback: click here

  90. Pingback: website

  91. Pingback: read more

  92. Pingback: read more

  93. Pingback: read more

  94. Pingback: click here

  95. Pingback: click here

  96. Pingback: click here

  97. Pingback: important source

  98. Pingback: official statement

  99. Pingback: Get the facts

  100. Pingback: Learn More

  101. Pingback: you could try here

  102. Pingback: you could check here

  103. Pingback: check that

  104. Pingback: More Bonuses

  105. Pingback: her latest blog

  106. Pingback: Visit Website

  107. Pingback: their explanation

  108. Pingback: why not find out more

  109. Pingback: view publisher site

  110. Pingback: i thought about this

  111. Pingback: my response

  112. Pingback: a fantastic read

  113. Pingback: imp source

  114. Pingback: useful reference

  115. Pingback: about

  116. Pingback: how to

  117. Pingback: news

  118. Pingback: new website

  119. Pingback: best info

  120. Pingback: read more

  121. Pingback: look here

  122. Pingback: see post

  123. Pingback: content

  124. Pingback: pop over to this website

  125. Pingback: click resources

  126. Pingback: Discover More

  127. Pingback: Continued

  128. Pingback: More Bonuses

  129. Pingback: hop over to this website

  130. Pingback: additional hints

  131. Pingback: navigate to these guys

  132. Pingback: you can try this out

  133. Pingback: check these guys out

  134. Pingback: look at this site

  135. Pingback: why not try these out

  136. Pingback: original site

  137. Pingback: a fantastic read

  138. Pingback: my company

  139. Pingback: useful reference

  140. Pingback: new website

  141. Pingback: read more

  142. Pingback: click here

  143. Pingback: must see

  144. Pingback: interserver promo code

  145. Pingback: interserver coupon

  146. Pingback: hotels

  147. Pingback: water slide

  148. Pingback: hotels burlington

  149. Pingback: pickleball

  150. Pingback: Double glazing window

  151. Pingback: 403b plan

  152. Pingback: garcinia cambogia extract does it work

  153. Pingback: Skydiving NYC

  154. Pingback: android studio 导入jar包及依莱酷 | 安卓文档网

  155. Pingback: android studio 导入jar包及依莱酷-IT大道

  156. 博主,导入其他人的android studio总是出现support库找不到,这是什么情况

  157. Pingback: Android Tips – 填坑手册 – Android开发中文站

    • 把library这个文件夹复制到和app文件夹同级目录下,然后在app文件夹中的build.gradle中添加依赖。

  158. 楼主,我刚接触as,想问下我已经下载了好了android support repository 15,里面有design。为什么我导入时却找不到,其他v4,v7之类的都能找到

  159. 关于“添加远程开源库”,只写那句就行了???不需要把github上的项目git clone下来,编译成aar吗?

  160. 添加本地开源库,在compile project(‘:volley’)之后应该还需要修改你导入的开源库目录下的build.gradle文件吧?因为你本地的设置和导入的开源库中的build.gradle中的设置可能会因为SDK、build-tools不同无法使用,另外include ‘:app’, “:volley”,volley应该使用单引号吧?

  161. 这几天弄这个把我弄崩溃了,今天终于找了个靠谱的答案了!

  162. 我用你的本地开源库导入方法gradle报错说找不到 not found property “VERSION_NAME” on project ‘:library’

  163. 求个jar包给eclipse用…我这项目组完全无视我多次提出换用studio开发环境的呼吁,还是坚持要我们用eclipse,搞得现在好多好用的开源控件没得用,希望楼主能提供个jar包,谢谢…我现在是直接把代码复制到项目里面去用了,版权什么的都留着,再次谢谢楼主…