問題描述
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 是如何工作的?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!