Android ApplicationId vs PackageName

Android ApplicationId vs PackageName

You might wonder what is the difference between package name we have in AndroidManifest.xml file and ApplicationId we see in build.gradle. They seem to be the same thing, but actually they are 2 different things. So if you didn’t know what is the difference between these 2 properties, you can find out now.

ApplicationId

  • represents the package name used to identify your application in Google Play store and is used to build your apk’s manifest.
  • once an app has been published to Gooogle Play store, the ApplicationId should never be changed
  • it is declared in app/build.gradle file
  • you can specify different applicationId for different versions of your app (flavors)
  • if you do not declare the ApplicationId, it will have as default value, the name from AndroidManifest.xml, but this is not recommended as this way they will be coupled and any refactor on package name from manifest will lead to a rename in ApplicationId also (which is exactly what we want to avoid)
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

PackageName

  • represents the package name used in your source code to refer to your R class and imports.
  • it is declared in AndroidManifest.xml file and is mandatory
  • if you have multiple manifest files (like when using flavors) it is optional, but if you want to declare it, it must be the same as the one declared in the default AndroidManifest.xml.
  • if you rename the package name from manifest file, it will have NO impact on the ApplicationId even if they have the same name.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

You can read more about this from here:

http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename

, , , ,
Previous Post
Did you know about Percent Support Library
Next Post
Android About ConstraintLayout

Related Posts

Menu