Androidmanifest 和 build.gradle 中的 minsdk 和 targetsdk 两者? [英] minsdk and targetsdk in Androidmanifest and build.gradle both?

查看:30
本文介绍了Androidmanifest 和 build.gradle 中的 minsdk 和 targetsdk 两者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将一个项目从 Exclipse 迁移到 Android Studio.build.gradle 文件有一个部分,其中包括:

I have just migrated a project from Exclipse to Android Studio. The build.gradle file has a section that includes:

defaultConfig {
    applicationId "com.example.someone.myapplication"
    minSdkVersion 8
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}

AndroidManifest.xmluses-sdk 元素中也是如此.

The same thing is in the uses-sdk element of the AndroidManifest.xml.

当两种设置同时存在时,哪些设置受到尊重?另外,我应该从 AndroidManifest.xml 中删除它们吗?我的项目必须至少支持 Api-8.如果从清单文件中删除 uses-sdk 部分,它会在旧平台上有什么不同吗?

When both settings are simultaneously present, which settings are respected? Also, should I remove them from AndroidManifest.xml? My project must support Api-8 at least. Would it make any difference on old platforms if the uses-sdk section is removed from the manifest file?

推荐答案

您只需要在 build.gradle 文件中定义 min SDK 和 target SDK.Gradle 构建系统会在您构建时自动在清单中定义这些值.

You only need to define the min SDK and target SDK in the build.gradle file. The Gradle build system will automatically define these values in the manifest when you build.

如果您在 build.gradleAndroidManifest.xml 文件中定义它们,build.gradle 文件中的设置将覆盖明显的.

If you define them in both the build.gradle and AndroidManifest.xml files, the settings in the build.gradle file will override the manifest ones.

最佳做法是完全删除清单中的 标签,只使用 build.gradle 文件指定最小 SDK 和目标 SDK.这不会对旧设备产生任何影响;它将运行完全相同.

Best practice is to completely remove the <uses-sdk> tag in the manifest and only use the build.gradle file to specify the min SDK and target SDK. This will not make any difference for older devices; it will run exactly the same.

defaultConfig {
    minSdkVersion 8
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}

同样的事情适用于 versionCodeversionName 设置.

The same thing applies for the versionCode and versionName settings.

这篇关于Androidmanifest 和 build.gradle 中的 minsdk 和 targetsdk 两者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆