android – How does the new applicationId in build.gradle work?-ThrowExceptions

Exception or error:

Google released version 0.11 of the Android Gradle plugin.

The release notes contains the following:

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

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

How to solve:

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.

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.

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *