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:
...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 lint
tool does some of these checks (thanks @CommonsWare in the comments above):
$ which lint
/android-sdk-macosx/tools/lint
$ lint myProjectDir --check NewApi
Scanning .: .....
No issues found.
It appears you can also run this as ant lint
as 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 by javac
:
java.compilerargs=-Xlint:all
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:
$ lint --show NewApi
NewApi
------
Summary: Finds API accesses to APIs that are not supported in all targeted API
versions
Priority: 6 / 10
Severity: Error
Category: Correctness
This check scans through all the Android API calls in the application and
warns about any calls that are not available on all versions targeted by this
application (according to its minimum SDK attribute in the manifest).
If you really want to use this API and don't need to support older devices
just set the minSdkVersion in your AndroidManifest.xml file.
If your code is deliberately accessing newer APIs, and you have ensured (e.g.
with conditional execution) that this code will only ever be called on a
supported platform, then you can annotate your class or method with the
@TargetApi annotation specifying the local minimum SDK to apply, such as
@TargetApi(11), such that this check considers 11 rather than your manifest
file's minimum SDK as the required API level.
And here are some helpful links regarding lint
:
easiest solution I found was to add this line to the Application.mk file
override APP_MIN_PLATFORM_LEVEL=99
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With