Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...