简体   繁体   English

Android应用包名称

[英]Android app package name

When creating an Android application using Java, you place your classes into packages such as com.example.appName 使用Java创建Android应用程序时,可以将类放入com.example.appName等包中

However, in the Android XML manifest file, you also specify the package there. 但是,在Android XML清单文件中,您还可以在那里指定包。

It is my understanding that the Google Play Store, where Android apps are uploaded, uses the package name as a unique identifier for your app. 我的理解是,上传Android应用的Google Play商店使用套餐名称作为应用的唯一标识符。

So, which package name actually identifies your app/APK file? 那么,哪个包名实际上标识了您的app / APK文件? And can the package names in your code be different to the package name in the manifest? 您的代码中的包名称是否可以与清单中的包名称不同?

Only the package name in AndroidManifest.xml counts and must not change. 只有AndroidManifest.xml的包名称AndroidManifest.xml重要,不得更改。 The package you put your Java classes in can be anything. 您放入Java类的包可以是任何东西。

The Play store picks up the package as the identifier from the manifest file . Play商店从清单文件中选取包作为标识符

It really doesn't matter if your source files go into the same package or something else. 如果您的源文件进入相同的包或其他内容,这无关紧要。

So, you can manage/arrange your source files into any arbitrary packages you want. 因此,您可以将源文件管理/排列到任何所需的任意包中。

Generally, it's easier to have your source files in the same package/sub-package as your manifest file, so that referencing them from the manifest file is easier, as you will not have to specify the fully qualified class names for your activities/services etc. 一般情况下, 它更容易在同一个包/子包的源文件的清单文件,以便从清单文件中引用它们更容易,因为你不必为你的活动/服务全限定类名等等

which package name actually identifies your app/APK file?

play store will take only Android manifest package. Play商店只会采用Android清单包。 like package="com.example.appName" package="com.example.appName"

 can the package names in your code be different to the package name in the manifest?

yes, you can use different package for your code but need to give the absolute package name when declaring in manifest.xml 是的,您可以为您的代码使用不同的包,但在manifest.xml中声明时需要提供绝对包名

android:name="org.demo.MyFile"

Android XML manifest file package is understanding by the Google Play Store because Google Play Store only read this file , when you upload android application in google play store. Android XML清单文件包是由Google Play商店理解的,因为当您在Google Play商店中上传Android应用程序时,Google Play商店只会读取此文件。

so, if you src package and manifest is different then it do not make any problem. 所以,如果你的src包和manifest不同,那么它就没有任何问题。

Thanks 谢谢

I just want to add couple more observation: * the field package from AndroidManifest is also used for package of generated classes (eg R class) * and something important if you are using google map v2 in your project pay attention of the package used in authorization because need to be the same. 我只是想补充几点观察:*来自AndroidManifest的字段包也用于生成类的包(例如R类)*以及在项目中使用google map v2时重要的事项注意授权中使用的包因为需要是一样的。 if you don't do that it will just not fetch the map but with no error message in logcat. 如果你不这样做,它将不会获取地图但在logcat中没有错误消息。 (just hit this issue today and yesterday) (今天和昨天刚刚发过这个问题)

googlemap v2 version 8.1.1 google play services 4.4.52 googlemap v2版本8.1.1 google play services 4.4.52

The answers here seem a little out from my experience. 这里的答案似乎与我的经历有点不同。

In Android Studio the applicationId in your Build.Gradle is the important attribute and should not change. 在Android Studio中,Build.Gradle中的applicationId是重要属性,不应更改。

Our Manifest package name was different from our applicationId, I changed them to be the same and was able to upload the APK to Google Play without error. 我们的Manifest软件包名称与我们的applicationId不同,我将它们更改为相同,并且能够毫无错误地将APK上传到Google Play。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM