mariosangiorgio mariosangiorgio - 1 year ago 203
Android Question

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

file that override what is specified in the

For instance, I had the following lines in

android {
compileSdkVersion 18
buildToolsVersion "18.1.1"

defaultConfig {
minSdkVersion 10
targetSdkVersion 10

which was overriding the corresponding tag in


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
and where it makes more sense to keep it.

Answer Source

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


from manifest as well as version codes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download