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)
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
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
eg:
com.android.Camera
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
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
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...
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
But if your Android App is only for personal purpose or created by you alone, you can use:
me.app_name.app
Related
The naming convention is usually company.domain.inreverse.appname
Is there a significance of using the actual company domain
Asking because I by mistake named the package com.companyName.app.appName instead of in.co.companyName.app.appName (where the company's actual internet domain is companyName.co.in)
So would it in any way affect my app, and/or its relation to the website?
No.. it won't. The idea is to give Global uniqueness.
check this page: https://en.wikipedia.org/wiki/Java_package#Package_naming_conventions
The Java Language Specification establishes package naming conventions to avoid the possibility of two published packages having the same name.
But keep in mind this: http://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html
Package names are written in all lower case to avoid conflict with the names of classes or interfaces.
I want to create apps under my company's name and Android Studio recommends using your domain, eg:
domain: example.com
App: myApp
gives a package name of com.example.myApp
That's all fine, but my company name begins with a number and Android Studio informs me I can't have numbers, eg:
com.1example.myApp
Now I could try "oneexample" and hopefully no-one from oneexample.com starts developing Android apps, but given how many devs appear to have a number at the start of their name, presumably this has come up before. So if I can please ask:
1) How should I tackle naming my packages?
2) Out of curiosity, why can't you have package names beginning with a number?
Thanks heaps!
Quentin.
1) How should I tackle naming my packages?
Short Answer: Android package/subpackage names must begin with an ASCII Latin letter. Since there seems to be no guidance from Google on package naming in cases where domain names begin with a number, developers are left to resolve this themselves.
Here are some real-world examples of domain names starting with a number, and the package names the developers decided to use for Android:
http://www.11bitstudios.com/
https://play.google.com/store/apps/details?id=com.elevenbitstudios.AnomalyWarzoneEarthHD
http://www.23snaps.com/
https://play.google.com/store/apps/details?id=com.snaps23.android
http://www.36you.com/
https://play.google.com/store/apps/details?id=com.thirtysixyougames.google.slotanddragons
Further Background
Java allows package names to begin with an ASCII Latin letter or an underscore character. From Naming a Package (The Java™ Tutorials > Learning the Java Language > Packages):
In some cases, the internet domain name may not be a valid package name. This can occur if the domain name contains a hyphen or other special character, if the package name begins with a digit or other character that is illegal to use as the beginning of a Java name, or if the package name contains a reserved Java keyword, such as "int". In this event, the suggested convention is to add an underscore.
The following examples of "Legalizing Package Names" are also shown:
Domain Name Package Name Prefix
--------------------------- ---------------------------
hyphenated-name.example.org org.example.hyphenated_name
example.int int_.example
123name.example.com com.example._123name
However, Android is more restrictive than Java, and package/subpackage names may NOT begin with an underscore. From Issue 65570 - Android Open Source Project - Issue Tracker - Google Project Hosting:
While Java allows package names that start with underscores, Android application packages (which have additional restrictions) do not. When you try to install an app whose package starts with _, the device PackageManager will reject it. For that reason we tightened the package name validation in Studio when you create the app such that you don't end up creating these packages up front and then suffering later.
Unfortunately, there doesn't seem to be any suggested convention from Google on legalizing package names for domains that begin with a number for Android.
2) Out of curiosity, why can't you have package names beginning with a number?
From Chapter 3. Lexical Structure (The Java® Language Specification - Java SE 7 Edition):
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.
<snip>
The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $ character should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems.
Again, this is further restricted in Android package names. From <manifest> | Android Developers:
package
A full Java-language-style package name for the application. The name should be unique. The name may contain uppercase or lowercase letters ('A' through 'Z'), numbers, and underscores ('_'). However, individual package name parts may only start with letters.
Thanks, #Quentin, for providing info on Android's additional restrictions over Java.
i have a problem in android application package installation,
why android must have two segment of package name,
why i can't use single Name as Package name.
Now:"com.alert.myalert"
Need:"myalert", in my application i required when my app is installed in device, it shows only my app name, when the user have to check in Settings->App->myalert. This is my problem, i can't get that now showing Settings->App->com.alert.myalert. kindly help me, Thanks in Advance.
You have an explanation about this here, it's just a convention to keep the names of your packages like the reverse of your domain.
From SUN Convention:
The prefix of a unique package name is always written in all-lowercase
ASCII letters and should be one of the top-level domain names,
currently com, edu, gov, mil, net, org, or one of the English
two-letter codes identifying countries as specified in ISO Standard
3166, 1981.
Subsequent components of the package name vary according to an
organization's own internal naming conventions. Such conventions might
specify that certain directory name components be division,
department, project, machine, or login names.
I'm thinking of taking the package name com.mangoapps.appname, but my question is, can someone else also use the prefix "com.mangoapps"?
Since I want to create a series of apps, I want a unique prefix "com.mangoapps".
And another question, how do I know if someone else is already using this package name as prefix?
Is there need of any relation between package name and developer's name?
There is no way to guarantee uniqueness. Anyone can do the same as you, that is just type in the name as packagename.
Things you can do to insure people wont do that, is to take (the reverse) of a domain you own. So if mangoapps.com is yours, there will probably be no one taking that packagename. And if you don't own the domain, you probably don't want to pick the name, as the owner might use it as default.
Because of this, there is also no way to know if someone uses that packagename. There might be a theoretical way to, for instance, check it for one place (e.g. some store, some collection of programs, etc), but I know of no such method for the play store.
There is no need for a relation between your name and the package name. The relation, if any, is with the name and a domain name, although it is not mandatory.
The package names should be based on a domain name that you control or have permission to use - that way ideally you have final say over which packages exist. What is your affiliation with mangoapps.com ?
note that in the real world none of this is enforced except by etiquette.
1) Yes, others can use the same prefix. Generally speaking, the prefix should be the reverse of your domain but it doesn't have to be, it can be anything. The prefix isn't visible to others so you could for example use com.SameerThigale if you don't have any other suitable domain to use.
2) They may already be doing so and there is no way to tell. However it doesn't really matter. All that needs to be unique (if you want to upload to the Play Store) is your prefix plus appname, i.e the complete package name. By choosing a prefix that relates in some way to you, you effectively eliminate the likelihood of conflicting with others.
3) There need be no relation between the package name and yourself. The package name is just a unique identifier for your application.
Sealing Packages within a JAR says
Packages within JAR files can be optionally sealed, which means that all classes defined in that package must be archived in the same JAR file.
So if your JAR is sealed and appears early on the CLASSPATH, then you can be sure that no other jars will be able to include classes in your package that have privileged access to package-private members.
Yes someone else can also use the prefix though the people won't do it in general as the name of their company is used after com prefix.
Its a part of url so you can always append to the url itself and search on google play
As I stated in the first point the developer/organization name is part of the package name itself.
i.e. com.mangoapps.appname
com -> company
mangoapps -> name of the company
appname -> name of the specific application that user will search on play store
Almost all android apps have links to 'developer's website'. Typically websites are used in assigning name spaces.
How can I assign unique package namespace if I don't have any website?
Or to put it other words, is website a parameter in assigning the namespace
If yes, can you please guide me how to get own site?
Dharma
The namespace is just that, a namespace. There is no need to create or own your own domain. You just need to be sure that your namespace is reasonable unique.
You dont need any website at all, package system is as the following:
If your package name is com.dharma.app then eclipse will generate a folder system like "src\com\dharma\app\". So, in the src(sources) folder, the outer folder will be com, 1 level deeper dharma, 1 level deeper app. Hope you understand it this way.
It's a good practice to name your packages following the java package naming convention. Following this article:
http://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html
This is recommended but not mandatory. i.e. you can just use an appropriate namespace without actually owning the domain.
You can use some other method of uniquely identifying your apps if you do not have a web domain name to use. Domain name is the recommmended way, but for example an email address or some other package name can be used as well depending on how important it is for you to distinguish your app as one made by a company.