When lint's own unit tests are running, they're running in the tools source tree, and it points to its own checked in version of the SDK, so the tests are always pointed to a valid and consistent SDK, so the tests are stable. (By the way, the way lint's tests ensure that they're always using this SDK and not picking up individual developer SDKs from $ANDROID_HOME is that these tests basically all extend the same subclass of LintDetectorTest, where they override the lint() call to also call
task.sdkHome(sdk);
to point to an SDK install that is found in a relative directory.
Anyway, that obviously doesn't work when lint unit tests are run for third party lint rules outside the lint distribution. What happens right now is that the test infrastructure looks for lint in a couple of places, the main one being consulting $ANDROID_HOME. Therefore, if you've set $ANDROID_HOME to point to a valid SDK, then the lint unit tests *should* locate the SDK and the android.jar is automatically added to the classpath -- and your tests should be able to refer to android.app.Activity & friends without any compilation/type resolution problems.
Your problem sounds similar to the problem Lin mentioned here the other day where a coworker had problems because they hadn't set $ANDROID_HOME.
I've just added some fixes to the lint test infrastructure (for 2.4 alpha1) which should help with this. (I've only added this to the new test infrastructure, e.g. TestLintTask#lint(), not the older extends LintDetectorTest architecture).
There are two new flags:
* allowMissingSdk: Whether, when lint unit tests are run, the SDK is allowed to be missing. By default, this is false. That means that as of 2.4 if you run a lint unit test and lint can't find an SDK, the test will fail. You can set this to true if for some reason you don't want this behavior but I think this will generally be helpful to default to false: you'll find out if for some reason the SDK isn't there, since otherwise you get strange failures (like the ones Lin mentioned the other day). The test failure also lists how you can go about configuring the SDK. One way is to set $ANDROID_HOME. But that isn't great since it can vary from developer to developer (unless the issue is on a build server where you can set up the environment exactly as you want). Another way is to call TestLintTask#sdkHome(File), as is done by our internal lint unit tests, so you can point to a specific SDK that you want to use for the tests.
* requireCompileSdk: Normally, lint tries to use the SDK that the test's compileSdkVersion asks for, but if it can't find that, it just uses the latest available SDK instead. If you set this flag to true, it will check and make sure that that specific SDK is available, and if not, it will fail the test. This lets you write a test that will fail if it's not using the exact, intended SDK version to compile your test.
Example usages:
lint()
.files(....).
.requireCompileSdk(true)
.run()
.expectClean();