1

I'm quite new with Android development, and I wanted to learn a bit about Lint tool and NewApi check. After doing some tests I'm a bit confused though.

After creating new Android application project in IntelliJ IDEA, I added some code to the onCreate method, so it now looks like this:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Display d = getWindowManager().getDefaultDisplay();
    Point size = new Point();

    d.getSize(size); // API level 13
    isDestroyed(); // API level 17

    NativeActivity nativeActivity = new NativeActivity(); // API level 11
    nativeActivity.getContentResolver(); // API level 11
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); // API level 9
    boolean canDisableShutterSound = cameraInfo.canDisableShutterSound; // API level 17
}

In the manifest file I have

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

After compiling the project and running lint from command line:

lint --check NewApi --classpath c:\_dev\TestNewApi\out c:\_dev\TestNewApi

I got the following output:

Scanning TestNewApi: .......
out\production\TestNewApi\com\example\TestNewApi\MyActivity.class: Error: Call requires API level 9 (current min is 7): android.app.NativeActivity#getContentResolver [NewApi]
out\production\TestNewApi\com\example\TestNewApi\MyActivity.class: Error: Call requires API level 9 (current min is 7): new android.app.NativeActivity [NewApi]
out\production\TestNewApi\com\example\TestNewApi\MyActivity.class: Error: Call requires API level 9 (current min is 7): new android.hardware.Camera.CameraInfo [NewApi]
out\production\TestNewApi\com\example\TestNewApi\MyActivity.class: Error: Field requires API level 9 (current min is 7): android.hardware.Camera.CameraInfo#canDisableShutterSound [NewApi]
4 errors, 0 warnings

So no complaints about getSize and isDestroyed methods. And after changing minSdkVersion to 9, the check result is:

Scanning TestNewApi: .......

No issues found.

It looks for me, like only the classes are checked in both cases, and if the class was introduced at or after minSdkVersion, then everything is ok. Is this the expected behavior? Or maybe I'm missing something?

4

1 回答 1

1

这是预期的行为吗?

恕我直言,不。我在 Eclipse 中看到了相同的行为,恕我直言,这是一个错误。通常,Lint 会抱怨比您的android:minSdkVersion或更新的方法@TargetApi()。我不太确定为什么这里不这样做。

我已经提交了与此相关的问题

于 2013-06-09T13:22:00.470 回答