Android 应用程序未指定 API 级别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3329926/
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
Application does not specify API level
提问by Trent
I am just beginning to use Eclipse for Android applications. I have installed Eclipse 3.5.2 and Java 5 AVD is Android 2.1 API 7
我刚刚开始将 Eclipse 用于 Android 应用程序。我已经安装了 Eclipse 3.5.2 并且 Java 5 AVD 是 Android 2.1 API 7
My initial Hello Android program ran fine but will not run again.
我最初的 Hello Android 程序运行良好,但不会再次运行。
getting the following error:
收到以下错误:
[2010-07-25 09:47:31 - HelloAndroid] WARNING: Application does not specify an API level requirement!
[2010-07-25 09:47:31 - HelloAndroid] Device API version is 7 (Android 2.1-update1)
[2010-07-25 09:47:31 - HelloAndroid] 警告:应用程序未指定 API 级别要求!
[2010-07-25 09:47:31 - HelloAndroid] 设备 API 版本为 7 (Android 2.1-update1)
searched the forums but could only find a refernece to manifest file to be sure following was set:
搜索了论坛,但只能找到清单文件的引用,以确保设置了以下内容:
<uses-sdk android:minSdkVersion="3" />
my manifest file does not contain that line:
我的清单文件不包含该行:
<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.helloandriod" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloAndroid" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I have checked the adv mgr and it is set to 7 In Eclipse i went to properties -> Android and set it to 7
我检查了 adv mgr 并将其设置为 7 在 Eclipse 中,我转到了属性 -> Android 并将其设置为 7
get same warnings
得到相同的警告
回答by nicholas.hauschild
Well, if Eclipse is, for whatever reason, not generating that line for you, by all means you can add it yourself.
好吧,如果 Eclipse 出于某种原因没有为您生成该行,那么您可以自己添加它。
Add the line:<uses-sdk android:minSdkVersion="3" />
添加行:<uses-sdk android:minSdkVersion="3" />
to your manifest, right before the ending manifest tag.
到您的清单,就在结束清单标签之前。
回答by chrisbunney
回答by Paul Lammertsma
It appears that there is a bug in the Android SDK Tools revision 16 that requires the correct ordering of the uses-sdk
tags. If you're using both targetSdkVersion
and minSdkVersion
, order them as follows:
Android SDK 工具修订版 16 中似乎存在一个错误,需要正确排序uses-sdk
标签。如果您同时使用targetSdkVersion
and minSdkVersion
,请按如下方式订购它们:
<uses-sdk android:targetSdkVersion="10" /> <!-- before minSdkVersion -->
<uses-sdk android:minSdkVersion="7" /> <!-- after targetSdkVersion -->
Reversing the order will give the warning message and pop up the device selection window. I therefore recommend writing this in a single line:
颠倒顺序会给出警告信息并弹出设备选择窗口。因此,我建议将其写在一行中:
<uses-sdk android:targetSdkVersion="10" android:minSdkVersion="7" />
回答by Tor Norbye
The manifest should only contain a single element, it's an error to use more than once.
清单应该只包含一个元素,多次使用是错误的。
In ADT 17, we have a new lint warning which detects and reports this problem:
在 ADT 17 中,我们有一个新的 lint 警告来检测并报告这个问题:
$ lint --version
lint: version 17
$ lint --show MultipleUsesSdk
MultipleUsesSdk
---------------
Summary: Checks that the <uses-sdk> element appears at most once
Priority: 6 / 10
Severity: Error
Category: Correctness
The <uses-sdk> element should appear just once; the tools will *not* merge the
contents of all the elements so if you split up the atttributes across
multiple elements, only one of them will take effect. To fix this, just merge
all the attributes from the various elements into a single <uses-sdk>
element.
More information: http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
更多信息:http: //developer.android.com/guide/topics/manifest/uses-sdk-element.html
回答by Omar Faroque Anik
you have to specify the API level in your code and it should be in a single line.
你必须在你的代码中指定 API 级别,它应该在一行中。
uses-sdk android:targetSdkVersion="19" android:minSdkVersion="4".
使用-sdk android:targetSdkVersion="19" android:minSdkVersion="4"。
Target should be latest one. It might help you as it worked for me. Thanks
目标应该是最新的。它可能对你有帮助,因为它对我有用。谢谢