Android violation check: minSdkVersion automatically

I am working on an Android application and fear that we have implemented code that uses functionality from API levels later than it minSdkVersion.

I would like to know if there is a way to detect some of these violations automatically.

In this application, the AndroidManifest.xmlfile indicates:

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

ndk-build seems to give me a warning about this (or is this a 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    

So far I understand that any tool cannot be 100% accurate due to the sending of the runtime, except:

  • full audit of the source code or
  • full testing of all code paths on a device using minSdkVersion (in this case, android-8 = 2.2 = Froyo)

... , - , , , / ?

, API -, ?

+5
2

, android lint ( @CommonsWare ):

$ which lint
/android-sdk-macosx/tools/lint

$ lint myProjectDir --check NewApi

Scanning .: .....

No issues found.

, ant lint SDK Tools Revision 21.

Lint , ! Jenkins --xml ..


, ant.properties - , - lint- , javac:

java.compilerargs=-Xlint:all

, javac , lint --check NewApi, [deprecation] . ( javac, .)


lint 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 minimum SDK as the required API level.

lint:

+4

, , Application.mk

APP_MIN_PLATFORM_LEVEL = 99

+2

All Articles