Goffredo
Goffredo

Reputation: 541

How to search for incompatible Android API usage in my app

Let's say I have set up my Android application's AndroidManifest.xml as follows:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>

I am interested in how I can scan my source code for invocations of Android APIs that are not part of the minimimun SDK version I have specified, which in this example is API Level 8. That way, I can inspect each questionable invocation to ensure that it is properly wrapped with a reflection test, or some other assurance of backwards compatibility, so that it won't crash older devices. Ideally, I could then mark off this invocation as 'safe' so that it doesn't trigger on subsequent scans.

For example, let's say a developer unknowingly checks in some code that uses DownloadManager, an API that is available in API levels 9 and higher. Because of my 'uses-sdk' statement above, MyApp will build, install, and run on an Android 2.2 (API Level 8) device. But once the code path invokes the DownloadManager method on that 2.2 device, the user will experience an unresolved virtual method exception (crash). This is what I'm trying to avoid.

Ideally scanning for these potentially-incompatible APIs would be something I can do from the command line, during building; and, it would be able to handle changes to android:minSdkVersion without too much retooling.

Upvotes: 2

Views: 206

Answers (1)

user1834095
user1834095

Reputation: 5713

I had a hard time myself to find this so I'll answer is clearly (even though this is a 2 year old question).

In Eclipse, right click on the project, click "Android tools" > "Run lint: check for common error".

This will give you a list of all oddities lint can find in your code, including incompatibilities to the minSdkVersion you defined in your manifest (can be found in the list with the category "Correctness").

Upvotes: 1

Related Questions