在Android的工作室包名称时dev名称以数字开头? [英] Package names in Android studio when dev name starts with a number?

查看:534
本文介绍了在Android的工作室包名称时dev名称以数字开头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建立在我公司的名称的应用程序和Android工作室建议使用您的域名,例如:

域:example.com

应用:对myApp

给com.example.myApp的包名

这一切都很好,但我的公司名称以数字开头和Android工作室告诉我,我不能有一个数字,例如:

com.1example.myApp

现在我可以尝试oneexample,希望没有人从oneexample.com开始开发Android应用程序,但考虑到有多少开发者似乎有一些在他们的名字开始,presumably这已经到来之前。所以,如果我可以请咨询:

1)我应该怎样处理我命名的包?

2)出于好奇,你为什么不能有包名开头的一个号码是多少?

感谢堆!

昆汀。


解决方案

  

1)我应该如何命名钓具我的包裹?


答案很简单: Android包/子包名称必须以ASCII拉丁文字母开头。由于人们似乎从谷歌在情况下,域名以数字开头的包命名任何指导,开发商都留给这个自行解决。

下面是域名开始与一些真实世界的例子,并且包名开发人员决定使用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拉丁文字母或下划线。从命名一个包(Java的贸易;教程>学习Java语言和GT;包)


  

在某些情况下,互联网域名可能不是一个有效的软件包名称。如果域名包含连字符或其他特殊字符,就会发生这种情况的如果包名以数字开头或其它字符是非法的,作为一个Java名称的开始使用,或者如果包名称中包含Java的保留关键字,如INT。在这种情况下,建议的惯例是增加一个下划线。


法治化包名称的以下的实施例也示:

 域名套餐名称preFIX
--------------------------- ----------------------- ----
hyphenated-name.example.org org.example.hyphenated_name
example.int int_.example
123name.example.com com.example._123name

不过,Android比Java更严格,而包/子包名称不能以下划线开始的。从发行65570 - Android开源项目 - 事件跟踪 - 谷歌工程托管


  

而Java允许用下划线开始包名,Android应用程序包(有额外的限制)没有。当您尝试安装一个应用程序,其包_开始,设备软件包管理系统将拒绝它。出于这个原因,当您创建的应用程序,这样你最终不会在前面创建这些包,然后后来我们的痛苦在收紧Studio中的包名验证。


不幸的是,似乎没有是来自谷歌的任何建议公约合法化包名称为以数字为Android开始的域。


  

2)出于好奇,你为什么不能也开始与一些包名?


第3章词法结构(为Java®语言规范 - 的Java SE 7版):


  

标识符是Java的字母和Java数字无限长度序列,的其中第一个必须是一个Java函即可。


<&剪断GT;


  

通过Java字母包括大写和小写的 ASCII拉丁字母 AZ(\\ u0041- \\ u005a)和AZ(\\ u0061- \\ u007a),而且,由于历史的原因, ASCII码下划线(_或\\ u005f)和美元符号($或\\ u0024)。 $字符只能在机械生成的源$ C ​​$ C使用或很少,对遗留系统访问pre-现有名称。


再次,这是进一步在Android包名称的限制。从<&舱单GT; | Android开发者


  


   应用程序的完整的Java语言风格的包名。该名称应该是唯一的。该名称可以包含大写或小写字母(A到Z),数字和下划线(_)。然而,个人包名称部分只能用字母开始。


谢谢,@Quentin,用于对Java提供有关Android的附加限制信息。

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.

这篇关于在Android的工作室包名称时dev名称以数字开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆