6

私は Android アプリに取り組んでおり、API レベル以降の機能を使用するコードを導入したのではないかと心配していますminSdkVersion

これらの違反の一部を自動的に検出する方法があるかどうか知りたいです。

このアプリの AndroidManifest.xmlファイルでは、次のように指定されています。

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

ndk-build は、これに関する警告を表示しているようです (または、別の理由でこの警告が表示されますか?):

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    

ランタイム ディスパッチのために、どのツールも 100% 正確ではないことは承知していますが、次の場合を除きます。

  • ソースコードの完全な監査、または
  • minSdkVersion を実行しているデバイス上のすべてのコード パスの完全なテスト (この場合は android-8 = 2.2 = Froyo)

...リントのようなツール、ビルド設定の変更、または少なくとも最も明白な/露骨な違反を特定するために使用できるものはありますか?

そのようなものが存在しない場合、監査を容易にする包括的な API リストまたは何かがありますか?

4

2 に答える 2

4

Androidlintツールがこれらのチェックのいくつかを行うようです(上記のコメントの@CommonsWareに感謝します):

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

$ lint myProjectDir --check NewApi

Scanning .: .....

No issues found.

ant lintSDK ツール リビジョン 21 の時点で、これを実行することもできるようです。

Lint にはさまざまな優れた出力形式があるようです。などを介したジェンキンスとの統合--xml...


さらに、 ではant.properties、次のように設定して、 によって実行される lint のようなチェックを行うことができますjavac

java.compilerargs=-Xlint:all

javac が lint --check NewApi のようにインシデントを報告するかどうかは不明ですが、[deprecation]少なくともエントリは報告します。( javac が報告する内容のリファレンスを見つけた場合は、コメントを投稿してください。)


後世のために、lint の NewApi チェッカーの説明を次に示します。

$ 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.

そして、ここに関連するいくつかの役立つリンクがありますlint:

于 2013-02-11T18:11:02.870 に答える