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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With