Technical docs‎ > ‎New Build System‎ > ‎

ApplicationId versus PackageName

This page is obsolete. Redirecting to https://developer.android.com/studio/build/application-id.html




All Android apps have a package name. The package name uniquely identifies the app on the device; it is also unique in the Google Play store. This means that once you have published an app with this package name, you can never change it; doing so would cause your app to be treated as a brand new app, and existing users of your app will not see the newly packaged app as an update.

Prior to the Android Gradle build system, the package name for your app was determined by the package attribute at the root element of your manifest file:
AndroidManifest.xml:
<manifest xmlns:android='http://schemas.android.com/apk/res/android'
android:versionCode='1'
However, the package defined here also serves a secondary purpose: it is used to name the package for your R resource class (as well as to resolve any relative class names to Activities). In the above example, the generated R class will be com.example.my.app.R, so if you have code in other packages that need to reference resources, it needs to import com.example.my.app.R.
With the new Android Gradle build system, you can easily build multiple different versions of your app; for example, you can build both a 'free' version and a 'pro' version of your app (using flavors), and these should have different packages in the Google Play store such that they can be installed and purchased separately, both installed at the same time, and so on. Similarly, you may also build both 'debug' and 'alpha' and 'beta' versions of your app (using build types) and these can also similarly contribute to unique package names.

At the same time, the R class you are importing in your code must stay the same at all time; your .java source files should not have to change when you are building the different versions of your app.
Therefore, we have decoupled the two usages of package name:
  • The final package that is used in your built .apk's manifest, and is the package your app is known as on your device and in the Google Play store, is the 'application id'.
  • The package that is used in your source code to refer to your R class, and to resolve any relative activity/service registrations, continues to be called the 'package'.
You can specify the application id in your gradle file as follows:
app/build.gradle:

compileSdkVersion 19

applicationId 'com.example.my.app'
targetSdkVersion 19
versionName '1.0'
...

As before, you need to specify the package used for your code in the Manifest file, just as shown in the above AndroidManifest.xml sample.
Here comes the critical part: When you've done the above, the two packages are independent. You are completely free to refactor your code - changing the internal package used for your activities and services, updating your Manifest package, and refactoring your import statements. This will have no bearing on the final id of your application, which is now always going to be the applicationId specified in the Gradle file.
You can vary the applicationId of your app for flavors and build types by using the following Gradle DSL methods:
app/build.gradle:
pro {
}
applicationId = 'com.example.my.pkg.free'
}
debug {
}
....

(In Android Studio you can configure all of this graphically as well in the Project Structure dialog.)
NOTE: For compatibility reasons, if you have not defined an applicationId in your build.gradle file, the applicationId will default to the same value as the one specified in the AndroidManifest.xml. In that case, the two are obviously not decoupled, and attempting to refactor your code can accidentally change the id of your application as well! In Android Studio, newly created projects always specify both.
NOTE 2: The package name must always be specified in the default AndroidManifest.xml file. If you have multiple manifests (e.g. a flavor specific manifest or a buildType specific manifest), the package name is optional, but if it is specified it must be identical to the package specified d in the main manifest.
Change App Package Name Android

Creating multiple APKs for different purposes.

Android studio change package name 2019 Step 4: Now select that folder that conatains java files (myactivity.java etc) and then right click on it then select refector then rename, Now a warning will be displayed but ignore it you go ahead and click Rename Package and rename it by new app name. Side tip: Change icon of any EXE file. About APK Icon Editor. APK Icon Editor is a free and open source Android app package editor which lets you edit various components of an APK file without any technical knowledge or coding. So many beginners of android studio have doubt “How to change package name in android studio app“? You can change it easily from Android Studio. Here are the steps: You can change it easily from Android Studio. Here are the steps:In the Android pane, click on the little gear icon.Uncheck/Deselect the Compact Empty Middle Packages option. The package name is a unique name to identify a specific app. It is very common we need to change the package name. Here i am going to show two ways to rename package in android app. Change the App Name Usually, when you change the project name, you wanna change the name of your app too. Go to the res folder values strings.xml and change the appname to your new name.

PackageName vs ApplicationId

Nowadays, many times we come to the situation that we need the APK with another different package name. Most of us do it easily, but sometimes we got stuck because of applicationId and packageName.We must know the difference between packageName and applicationId. And the other thing is Java package.

The following are the three which keeps us confusing:

  1. applicationId: BuildConfig.APPLICATION_ID
  2. packageName: getApplicationContext().getPackageName()
  3. Java package: BuildConfig.class.getPackage().toString()

Let’s see with an example

The following is the snippet from the gradle of a sample Android application.

Here we will be having two different APKs.

Change App Package Name Android
  1. Release APK with com.mindorks.example.release
  2. Debug APK with com.mindorks.example.debug

Android Studio Get Package Name

The following is the snippet from manifest of the same sample Android application.

The following is the project package snippet of the same sample Android application.

So, let’s create a debug APK and see what are the values of all the three.

Read the values carefully.

The following shows the final AndroidManifest file after APK creation.

getPackageName gives the same applicationId which is created at the final moment from the gradle file and it overrides the AndroidManifest package. So the final AndroidManifest contains the same applicationId. So, the getPackageName is the same as the applicationId as the applicationId overrides the packageName in the AndroidManifest at the final moment.

But for the Java code, the package is same as the project structure. The package that is used in your source code to refer to your R class, and to resolve any relative activity, service registrations, continues to be called the package as defined in your manifest. So, the AndroidManifest should have the package same as Java package to resolve relative activity, service.

So, with the same java package, we can create any number of APKs with all unique applicationId.

But the final AndroidManifest contains the package as the unique applicationId only.

Change App Name Android Manifest.xml

If you have to actually change the structure of your project, then you have to change your packageName in Manifest.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.

Change App Name Android Studio

We can also create multiple APKs through productFlavors like above.

Remember, once an app has been published to Google Play store, the ApplicationId should never be changed.

So, the applicationId matters.

Happy Coding :)

Change App Name Android Tablet

Also, Let’s become friends onTwitter,Linkedin,Github, andFacebook.