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

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

问题描述

我刚刚将一个项目从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和目标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.

最佳做法是完全删除清单中的<uses-sdk>标记,并且仅使用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设置同样适用.

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

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