How to force checking for incompatible API usage in Android code?

不羁的心 提交于 2019-12-13 05:23:33

问题


I have set minSdk to 7 and targetSdk to 17.

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

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.

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.


回答1:


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

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.

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.




回答2:


you check by doing something like this

if(Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1){

}else{

}


来源:https://stackoverflow.com/questions/18215253/how-to-force-checking-for-incompatible-api-usage-in-android-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!