如何在Android代码中强制检查不兼容的API使用情况? [英] How to force checking for incompatible API usage in Android code?

查看:181
本文介绍了如何在Android代码中强制检查不兼容的API使用情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将minSdk设置为7,将targetSdk设置为17。

I have set minSdk to 7 and targetSdk to 17.

我通过手动检查是否崩溃来发现问题。 (是的,这是废话)

I find the problems by manually checking if something crashes. (Yes this is nonsense)

我也尝试将targetSdk设置为7。但这也无济于事。我想我错过了一个仍然认为目标是17的设置。

I tried setting targetSdk to 7 too. But that doesn't help either. I think I am missing a setting which still thinks that the target is 17.

如何确定我没有使用任何不兼容的代码?我至少需要警告。当然,我会检查构建版本是否可以动态调用更高级别的API,但我想确保已包含所有可能导致应用程序在较低版本的Android上崩溃的代码。

How can I be sure that I am not using any incompatible code? I at least need warnings. For sure I check for build version to dynamically call higher level APIs or not, but I want to be sure that I have surrounded any possible code that may make the app crash on lower versions of Android.

推荐答案


如何确定我没有使用任何不兼容的代码?

How can I be sure that I am not using any incompatible code?

假设您使用的是较新版本的Android工具(例如,过去一年中使用过),Lint会指出对您来说,您正在使用的任何东西都比您的 android:minSdkVersion 更新,但被构建目标允许。

Assuming that you are using a reasonably recent version of the Android tools (e.g., something in the past year), Lint will point out to you anything that you are using that is newer than your android:minSdkVersion but is allowed by your build target.

如果您使用的是Eclipse,则在保存源文件时会自动发生这种情况,或者可以通过在Package Explorer中右键单击项目,然后选择Android工具> Run Lint:检查常见错误来在项目上手动运行Lint。

If you are using Eclipse, this should happen automatically when you save source files, or you can manually run Lint on your project by right-clicking over the project in Package Explorer, then choosing Android Tools > Run Lint: Check for Common Errors.

这篇关于如何在Android代码中强制检查不兼容的API使用情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆