build.gradle 中的新 applicationId 是如何工作的?

时间:2023-02-02
本文介绍了build.gradle 中的新 applicationId 是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

Google 发布了 0.11 版的 Android Gradle 插件.

Google released version 0.11 of the Android Gradle plugin.

发行说明包含以下内容:

The release notes contains the following:

0.11 中用户可见的变化之一是我们已弃用packageName 和 packageNameSuffix 设置,并将它们重命名为applicationId 和 applicationIdSuffix.这样做的目的是使很明显,此应用程序 ID 与包分离清单中的声明,特别是 R 类和BuildConfig 类,以及应用程序中的所有实现类,可以自由重命名和重构;你只需要保持applicationId 相同.如果你打开你的 build.gradle 文件,lint 是突出显示这些已弃用的调用并提供快速修复以进行更新他们:

One of the user visible changes in 0.11 is that we've deprecated the packageName and packageNameSuffix settings, and have renamed them to applicationId and applicationIdSuffix. The purpose of this is to make it clear that this application id is decoupled from package declarations in your manifest, and in particular, the R class and the BuildConfig class, and all the implementation classes inside your app, can be renamed and refactored freely; you just need to keep applicationId the same. If you open your build.gradle file, lint is highlighting these deprecated calls and offering quickfixes to update them:

这究竟是什么意思.构建脚本中的包名如何与清单中的包名解耦?

What exactly does this mean. How is the packagename in the build script decoupled from the one in the manifest?

推荐答案

package 标识设备上安装的一个应用程序.属性名称本身具有误导性,因为人们可能认为重构 java 类可能还需要重命名 package 属性.package 属性可以是任何符合 javadoc 中描述的限制的字符串.

package specified in AndroidManifest.xml identify one application installed on the device. The name of the property itself is misleading because one may think that refactoring java classes may require renaming package property as well. package property can be any string respecting limitation described in javadoc.

由于这种混淆,Google 家伙决定将 package 重命名为 applicationId.但是,此更改仅适用于 gradle 文件.更改清单属性名称会破坏与以前版本的兼容性,这是我的猜测.

Because this confusion Google guys decided to rename package to applicationId. However, this change apply to gradle file only. Changing manifest property name would break compatibility with previous versions, that's my guess.

因此,当您构建 APK 时,gradle 会将清单的 package 属性值替换为 gradle 脚本中指定的 applicationId 值.

So when you build your APK, gradle replaces manifest's package property value with applicationId value specified in gradle script.

如果您想自己测试.只需将 applicationId 设置为与清单的 package 不同的值并构建 APK.然后转到文件夹 /build/intermediates/manifests/dev/debug 并打开 AndroidManifest.xml.你会在那里找到 applicationId 值.

If you would like to test it yourself. Just set applicationId with different value that your manifest's package and build APK. Then go to folder /build/intermediates/manifests/dev/debug and open AndroidManifest.xml. You will find there applicationId value.

这篇关于build.gradle 中的新 applicationId 是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:在 jCenter 中分发 Android 库以在 gradle 中使用 下一篇:Android Studio 突然开始显示无法解析 com.android.support...25.0.0 错误信息,

相关文章

最新文章