Android Lint 错误地认为最小 SDK 版本为 1

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10322482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:17:49  来源:igfitidea点击:

Android Lint erroneously thinks min SDK version is 1

androideclipsebuildcompiler-errorsandroid-lint

提问by jdk

Eclipse refuses to build my Android project. In the package explorer, the project root node has the little red error symbol, but nothing else inside of it has this symbol. The Problems tab shows errors detected by Lint:

Eclipse 拒绝构建我的 Android 项目。在包资源管理器中,项目根节点有一个小的红色错误符号,但它里面的其他任何东西都没有这个符号。“问题”选项卡显示 Lint 检测到的错误:

Call requires API level 3 (current min is 1): android.os.AsyncTask#<init>   
Call requires API level 3 (current min is 1): android.view.GestureDetector#<init>   
Call requires API level 3 (current min is 1): android.view.inputmethod.InputMethodManager#hideSoftInputFromWindow   
Call requires API level 3 (current min is 1): android.view.inputmethod.InputMethodManager#hideSoftInputFromWindow   
Call requires API level 3 (current min is 1): android.view.inputmethod.InputMethodManager#showSoftInput
Call requires API level 3 (current min is 1): android.view.inputmethod.InputMethodManager#showSoftInput
Call requires API level 3 (current min is 1): android.view.inputmethod.InputMethodManager#showSoftInput
Call requires API level 3 (current min is 1): android.view.inputmethod.InputMethodManager#toggleSoftInput
Call requires API level 3 (current min is 1): android.view.Menu#getItem 
Call requires API level 3 (current min is 1): android.view.Menu#getItem 
Call requires API level 3 (current min is 1): android.widget.HorizontalScrollView#getId 
Call requires API level 5 (current min is 1): android.app.Activity#onBackPressed    
Call requires API level 5 (current min is 1): android.app.Activity#onBackPressed    
Call requires API level 5 (current min is 1): android.app.Activity#onBackPressed    
Class requires API level 3 (current min is 1): android.view.inputmethod.InputMethodManager  
Class requires API level 3 (current min is 1): android.view.inputmethod.InputMethodManager  
Class requires API level 3 (current min is 1): android.view.inputmethod.InputMethodManager
Class requires API level 3 (current min is 1): android.view.inputmethod.InputMethodManager  
Class requires API level 3 (current min is 1): android.view.inputmethod.InputMethodManager  
Class requires API level 3 (current min is 1): android.view.inputmethod.InputMethodManager
Class requires API level 3 (current min is 1): android.widget.HorizontalScrollView
Class requires API level 3 (current min is 1): android.widget.HorizontalScrollView
Field requires API level 3 (current min is 1): android.os.Build#DISPLAY
Field requires API level 4 (current min is 1): android.content.res.Configuration#screenLayout   
Field requires API level 4 (current min is 1): android.os.Build#CPU_ABI 
Field requires API level 4 (current min is 1): android.os.Build#MANUFACTURER
Field requires API level 4 (current min is 1): android.os.Build$VERSION#SDK_INT

My best guess is that Lint thinks my minSdkVersion is 1, which it isn't; my manifest declares minSdkVersion="8". I've tried the following in an effort to fix this:

我最好的猜测是 Lint 认为我的 minSdkVersion 是 1,但事实并非如此;我的清单声明minSdkVersion="8". 我尝试了以下方法来解决这个问题:

  • Restarting Eclipse
  • Restarting my computer
  • Project > Clean
  • Manually deleting /binand /gento force hem to be generated again
  • 重启 Eclipse
  • 重新启动我的电脑
  • 项目 > 清洁
  • 手动删除/bin/gen强制重新生成下摆

At this point I'm out of ideas. Anybody have suggestions?

在这一点上,我没有想法。有人有建议吗?

回答by guanfei

I have the same problem, and my solution is:

我有同样的问题,我的解决方案是:

Right click on the project folder > Android tools > Clear Lint Markers

右键单击项目文件夹 > Android 工具 > 清除 Lint 标记

"Run Android Lint" makes some markers and the markers cause this error.

“运行 Android Lint”会生成一些标记,这些标记会导致此错误。

回答by DiscDev

"Clear Lint Markers" in the Accepted Answer removed the error temporarily, but it kept coming back every time I saved a file in the affected project.

Accepted Answer 中的“Clear Lint Markers”暂时消除了错误,但每次我在受影响的项目中保存文件时它都会出现。

To make it stop reporting that error, I had to disable the lint check altogether:

为了让它停止报告该错误,我不得不完全禁用 lint 检查:

Right click project -> Properties -> Android Lint Preferences

Search for "minSdk" in the search box

Click on "UsesMinSdkAttributes"

Click the "Ignore All" button at the bottom.

Clean and rebuild the project, and Eclipse/ADT will no longer run the lint check for minSdk on your project.

清理并重建项目,Eclipse/ADT 将不再对您的项目运行 minSdk 的 lint 检查。

回答by Coryffaeus

Make sure you have android:namespace identifier together with minSdkVersionattribute. Like this:

确保你有android:命名空间标识符和minSdkVersion属性。像这样:

android:minSdkVersion="8".

android:minSdkVersion="8".

When creating a project based on some Android sample projects (like BluetoothChat) the namespace gets omitted and confuses Lint. Then even clearing Lint Markers doesn't truly cure the issue as they reappear after running Lint again, which happens automatically pretty often.

在基于一些 Android 示例项目(如 BluetoothChat)创建项目时,命名空间被省略并混淆了 Lint。然后即使清除 Lint Markers 也不能真正解决问题,因为它们在再次运行 Lint 后重新出现,这种情况经常自动发生。

Note: this was verified with samples revision 1 for API16

注意:这已通过 API16 的示例修订版 1 进行了验证

回答by El Duderino

Try right clicking on the project folder > Android tools > fix properties

尝试右键单击项目文件夹 > Android 工具 > 修复属性

You should also check in the build properties that all your android libraries and things are checked and loading in the correct order. Right click on the project > Properties > Build

您还应该检查构建属性,以检查所有 android 库和事物并以正确的顺序加载。右键单击项目 > 属性 > 构建

回答by NameZero912

A simple Project -> Cleanalso fixed the issue for me.

一个简单的Project -> Clean也为我解决了这个问题。