当开发名称以数字开头时 Android studio 中的包名称?
Package names in Android studio when dev name starts with a number?
我想以我公司的名义创建应用,Android Studio 建议使用您的域,例如:
域:example.com
应用:我的应用
给出包名com.example.myApp
没关系,但我的公司名称以数字开头,Android Studio 告诉我不能有数字,例如:
com.1example.myApp
现在我可以尝试 "oneexample" 并且希望 example.com 中没有人开始开发 Android 应用程序,但是考虑到有多少开发者在他们的开始时似乎有一个数字名字,想必这是以前出现过的。所以如果我可以请问:
1) 我应该如何命名我的包?
2) 出于好奇,为什么包名不能以数字开头?
非常感谢!
昆汀.
1) How should I tackle naming my packages?
简答: Android package/subpackage 名称必须以 ASCII 拉丁字母开头。由于 Google 在域名以数字开头的情况下似乎没有关于包命名的指导,开发人员只能自己解决这个问题。
以下是一些以数字开头的域名的真实示例,以及开发人员决定用于 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
更多背景知识
Java 允许包名称以 ASCII 拉丁字母或下划线字符开头。来自 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.
还显示了以下 "Legalizing Package Names" 的示例:
Domain Name Package Name Prefix
--------------------------- ---------------------------
hyphenated-name.example.org org.example.hyphenated_name
example.int int_.example
123name.example.com com.example._123name
但是,Android 比 Java 更严格,并且 package/subpackage 名称不能以下划线开头 。来自 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.
不幸的是,Google 似乎没有任何关于使以 Android.
的数字开头的域的包名称合法化的建议约定
2) Out of curiosity, why can't you have package names beginning with a number?
来自 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.
<截图>
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.
同样,这在 Android 包名称中受到进一步限制。来自 <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.
感谢@Quentin 提供有关 Android 相对于 Java 的附加限制的信息。
我想以我公司的名义创建应用,Android Studio 建议使用您的域,例如:
域:example.com
应用:我的应用
给出包名com.example.myApp
没关系,但我的公司名称以数字开头,Android Studio 告诉我不能有数字,例如:
com.1example.myApp
现在我可以尝试 "oneexample" 并且希望 example.com 中没有人开始开发 Android 应用程序,但是考虑到有多少开发者在他们的开始时似乎有一个数字名字,想必这是以前出现过的。所以如果我可以请问:
1) 我应该如何命名我的包?
2) 出于好奇,为什么包名不能以数字开头?
非常感谢!
昆汀.
1) How should I tackle naming my packages?
简答: Android package/subpackage 名称必须以 ASCII 拉丁字母开头。由于 Google 在域名以数字开头的情况下似乎没有关于包命名的指导,开发人员只能自己解决这个问题。
以下是一些以数字开头的域名的真实示例,以及开发人员决定用于 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
更多背景知识
Java 允许包名称以 ASCII 拉丁字母或下划线字符开头。来自 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.
还显示了以下 "Legalizing Package Names" 的示例:
Domain Name Package Name Prefix
--------------------------- ---------------------------
hyphenated-name.example.org org.example.hyphenated_name
example.int int_.example
123name.example.com com.example._123name
但是,Android 比 Java 更严格,并且 package/subpackage 名称不能以下划线开头 。来自 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.
不幸的是,Google 似乎没有任何关于使以 Android.
的数字开头的域的包名称合法化的建议约定2) Out of curiosity, why can't you have package names beginning with a number?
来自 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.
<截图>
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.
同样,这在 Android 包名称中受到进一步限制。来自 <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.
感谢@Quentin 提供有关 Android 相对于 Java 的附加限制的信息。