Edit: I like ofir_aghai's answer better, although my answer may still be helpful for apps that aren't on the Google Play Store.
If you're comfortable using the command line, a solution I like is Android's pm command. It can easily be called using adb like so:
$ adb shell "pm list packages -f test" package:/system/app/AutomationTest_JBUP.apk=com.sec.android.app.DataCreate package:/system/app/BluetoothTest.apk=com.sec.android.app.bluetoothtest
Replace test with whatever package you're looking for.
pm has a variety of options that may be useful depending what you want to do:
usage: pm list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [FILTER] pm list packages: prints all packages, optionally only those whose package name contains the text in FILTER. Options: -f: see their associated file. -d: filter to only show disbled packages. -e: filter to only show enabled packages. -s: filter to only show system packages. -3: filter to only show third party packages. -i: see the installer for the packages. -u: also include uninstalled packages.
android.defaultConfig.applicationIdproperty in your module'sbuild.gradle.ktsfile. The naming rules are: It must have at least two segments (one or more dots), each must start with a letter, all characters must be alphanumeric or underscore [a-zA-Z0-9_].