245

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)

user
  • 5,370
  • 8
  • 47
  • 75
Charles Yeung
  • 38,347
  • 30
  • 90
  • 130

7 Answers7

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

Jimmy Huch
  • 4,400
  • 7
  • 29
  • 34
  • Thanks for the suggestion. But, is there any reference from the official Android site? – Charles Yeung Jun 08 '11 at 03:41
  • 2
    here's a (brief) reference from Android site - have a look "Package Name" paragraph at http://developer.android.com/resources/tutorials/hello-world.html – Bojan Komazec Oct 16 '11 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 '12 at 15:16
  • @uval Yes I know that capitals in packages are not allowed. I don't think I made a mistake in the answer as I didn't use a capital in any of the package names :S – Jimmy Huch Jul 29 '12 at 18:23
  • 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 '12 at 21:06
  • It is important to note that the first part is the TLD of the company. Other valid package names could be `de.mysoft.fractions` (from the linked wikipedia example) or `org.wikipedia.wikipediaapp`, for the "de" and "org" TLDs, respectively. – Niels Abildgaard Jan 15 '15 at 12:26
  • 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? – android developer Apr 02 '15 at 22:32
  • 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](http://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html) for details. – Jimmy Huch Sep 09 '15 at 20:29
  • 1
    Would "com.appname" be a valid package name in android? – Mark Buikema Nov 15 '16 at 09:52
  • Is there any strict rule that provides a way to validate it? – Mohammad Kermani Oct 10 '17 at 12:51
  • there is no restriction in package name you can call it whatever you want. my package names currently dont have "com." in it but accepted by google without any problem. – Emil Nov 06 '17 at 17:07
  • Do you foresee any issues having a 2 part package name? For instance, **app.coinverse** as my company is the app name. – AdamHurwitz Sep 28 '18 at 04:37
  • 1
    @AdamHurwitz you will not have any issue at all. it has even almost no usage but for some deeplinking purpose reverse url pattern is useful they say although, you can have deeplinking working without this as well – Emil Nov 06 '18 at 12:31
76

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.

Hunter-Orionnoir
  • 2,015
  • 1
  • 18
  • 23
ameyume
  • 2,370
  • 1
  • 14
  • 9
46

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 name@example.com it should be:

com.example.name.region.projectname

JCasso
  • 5,423
  • 2
  • 28
  • 42
  • can you please explain why should I use it? what benefits do I get using my company domain name as a packagename ? – Emil Nov 06 '17 at 17:10
  • Please see this StackOverflow question as an example: https://stackoverflow.com/questions/8381324/two-service-with-the-same-intent-filter – JCasso Nov 06 '17 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 06 '17 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: https://developer.android.com/studio/build/application-id.html – JCasso Nov 07 '17 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 foo@outlook.com and Microsoft wanted to create a foo package for Outlook? Both would be at com.outlook.foo, right? – HappyDog May 22 '20 at 09:50
  • What are you supposed to do if your domain name starts with a number (or contains only numbers)? It won't let me create the package name: "a digit cannot be the first character in a package segment" – Michael Sep 24 '22 at 18:14
9
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

zapotec
  • 2,628
  • 4
  • 31
  • 53
charles
  • 115
  • 1
  • 1
4

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

miguel
  • 16,205
  • 4
  • 53
  • 64
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...

Eric
  • 1,953
  • 4
  • 24
  • 33
  • Thanks for the suggestion. But, is there any reference from the official Android site? – Charles Yeung Jun 08 '11 at 03:42
  • The closest thing I could find was a blurb here: http://developer.android.com/guide/topics/manifest/manifest-element.html 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 08 '11 at 03: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? – android developer Jul 25 '15 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 '20 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
ajdeguzman
  • 1,223
  • 3
  • 16
  • 27
  • 14
    You can say, that the statement made is purely you'r opinion :) – Rahul Reddy Nov 05 '14 at 12:30
  • @RahulReddy why is that downvoted, I dont understand. google doesnt restrict anybody to use com. or org.! you can use whatever you want as a packagename – Emil Nov 06 '17 at 17:09
  • 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. – Oliver Hausler Nov 05 '18 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 06 '18 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 07 '18 at 12:26
  • @sisisisi thats not posisble. Google verifies uniqueness when you upload a new package to the play store. if there is already an existing package name with "me.app_name.services.MyService", Google wont allow you to upload it. Also it wont be possible on your android device even without Google playstore. it is not allowed to install 2 apps with the same package name. – Emil Nov 07 '18 at 14:23
  • @batmaci Google verifies uniqueness and probably have their reasons why they don't verify domain ownership [I can think of quite a few]. Notwithstanding, recommendations should be followed to prevent use of somebody else's domain. If you would use one of my domains, I would ask Google to shut you down. Probably not what you want. – Oliver Hausler Nov 28 '18 at 02:58
  • @OliverHausler the day you uploaded your app, if it is written in the googles policy, yes you can but if not, not possible to shut you down. because domains might change the owner as well. if you find this policy, please let me know. i have never seen it. – Emil Nov 28 '18 at 11:05
  • 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 '20 at 09:54