Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android studio: why are minSdkVersion and targetSdkVersion specified both in AndroidManifest.xml and build.gradle?

I just discovered something weird about Android studio: it has some configuration options in the build.gradle file that override what is specified in the AndroidManifest.xml file.

For instance, I had the following lines in build.gradle:

android {     compileSdkVersion 18     buildToolsVersion "18.1.1"      defaultConfig {         minSdkVersion 10         targetSdkVersion 10     } ... } 

which was overriding the corresponding tag in AndroidManifest.xml:

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

I don't really like to have the same settings spread in two different files, so I am wondering if I can safely remove it either from build.gradle or AndroidManifest.xml and where it makes more sense to keep it.

like image 928
mariosangiorgio Avatar asked Nov 15 '13 09:11

mariosangiorgio


People also ask

What is minSdkVersion and targetSdkVersion in Android?

minSdkVersion : The min sdk version is the minimum version of the Android operating system required to run your application. targetSdkVersion : The target sdk version is the version your app is targeted to run on. Follow this answer to receive notifications.

Can compile SDK and target SDK be different?

Relationship between compile and target SDK versionsEven if the compileSdkVersion and targetSdkVersion have completely different meanings they are obviously not independent.

How do I change my target API level on Android?

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.

How do I change the minimum SDK version?

check it: Android Studio->file->project structure->app->flavors->min sdk version and if you want to run your application on your mobile you have to set min sdk version less than your device sdk(API) you can install any API levels. Show activity on this post. Set the min SDK version in your project's AndroidManifest.


1 Answers

Gradle overrides the manifest values, and I prefer to update the build.gradle file rather than the manifest. Probably this is the right way using Gradle. Gradle supports product flavours which can be controlled via an IDE and those product flavors can change many things in our Manifest like package name, version code, version name, target SDK and many other. Then by one click in Android Studio you can change many properties and generate another apk.

You can leave the manifest as it is and do all configuration in build.gradle. You can safely remove

<uses-sdk></uses-sdk> 

from manifest as well as version codes.

like image 176
mar3kk Avatar answered Oct 06 '22 09:10

mar3kk