I’m working on an android app, and worried that we have introduced code that uses functionality from API levels later than its minSdkVersion.
I’d like to know if there’s any way to detect some of these violations automatically.
In this app’s AndroidManifest.xml file, it specifies:
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="17" />
ndk-build is seems to be giving me a warning about this (or is this warning for another reason?):
Android NDK: Found stable platform levels: 14 3 4 5 8 9
Android NDK: Found max platform level: 14
Android NDK: Parsing ./jni/Application.mk
Android NDK: Found APP_PLATFORM=android-17 in ./project.properties
Android NDK: Adjusting APP_PLATFORM android-17 to android-14 and enabling -fPIE
/android-ndk/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml
While I realize any tool cannot be 100% accurate due to runtime dispatch, other than:
- a full audit of the source code, or
- a complete testing of all code paths on a device running minSdkVersion (in this case android-8 = 2.2 = Froyo)
…is there a lint-like tool, a build setting change, or anything else I can use to identify at least the most obvious/blatant violations?
If no such thing exists, is there a comprehensive API list or something that will make an audit easier?
It looks like the android
linttool does some of these checks (thanks @CommonsWare in the comments above):It appears you can also run this as
ant lintas of SDK Tools Revision 21.Lint has various nice output formats, it seems! Integration with Jenkins via
--xml, etc…In addition, in
ant.properties, you can set something like this to have some lint-like checks performed byjavac:It’s unclear whether javac reports incidents like lint –check NewApi does, but it does report
[deprecation]entries at least. (If you find a reference for what javac reports, please post a comment.)For posterity, here’s the description of lint’s NewApi checker:
And here are some helpful links regarding
lint: