Charles Yeung
Charles Yeung

Reputation: 38815

Android - Package Name convention

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)

Upvotes: 255

Views: 348757

Answers (7)

ameyume
ameyume

Reputation: 2460

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.

Upvotes: 82

charles
charles

Reputation: 155

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

Upvotes: 13

miguel
miguel

Reputation: 16600

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

Upvotes: 8

JCasso
JCasso

Reputation: 5523

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

Upvotes: 51

ajdeguzman
ajdeguzman

Reputation: 1209

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

me.app_name.app

Upvotes: -3

Jimmy Huch
Jimmy Huch

Reputation: 4550

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

Upvotes: 282

Eric
Eric

Reputation: 1973

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...

Upvotes: 3

Related Questions