Reputation: 103
I am new to Android Stuio. I created a project with the default setting and the added a fragment layout then fragment class
I am now getting the following error:
Class requires API level 11 (current min is 8)
on this line:
public class WeatherFragment extends Fragment {
here is my import:
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;
and this is my Manifest:
<?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>
Upvotes: 0
Views: 13024
Reputation: 219
Don't change your SDK in the manifest file, since the value always going to be overwritten by your "build.gradle" file (As specified in the Issue id: GradleOverrides.)
Not only that, but if you try to insert your SDK in the manifest file, it won't even work:
So, to fix that, try this method.
Go to your "build.gradle" file, and add this to your "defaultConfig".
defaultConfig{
minSdkVersion 15
targetSdkVersion 28
}
After that, remove the SDK you inserted into your manifest file, and it will work.
Upvotes: 1
Reputation: 1
you can change your minSdkVersion to 11 in Manifest as below. I hope it will help:
<?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>
Upvotes: 0
Reputation: 1092
If you persist to use SDK version 8, I think that you must use android.support.v4.app.Fragment
instead android.app.Fragment
.
It happened because android.app.Fragment
is supported from Android SDK version +11 and if you want to use that you must use support library.
Upvotes: 4
Reputation: 1039
Add the following lines in your manifest: While changing the minimal sdk version to 11, will help resolving your error...
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
Upvotes: 0
Reputation: 452
All the answers above are quite right but they don't explain why this is happening, the cause of the error is that you need at least API level 11 (Android 3.0). This is needed because the usage of Fragments in your API. Fragments were introduced in the 3.0 version. So if you want to allow devices with an Android version below than 3.0 you can not use Fragments.
Upvotes: 0
Reputation: 9884
Change your manifest as below:
<?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>
Upvotes: 2
Reputation: 4382
add this in your manifest
<?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>
Upvotes: 0
Reputation: 1595
change your manifest to this
<?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>
Upvotes: -1
Reputation: 13761
Basically the feature you want to use requires a minimal API that is not guaranteed in your current Manifest
file. You have to make sure it is set because any user that runs your app might have problems if they use a lower API for the one that's made your app.
You have to include a statement like this in your Manifest file to ensure the users will be running a minimal API of 11 (and by the way make your code compile).
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
Upvotes: 0
Reputation: 29632
add following lines in your manifest.xml before application tag starts.
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="16" />
Upvotes: 0