Android-Developer-Tools

Android Build System

Application ID for package identification

With the Android build system, the applicationId attribute is used to uniquely identify application packages for publishing. The application ID is set in the android section of the build.gradle file.

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 19
        buildToolsVersion "19.1"

    defaultConfig {
        applicationId "com.example.my.app"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    ...

Note: The applicationId is specified only in your build.gradle file, and not in the AndroidManifest.xml file.

When using build variants, the build system enables you to uniquely identify different packages for each product flavors and build types. The application ID in the build type is added as a suffix to those specified for the product flavors.

   productFlavors {
        pro {
            applicationId = "com.example.my.pkg.pro"
        }
        free {
            applicationId = "com.example.my.pkg.free"
        }
    }

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
        }
    }
    ....

The package name must still be specified in the manifest file. It is used in your source code to refer to your R class and to resolve any relative activity/service registrations.

    package="com.example.app">

Note: If you have multiple manifests (for example, a product flavor specific manifest and a build type manifest), the package name is optional in those manifests. If it is specified in those manifests, the package name must be identical to the package name specified in the manifest in the src/main/ folder.

For more information about the build files and process, see Build System Overview.