248

For the "Hello World" example in android.com, the package name is
"package com.example.helloandroid;"

Is there any guideline/standard to name this package? (references would be nice)

7 Answers 7

279

Android follows normal java package conventions plus here is an important snippet of text to read (this is important regarding the wide use of xml files while developing on android).

The reason for having it in reverse order is to do with the layout on the storage media. If you consider each period ('.') in the application name as a path separator, all applications from a publisher would sit together in the path hierarchy. So, for instance, packages from Adobe would be of the form:

com.adobe.reader (Adobe Reader)

com.adobe.photoshop (Adobe Photoshop)

com.adobe.ideas (Adobe Ideas)

[Note that this is just an illustration and these may not be the exact package names.]

These could internally be mapped (respectively) to:

com/adobe/reader

com/adobe/photoshop

com/adobe/ideas

The concept comes from Package Naming Conventions in Java, more about which can be read here:*

http://en.wikipedia.org/wiki/Java_package#Package_naming_conventions

Source: http://www.quora.com/Why-do-a-majority-of-Android-package-names-begin-with-com

13
  • 2
    here's a (brief) reference from Android site - have a look "Package Name" paragraph at developer.android.com/resources/tutorials/hello-world.html Oct 16, 2011 at 22:01
  • 4
    You have a mistake in your answer that might mislead people. it's com.adobe.ideas, and not com.adobe.Ideas (capital I). using capitals in package names is a bad idea (some google services won't work for you)
    – Amir Uval
    Jul 19, 2012 at 15:16
  • 5
    Sorry, man. After seeing your answer I took a closer look, and my browser connected the i with its dot, making it look like a capital I. How embarrassing :S
    – Amir Uval
    Jul 29, 2012 at 21:06
  • 7
    @androiddeveloper - All alphanumeric characters, '.' and '_' is allowed. However, a package name (or a "sub-package" name for that matter, like "reader" in com.adobe.reader) cannot begin with a number, or cannot be a java reserved keyword (like "for" or "while"). To combat these restrictions, you would start the package name with a leading '_' so 3.cookies.for.you.com would translate to com.you._for.cookies._3). See the relevant Oracle documentation for details.
    – Jimmy Huch
    Sep 9, 2015 at 20:29
  • 1
    Would "com.appname" be a valid package name in android? Nov 15, 2016 at 9:52
77

The package name is used for unique identification for your application.
Android uses the package name to determine if the application has been installed or not.
The general naming is:

com.companyname.applicationname

e.g.:

com.companyxyz.camera (All lowercase no underscore according to the Kotlin style guide.)

This Kotlin style guide reference specifically addresses casing (all lowercase) and to not have any underscores.

Package names are all lowercase, with consecutive words simply concatenated together (no underscores).

Examples to avoid:

com.companyxyz.Camera ( Avoid this, in Java this is a convention that commonly would denote a Class or Interface and this also does not follow Kotlin style guidance.

com.company_xyz.camera_app (Avoid this too. In Java this would be done for namespace collision reduction when the url or app name contains a special, i.e., non-alphanumeric, character.)

Personal Observation: no guidance specifically for package names in the Kotlin style guide regarding the accepted practice of using domain names in reverse order to avoid name collisions was present on re-review, but that convention appears to be widely adopted following the same convention guidelines in the oracle documentation. This is a widely accepted practice. e.g., com.google.abc or com.microsoft.cortana except for the use of underscores. This is possibly a karmic punishment for getting tricksy with a name...

Further references/reading: Kotlin style guide for Android package naming ( https://developer.android.com/kotlin/style-guide#package_names )

Jaca/Oracle Package Name guidance (https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html )

There are many stack overflow articles dedicated to this topic as well and I will leave that a search exercise for the reader to undertake.

2
  • 5
    com can vary, if the domain name of the company/organisation is different. ie. org.wikipedia.wikipediaapp Jan 15, 2015 at 12:24
  • 15
    what if someone took my website name as a package name for his Android app? Can I take down this app from the store? Jul 1, 2016 at 20:37
48

http://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html

Companies use their reversed Internet domain name to begin their package names—for example, com.example.mypackage for a package named mypackage created by a programmer at example.com.

Name collisions that occur within a single company need to be handled by convention within that company, perhaps by including the region or the project name after the company name (for example, com.example.region.mypackage).

If you have a company domain www.example.com

Then you should use:

com.example.region.projectname

If you own a domain name like example.co.uk than it should be:

uk.co.example.region.projectname

If you do not own a domain, you should then use your email address:

for [email protected] it should be:

com.example.name.region.projectname

6
  • can you please explain why should I use it? what benefits do I get using my company domain name as a packagename ?
    – Emil
    Nov 6, 2017 at 17:10
  • Please see this StackOverflow question as an example: stackoverflow.com/questions/8381324/…
    – JCasso
    Nov 6, 2017 at 21:23
  • ok i understand this to keep package name unique but my question is when we upload to google play. doesnt google play ensure that package name is unique in the store before it goes online? so if we only install from google play, we shouldnt have this conflict
    – Emil
    Nov 6, 2017 at 22:39
  • Google play ensures that application ids are unique. It does not scan the packages for conflicts. So it is possible that two intents/services having the same canonical name if developers do not follow this naming convention. Please see: developer.android.com/studio/build/application-id.html
    – JCasso
    Nov 7, 2017 at 21:47
  • What happens if you change your domain name? Also, the suggestion for e-mail seems a bit dangerous - what if my e-mail were [email protected] and Microsoft wanted to create a foo package for Outlook? Both would be at com.outlook.foo, right?
    – HappyDog
    May 22, 2020 at 9:50
11
com = commercial application (just like .com, most people register their app as a com app)
First level = always the publishing entity's' name
Second level (optional) = sub-division, group, or project name
Final level = product name

For example the android launcher (home screen) is com.google.android.launcher

0
5

From the Kotlin Android style guide:

Package names are all lowercase, with consecutive words simply concatenated together (no underscores).

https://developer.android.com/kotlin/style-guide#package_names

3

Generally the first 2 package "words" are your web address in reverse. (You'd have 3 here as convention, if you had a subdomain.)

So something stackoverflow produces would likely be in package com.stackoverflow.whatever.customname

something asp.net produces might be called net.asp.whatever.customname.omg.srsly

something from mysubdomain.toplevel.com would be com.toplevel.mysubdomain.whatever

Beyond that simple convention, the sky's the limit. This is an old linux convention for something that I cannot recall exactly...

4
  • Thanks for the suggestion. But, is there any reference from the official Android site? Jun 8, 2011 at 3:42
  • The closest thing I could find was a blurb here: developer.android.com/guide/topics/manifest/… But if you take everything that exists as package libraries, you'll see they always follow the same convention. http is from org.apache.http, Andengine is org.anddev.andengine, etc etc.
    – Eric
    Jun 8, 2011 at 3:47
  • 1
    What are the rules about which characters are allowed for the package name on Android ? is it just English letters, the "." and the "_" characters that are allowed? Jul 25, 2015 at 20:39
  • Thanks everybody for helpful comments. I'm facing with related problem: my package spectorsky in the application calendar is reffered in Device File Explorer as com.tmp.spectorsky.calendar. I cannot understand why does tmp level appear here?
    – Spectorsky
    Apr 12, 2020 at 11:13
0

But if your Android App is only for personal purpose or created by you alone, you can use:

me.app_name.app
9
  • 15
    You can say, that the statement made is purely you'r opinion :) Nov 5, 2014 at 12:30
  • 2
    @batmaci I believe this has been downvoted because it misguides people into using arbitrary package names. Even though this may technically be possible and Google does not verify if the domain is yours, it would lead to namespace pollution and should therefore considered bad practice. Nov 5, 2018 at 18:32
  • 3
    @OliverHausler what do you mean by namespace pollution? where and how? why does this so much matter? i only know that if you have a website and you want to do deeplinking to your app, it makes things easier but even without you can still easily deeplink. above answers none of them explains why but they just repeat what google told them.
    – Emil
    Nov 6, 2018 at 13:32
  • 1
    @batmaci Imagine this situation: Dev X creates app (with a not creative name) and in it "me.app_name.services.MyService". Dev Y, who happens to have the same nickname as dev X (sisisisi was taken from me in multiple places for example), creates an app, name also not creative, same as Dev X-s app name. Dev Y creates a "me.app_name.services.MyService" for his app. User installs both apps, one of them tries to start its service by name - which service is started? Seems unlikely, but consider the number of android apps out there. Using your email in the package name eliminates this possibility.
    – sisisisi
    Nov 7, 2018 at 12:26
  • 1
    Also, .me is a valid top-level domain, and therefore a developer who has registered app_name.me would collide with your personal namespace.
    – HappyDog
    May 22, 2020 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.