Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the minimum api level for projects in Android Studio?

I recently migrated a project into Android Studio 0.4.3. When compiling, it gave me errors on several lines of java, including the following:

FragmentManager fm = getFragmentManager();

fm.findFragmentById()

@Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

getResources().getStringArray(R.array.course_descriptions); 

I see the following error message:

Call requires API level 11 (current min is 7)

I'm running Android Studio .0.4.3. I also downloaded Android 4.4.2 (API 19) through the SDK manager.

I added the following line to my manifest:

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

I did a "Sync Project with Gradle files", cleaned and rebuilt the project. I still see the same errors.

How do I fix this issue ?

like image 376
JohnB Avatar asked Jan 30 '14 07:01

JohnB


People also ask

How do I change the API level in Android project?

Step 1: Open your project in Android mode then go to Gradle Scripts > build. gradle(Module: app) as shown in the following image. Step 2: Refer to the below image and here you have to change the minSdkVersion and targetSdkVersion as per the requirement.

Which file in an Android project specifies the minimum API level for a project?

android:minSdkVersion — Specifies the minimum API Level on which the application is able to run. The default value is "1".

What is the minimum required sdk API level?

For more information about downloading and installing Android SDK components, see Android SDK Setup. Beginning in August 2021, the Google Play Console requires that new apps target API level 30 (Android 11.0) or higher. Existing apps are required to target API level 30 or higher beginning in November 2021.


4 Answers

I have 0.8.6 version and it's can be done like this:

In the menu: File -> Project Structure.

In the open menu, navigate to app, then in the tabs choose Flavors.

enter image description here

like image 106
AsfK Avatar answered Oct 20 '22 16:10

AsfK


If you have generated your project on recent versions of Android Studio, the setting is in gradle config file. Find build.gradle file in your application module. There should be something like this.

defaultConfig {
    minSdkVersion 7
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}
like image 34
Yuichi Araki Avatar answered Oct 20 '22 17:10

Yuichi Araki


Starting from gradle build system all your setting related to sdk and compilation APIs will be overridden by what you define in your build.gradle file.

So going forward if you want you can remove these all configurations from your AndroidManifest.xml and keep them in build.gradle files only to avoid confusions.

So check minSdkVersion in module's build.gradle file which is throwing the error.

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.1'

    defaultConfig {
        minSdkVersion 7      // Change 7 to 11 will solve your problem
        targetSdkVersion 19
    }

}

I prefer to have these all configurations in my top project level build.gradle file because if the configurations are different in different modules you will be ended up with Manifest Merging error.

like image 44
Piyush Agarwal Avatar answered Oct 20 '22 17:10

Piyush Agarwal


In the latest version as of dated 2020, perform the following steps:

  1. Click on Files (top left)
  2. Go to Project Structure (Ctlr + Alt + Shift + S)
  3. Click on modules
  4. In the right pane, click on Default Config (Middle one)
  5. Change Minimum SDK version
  6. Apply and click OK

Done!

like image 22
Vani Gupta Avatar answered Oct 20 '22 17:10

Vani Gupta