16 April 2011

Android Sources in Eclipse

I've blogged about getting Eclipse to show Android sources before, but these techniques no longer work. So I'll toss a working how-to out there again.


I'm still baffled that Google hasn't ensured this working from day #1 with this eclipse plugin. But enough crying :)


I should also mention there is an eclipse plugin made for this. I've never tried it. I don't like bloating eclipse with tons of plugins, unless I really have to. And this boils down to 8 pretty easy steps, so an eclipse plugin isn't something Id'e consider. (But I may change my mind later)

Download the sources from github, and attach them:
  • Click the Snapshot link which just appeared by the Tree -link

You'll start downloading a file which is about 130mb. This is the android source file. It's filename starts with base, for me it's called base-08d9d9a.tar.gz
  • move the base -file to the SDK platform directory, for me that's /opt/android-sdk-linux_x86/platforms/android-8
  • unpack it (tar xvfz base-08d9d9a.tar.gz).
  • head into eclipse, and press F3 over some android source you're missing, like Activity. And get this pesky window, which we all hate:

  • Click Attach Source, choose External Folder, and choose the core/java in the base folder. For me that's /opt/android-sdk-linux_x86/platforms/android-8/base-08d9d9a/core/java
There you go. Please post a comment and tell me how this turns out for you :)


.finn


(*1) There are loads of versions there, and it's a bit confusing. I've concluded the stuff we're looking for should end with SDK. However I'm not 100% certain about what version to download to match the Android version we see in the Android SDK download tool - this is just me guessing.

14 April 2011

Getting that Skeleton test up

When creating a new unit test file, getting the import statics right with Hamcrest is 30 seconds of hassle, every time.

Here is the typical unit test start-up I prefer:
@Test
public void skeletonTest() {
assertThat(true, is(equalTo(true)));
}
Here is a eclipse template, which may solve this. But may also not, as I tend to forget little tricks like these. Time will tell if I've been able to incorporate this my reflexes.

So, get the template in, make the new junit test file, type skeltest and press ctrl+space.
























The template:
${imp:import(org.junit.Test)}
${imps:importStatic(
org.hamcrest.Matchers.equalTo,
org.hamcrest.Matchers.is,
org.junit.Assert.assertThat)}
@Test
public void skeletonTest() {
assertThat(true, is(equalTo(true)));
}