Android studio:为什么在AndroidManifest.xml 和build.gradle 中都指定了minSdkVersion 和targetSdkVersion? [英] Android studio: why are minSdkVersion and targetSdkVersion specified both in AndroidManifest.xml and build.gradle?
问题描述
我刚刚发现了 Android Studio 的一些奇怪之处:它在 build.gradle
文件中有一些配置选项,这些选项覆盖了 AndroidManifest.xml
文件中指定的内容.
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.
例如,我在 build.gradle
中有以下几行:
For instance, I had the following lines in build.gradle
:
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 10
}
...
}
覆盖了AndroidManifest.xml
中的相应标签:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8"/>
我真的不喜欢将相同的设置分布在两个不同的文件中,所以我想知道是否可以从 build.gradle
或 AndroidManifest.xml<安全地删除它/code> 以及保留它更有意义的地方.
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.
推荐答案
Gradle 覆盖清单值,我更喜欢更新 build.gradle
文件而不是清单.可能这是使用 Gradle 的正确方法.Gradle 支持可以通过 IDE 控制的产品风格,这些产品风格可以改变我们 Manifest 中的许多内容,例如包名称、版本代码、版本名称、目标 SDK 等等.然后在 Android Studio 中单击一下,您可以更改许多属性并生成另一个 apk.
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.
您可以保留清单原样并在 build.gradle
中进行所有配置.您可以安全地删除
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.
这篇关于Android studio:为什么在AndroidManifest.xml 和build.gradle 中都指定了minSdkVersion 和targetSdkVersion?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!