【问题标题】:Class requires API level 11 (current min is 8)类需要 API 级别 11(当前最低为 8)
【发布时间】:2019-01-27 23:30:00
【问题描述】:

我是 Android Stuio 的新手。我使用默认设置创建了一个项目,并添加了片段布局然后片段类

我现在收到以下错误:

类需要 API 级别 11(当前最低为 8)

在这一行:

公共类 WeatherFragment 扩展片段 {

这是我的导入:

import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;;
import android.support.v4.app.FragmentManager;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.support.v4.widget.DrawerLayout;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.app.Fragment;
import android.support.v4.app.ListFragment;

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jassim.yallabahrain.app" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.jassim.yallabahrain.app.MainActivity"
            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>

【问题讨论】:

  • 嗯,我不知道google.com 不起作用....
  • here 是在旧设备中实现片段的好教程。希望它能达到您的目的。

标签: android mobile sdk


【解决方案1】:

如果你坚持使用SDK版本8,我认为你必须使用android.support.v4.app.Fragment而不是android.app.Fragment

这是因为 Android SDK 版本 +11 支持 android.app.Fragment,如果你想使用它,你必须使用支持库。

【讨论】:

    【解决方案2】:

    如下更改清单:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jassim.yallabahrain.app" >
    
    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="17" />
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.jassim.yallabahrain.app.MainActivity"
            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>
    

    【讨论】:

      【解决方案3】:

      不要在清单文件中更改您的 SDK,因为该值总是会被​​您的“build.gradle”文件覆盖(如 问题 ID:GradleOverrides. 中指定) p>

      不仅如此,如果您尝试将 SDK 插入清单文件中,它甚至都不起作用:

      所以,要解决这个问题,试试这个方法。

      转到您的“build.gradle”文件,并将其添加到您的“defaultConfig”中。

      defaultConfig{
      
         minSdkVersion 15
         targetSdkVersion 28
      
      }
      

      之后,删除您插入到清单文件中的 SDK,它就可以工作了。

      【讨论】:

        【解决方案4】:

        在应用程序标记开始之前在您的 manifest.xml 中添加以下行。

        <uses-sdk
            android:minSdkVersion="11"
            android:targetSdkVersion="16" />
        

        【讨论】:

        • 使用 gradle 构建时,在build.grade 中设置minSdkVersiontargetSdkVersion,而不是在AndroidManifest.xml 中设置&lt;uses-sdk&gt; 元素。 [仍然,Android Studio 0.6.1 警告说某些布局资源“需要 API 级别 11(当前最低为 1)”,即使它设置为 13。]
        【解决方案5】:

        基本上,您要使用的功能需要一个最小的 API,这在您当前的 Manifest 文件中无法保证。您必须确保它已设置,因为任何运行您的应用的用户都可能会遇到问题,如果他们使用较低的 API 来制作您的应用。

        您必须在您的清单文件中包含这样的语句,以确保用户将运行 11 的最小 API(顺便让您的代码编译)。

        <uses-sdk
            android:minSdkVersion="11"
            android:targetSdkVersion="19" />
        

        【讨论】:

          【解决方案6】:

          将此添加到您的清单中

          <?xml version="1.0" encoding="utf-8"?>
          <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.jassim.yallabahrain.app" >
          <uses-sdk
              android:minSdkVersion="11"
              android:targetSdkVersion="19" />
          <application
              android:allowBackup="true"
              android:icon="@drawable/ic_launcher"
              android:label="@string/app_name"
              android:theme="@style/AppTheme" >
              <activity
                  android:name="com.jassim.yallabahrain.app.MainActivity"
                  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>
          

          【讨论】:

            【解决方案7】:

            以上所有答案都非常正确,但它们没有解释为什么会发生这种情况,错误的原因是您至少需要 API 级别 11 (Android 3.0)。这是必需的,因为在您的 API 中使用了 Fragments。片段是在 3.0 版本中引入的。因此,如果您想允许 Android 版本低于 3.0 的设备,则不能使用 Fragments。

            【讨论】:

              【解决方案8】:

              在清单中添加以下行: 将最小 sdk 版本更改为 11 时,将有助于解决您的错误...

              <uses-sdk
                  android:minSdkVersion="11"    
                  android:targetSdkVersion="18" />
              

              【讨论】:

                【解决方案9】:

                您可以在 Manifest 中将 minSdkVersion 更改为 11,如下所示。我希望它会有所帮助:

                    <?xml version="1.0" encoding="utf-8"?>
                <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                    package="com.example.s1"
                    android:versionCode="1"
                    android:versionName="1.0" >
                
                <uses-sdk
                    android:minSdkVersion="11"
                    android:targetSdkVersion="21" />
                
                    <application
                        android:allowBackup="true"
                        android:icon="@drawable/ic_launcher"
                        android:label="@string/app_name"
                        >
                        <activity
                            android:name=".MainActivity"
                            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>
                

                【讨论】:

                  【解决方案10】:

                  将您的清单更改为此

                  <?xml version="1.0" encoding="utf-8"?>
                  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                      package="com.jassim.yallabahrain.app" >
                  
                      <uses-sdk
                              android:minSdkVersion="11"
                              android:targetSdkVersion="19" />
                  
                      <application
                          android:allowBackup="true"
                          android:icon="@drawable/ic_launcher"
                          android:label="@string/app_name"
                          android:theme="@style/AppTheme" >
                          <activity
                              android:name="com.jassim.yallabahrain.app.MainActivity"
                              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>
                  

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 2015-11-17
                    • 1970-01-01
                    • 2012-09-14
                    • 1970-01-01
                    • 1970-01-01
                    • 2015-01-15
                    • 1970-01-01
                    • 1970-01-01
                    相关资源
                    最近更新 更多