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

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

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

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

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

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

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

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

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

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

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

  11. Pingback: Skydiving NYC

  12. Pingback: garcinia cambogia extract does it work

  13. Pingback: 403b plan

  14. Pingback: Double glazing window

  15. Pingback: pickleball

  16. Pingback: hotels burlington

  17. Pingback: water slide

  18. Pingback: hotels

  19. Pingback: interserver coupon

  20. Pingback: interserver promo code

  21. Pingback: must see

  22. Pingback: click here

  23. Pingback: read more

  24. Pingback: new website

  25. Pingback: useful reference

  26. Pingback: my company

  27. Pingback: a fantastic read

  28. Pingback: original site

  29. Pingback: why not try these out

  30. Pingback: look at this site

  31. Pingback: check these guys out

  32. Pingback: you can try this out

  33. Pingback: navigate to these guys

  34. Pingback: additional hints

  35. Pingback: hop over to this website

  36. Pingback: More Bonuses

  37. Pingback: Continued

  38. Pingback: Discover More

  39. Pingback: click resources

  40. Pingback: pop over to this website

  41. Pingback: content

  42. Pingback: see post

  43. Pingback: look here

  44. Pingback: read more

  45. Pingback: best info

  46. Pingback: new website

  47. Pingback: news

  48. Pingback: how to

  49. Pingback: about

  50. Pingback: useful reference

  51. Pingback: imp source

  52. Pingback: a fantastic read

  53. Pingback: my response

  54. Pingback: i thought about this

  55. Pingback: view publisher site

  56. Pingback: why not find out more

  57. Pingback: their explanation

  58. Pingback: Visit Website

  59. Pingback: her latest blog

  60. Pingback: More Bonuses

  61. Pingback: check that

  62. Pingback: you could check here

  63. Pingback: you could try here

  64. Pingback: Learn More

  65. Pingback: Get the facts

  66. Pingback: official statement

  67. Pingback: important source

  68. Pingback: click here

  69. Pingback: click here

  70. Pingback: click here

  71. Pingback: read more

  72. Pingback: read more

  73. Pingback: read more

  74. Pingback: website

  75. Pingback: click here

  76. Pingback: read more

  77. Pingback: more news

  78. Pingback: check this link right here now

  79. Pingback: official site

  80. Pingback: her latest blog

  81. Pingback: Clicking Here

  82. Pingback: More hints

  83. Pingback: best value

  84. Pingback: best news

  85. Pingback: learn now

  86. Pingback: Give Her Makeup.com

  87. Pingback: click here

  88. Pingback: read more

  89. Pingback: important

  90. Pingback: find

  91. Pingback: figure out

  92. Pingback: continue reading

  93. Pingback: what to do

  94. Pingback: where to look

  95. Pingback: insight

  96. Pingback: quality article

  97. Pingback: quality article

  98. Pingback: More about the author

  99. Pingback: useful reference

  100. Pingback: i thought about this

  101. Pingback: Homepage

  102. Pingback: find this

  103. Pingback: browse this site

  104. Pingback: my response

  105. Pingback: i thought about this

  106. Pingback: why not try these out

  107. Pingback: More hints

  108. Pingback: Get the facts

  109. Pingback: you could look here

  110. Pingback: official statement

  111. Pingback: try this web-site

  112. Pingback: explanation

  113. Pingback: discover this info here

  114. Pingback: mitogen

  115. Pingback: sperrys gift cards

  116. Pingback: read more

  117. Pingback: check my blog

  118. Pingback: More about the author

  119. Pingback: click site

  120. Pingback: my review here

  121. Pingback: get redirected here

  122. Pingback: useful reference

  123. Pingback: Get More Info

  124. Pingback: see here

  125. Pingback: how to get bigger boobs naturally

  126. Pingback: how to get bigger boobs without surgery

  127. Pingback: this website

  128. Pingback: great post to read

  129. Pingback: my company

  130. Pingback: imp source

  131. Pingback: click to read more

  132. Pingback: find more info

  133. Pingback: see it here

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

  135. Pingback: Homepage

  136. Pingback: a fantastic read

  137. Pingback: find this

  138. Pingback: Bonuses

  139. Pingback: read this article

  140. Pingback: click here now

  141. Pingback: browse this site

  142. Pingback: check here

  143. Pingback: original site

  144. Pingback: my response

  145. Pingback: this page

  146. Pingback: navigate to this website

  147. Pingback: news

  148. Pingback: have a peek at these guys

  149. Pingback: have a peek at these guys

  150. Pingback: click here

  151. Pingback: click here

  152. Pingback: click here

  153. Pingback: click here

  154. Pingback: read more

  155. Pingback: read more

  156. Pingback: read more

  157. Pingback: read more

  158. Pingback: what is new

  159. Pingback: what is new

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

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