Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Context.getPackageName() vs BuildConfig.APPLICATION_ID

Tags:

android

gradle

I can retrieve the package name using:

Context.getPackageName() 

or

BuildConfig.APPLICATION_ID 

Is there any difference between those 2 ways? Is one preferred to another in particular situations? Is it safe to assume that they always give the same result?

Basically, which one is better?

like image 502
Manza Avatar asked Feb 13 '17 13:02

Manza


People also ask

What is the difference between package name and application ID?

The package name is just to organize your code. The applicationId, on the other hand, is used to identify your app in the Play Store. You will change this only if you plan to generate another app based on same code.

How is BuildConfig generated?

There's a class called BuildConfig. java which is automatically generated by the build system. This class is updated automatically by Android's build system (like the R class). It already contains a static final boolean called DEBUG, which is normally set to true.

What is package name in Android Studio?

The package name of an Android app uniquely identifies your app on the device, in Google Play Store, and in supported third-party Android stores.


1 Answers

As of Android Studio 3.5, BuildConfig.APPLICATION_ID is deprecated and replaced with BuildConfig.LIBRARY_PACKAGE_NAME.

From Android Google Source:

BuildConfig: Deprecate APPLICATION_ID in libraries.

It is at best misleading, so it is marked as deprecated and replaced by LIBRARY_PACKAGE_NAME.

like image 106
AL. Avatar answered Sep 19 '22 00:09

AL.