【问题标题】:Application does not specify API level应用程序未指定 API 级别
【发布时间】:2010-07-25 16:10:27
【问题描述】:

我刚刚开始将 Eclipse 用于 Android 应用程序。 我已经安装了 Eclipse 3.5.2 和 Java 5 AVD 是 Android 2.1 API 7

我最初的 Hello Android 程序运行良好,但不会再次运行。

得到以下错误:

[2010-07-25 09:47:31 - HelloAndroid] 警告:应用程序未指定 API 级别要求!
[2010-07-25 09:47:31 - HelloAndroid] 设备 API 版本为 7 (Android 2.1-update1)

搜索了论坛,但只能找到清单文件的引用以确保已设置以下内容:

<uses-sdk android:minSdkVersion="3" />

我的清单文件不包含该行:

 <?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>

我检查了 adv mgr,它设置为 7 在 Eclipse 中,我转到属性 -> Android 并将其设置为 7

得到相同的警告

【问题讨论】:

  • 提醒一下。 Eclipse 不会仅仅因为您在 SDK 管理器中创建了 AVD 而生成该行。通过属性设置目标 API 是正确的做法,但也不会为您生成行。它仅在您在项目创建时指定 AVD 时生成。在导入现有项目时,我无论如何都找不到指定这样的内容,只能通过 new-project

标签: android eclipse


【解决方案1】:

好吧,如果 Eclipse 出于某种原因没有为您生成该行,那么您可以自己添加它。

添加行:
&lt;uses-sdk android:minSdkVersion="3" /&gt;

到您的清单,就在结束清单标记之前。

【讨论】:

【解决方案2】:

你还应该包括

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

在您的清单文件中,如果它不存在的话。从您的问题中不清楚,但似乎不是。

有关 API 级别的未来参考,请参阅this page

【讨论】:

  • 感谢您的意见。对于其他阅读本文的人,我手动输入了两个 src 命令,而 Eclipse 不喜欢手动输入。说是不同步。但我能够在 Eclipse 中更新清单。它现在运行没有错误,但 avd 只提供日期和时间。我会弄清楚但至少没有错误。谢谢
【解决方案3】:

Android SDK 工具修订版 16 中似乎存在一个错误,需要正确排序 uses-sdk 标记。如果您同时使用targetSdkVersionminSdkVersion,请按以下顺序排列:

<uses-sdk android:targetSdkVersion="10" /> <!-- before minSdkVersion -->
<uses-sdk android:minSdkVersion="7" />     <!-- after targetSdkVersion -->

颠倒顺序会给出警告信息并弹出设备选择窗口。因此,我建议将其写在一行中:

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

【讨论】:

  • 我打开了issue #27320
  • 这对我来说非常有效。谢谢!!我使用了 Project Build target Android 4.0 和代码
【解决方案4】:

清单应该只包含一个元素,多次使用是错误的。

在 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.

更多信息:http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

【讨论】:

  • 也感谢您在这里发表评论。作为参考,已关闭的问题是issue #27320
【解决方案5】:

您必须在代码中指定 API 级别,并且应该在一行中。

使用-sdk android:targetSdkVersion="19" android:minSdkVersion="4"。

目标应该是最新的。它可能对你有帮助,因为它对我有用。谢谢

【讨论】:

    猜你喜欢
    • 2018-02-25
    • 1970-01-01
    • 2013-03-25
    • 2012-02-17
    • 1970-01-01
    • 2012-09-10
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    相关资源
    最近更新 更多