Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package name alias or nickname

Is it possible to create a nickname for a package name, that I can refer in xml file?

I don't want to write the whole package name e.g. com.example.go.deck.today instead can I create an alias and refer that alias?

I'd like to refer an alias or nick instead of the package name in an android/layout XML file.

like image 458
Yauraw Gadav Avatar asked Aug 31 '12 11:08

Yauraw Gadav


People also ask

Is a nickname an alias?

Alias derives from the term “alias dictus,” which means “otherwise called.” An alias is a pseudonym, nickname, or alternative name for an individual (alternative to their legal name). The expression “John Doe, alias” or “John Doe alias” means an unknown person.

How do you name a package?

Naming ConventionsPackage names are written in all lower case to avoid conflict with the names of classes or interfaces. 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 .

Can package name be same as class name?

Yes, it will work.


2 Answers

No, sorry, this is not possible, at least not directly within the Android toolset.

like image 159
CommonsWare Avatar answered Oct 23 '22 17:10

CommonsWare


Android by itself does not provide such facility. However you can use the ant to do it for you. You could write a custom build.xml, customizing the target <target name="-code-gen"> to do token replacement before the R class is generated. You could add the rule :

<replace file="targetFile" token="@PACKAGE_ALIAS@" value="com.example.go.deck.today"/> 

this would replace every occurrence of @PACKAGE_ALIAS@ by com.example.go.deck.today in the targetFile.

I am not an ant specialist but based on past experience I would say that it would not be hard to write a rule that could scan all file in the res dir.

like image 45
André Oriani Avatar answered Oct 23 '22 16:10

André Oriani