Android: Attaching Sources to Libraries in Eclipse

Since ADT r17, Android projects in Eclipse have had a nice property: all jars in your libs directory have been automatically picked up by Eclipse projects under a magic “Android Dependencies” entry in the build path. Ant builds use the same conventions, so adding a library is as simple as dropping it into the right directory. Unfortunately, though, this magic came with a major limitation: there was no way to attach sources to these libraries (see issue 27940). This led me to duplicate build path entries manually just to get source attachments.

Good news: in the just-released r20 version of ADT, Google have provided a solution to this problem. It’s not well advertised, but if you check out comment 21 on the aforementioned issue, you see that by creating a properties file for each library, you can tell ADT where to find the sources. So, for example, if you have a jar named:

some-library-1.0.jar

you can create a properties file alongside it named:

some-library-1.0.jar.properties

Within the properties file you can add a src property set to the relative (or absolute, but that’s version-control-unfriendly) path of the source jar, zip or directory. Say, like me, you put it in the libs/src subdirectory, your properties file might look like:

src=src/some-library-1.0-sources.jar

Once you’ve added the properties file, refresh the project in Eclipse and voilà: the sources will be attached! A similar property named doc is supported for javadoc attachments.

Although this new feature is very welcome, I feel like it could use a bit more fine tuning. The main issue is the need to create a separate properties file for each jar. I keep my source jars in predictable locations, with conventional names, so I should be able to configure the convention once and have everything Just Work from then on. Heck, I’m not sure why there isn’t a default convention, which I could just follow with no further configuration!

===============================================

注:

上文所说的路径有错,properties文件必须放在libs目录下才能生效,而不能放在libs/src目录下

更多相关文章

  1. 修改android virtual device路径
  2. Android调用系统自带的文件管理器进行文件选择并获得路径,android
  3. Android Studio中配置代码和资源的路径
  4. Android Studio apk生成路径
  5. Android拷贝图片到指定文件路径
  6. 修改Android Media Scanner的扫描路径
  7. Android修改Eclipse 中的Default debug keystore路径,以及修改and
  8. 直播源码Android实现 曲线路径动画
  9. android中获取当前程序路径

随机推荐

  1. android LinearLayout布局子空间没有填充
  2. android SDK与ADT版本更新问题
  3. android String
  4. android 获取控件真实高度
  5. Android使用XPush配置极光推送
  6. android启动画面
  7. Android预定义样式
  8. 1.8 Android(安卓)SQLite数据库
  9. [置顶] Android(安卓)View系统学习文章汇
  10. Android(安卓)build system