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.
我刚刚发现Android studio有一些奇怪的地方:它在构建中有一些配置选项。渐变文件,覆盖AndroidManifest中指定的内容。xml文件。
For instance, I had the following lines in build.gradle
:
例如,我在build中有以下几行代码。
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 10
}
...
}
which was overriding the corresponding tag in AndroidManifest.xml
:
它覆盖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.
我不太喜欢将相同的设置分散在两个不同的文件中,所以我想知道是否可以安全地将其从build中删除。gradle或AndroidManifest。xml以及保存它更有意义的地方。
2 个解决方案
#1
101
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.
Gradle覆盖了manifest值,我更喜欢更新构建。等级文件而不是清单。这可能是使用Gradle的正确方法。Gradle支持可以通过IDE控制的产品风格,这些产品风格可以改变很多东西,比如包名、版本代码、版本名、目标SDK等。然后在Android Studio中点击一次,你可以改变很多属性并生成另一个apk。
You can leave the manifest as it is and do all configuration in build.gradle
. You can safely remove
您可以保留清单,并在build.gradle中完成所有配置。您可以安全地删除
<uses-sdk></uses-sdk>
from manifest as well as version codes.
从清单和版本代码。
#2
0
From the Android docs:
从Android文档:
Note: If your app defines the app version directly in the element, the version values in the Gradle build file will override the settings in the manifest. Additionally, defining these settings in the Gradle build files allows you to specify different values for different versions of your app. For greater flexibility and to avoid potential overwriting when the manifest is merged, you should remove these attributes from the element and define your version settings in the Gradle build files instead.
注意:如果您的应用程序直接在元素中定义应用程序版本,那么Gradle构建文件中的版本值将覆盖清单中的设置。此外,在Gradle构建文件中定义这些设置允许您为不同版本的应用程序指定不同的值。为更大的灵活性和避免潜在的重写清单合并时,你应该删除这些属性的元素,在Gradle构建文件中定义版本设置。
https://developer.android.com/studio/publish/versioning.html#appversioning
https://developer.android.com/studio/publish/versioning.html appversioning
#1
101
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.
Gradle覆盖了manifest值,我更喜欢更新构建。等级文件而不是清单。这可能是使用Gradle的正确方法。Gradle支持可以通过IDE控制的产品风格,这些产品风格可以改变很多东西,比如包名、版本代码、版本名、目标SDK等。然后在Android Studio中点击一次,你可以改变很多属性并生成另一个apk。
You can leave the manifest as it is and do all configuration in build.gradle
. You can safely remove
您可以保留清单,并在build.gradle中完成所有配置。您可以安全地删除
<uses-sdk></uses-sdk>
from manifest as well as version codes.
从清单和版本代码。
#2
0
From the Android docs:
从Android文档:
Note: If your app defines the app version directly in the element, the version values in the Gradle build file will override the settings in the manifest. Additionally, defining these settings in the Gradle build files allows you to specify different values for different versions of your app. For greater flexibility and to avoid potential overwriting when the manifest is merged, you should remove these attributes from the element and define your version settings in the Gradle build files instead.
注意:如果您的应用程序直接在元素中定义应用程序版本,那么Gradle构建文件中的版本值将覆盖清单中的设置。此外,在Gradle构建文件中定义这些设置允许您为不同版本的应用程序指定不同的值。为更大的灵活性和避免潜在的重写清单合并时,你应该删除这些属性的元素,在Gradle构建文件中定义版本设置。
https://developer.android.com/studio/publish/versioning.html#appversioning
https://developer.android.com/studio/publish/versioning.html appversioning