简体   繁体   English

更改 package 名称与 applicationId 之间有什么区别

[英]What is the difference between changing package name vs applicationId

What is the difference between changing package name vs applicationId to the final apk.将 package name 与 applicationId 更改为最终 apk 之间有什么区别。

I know it is different for aspect of keeping source code, but lets say I got some app with package name abc.d.我知道在保留源代码方面有所不同,但可以说我得到了一些名称为 package abc.d 的应用程序。 What will be the difference in the builded apk file构建的apk文件会有什么不同

  1. if I rename the abc.d into qwer and then build the apk file如果我将 abc.d 重命名为 qwer 然后构建 apk 文件

vs对比

  1. change the applicationId into gradle with qwer使用 qwer 将 applicationId 更改为 gradle

The package name is just to organize your code. 包名称只是用于组织代码。

The applicationId , on the other hand, is used to identify your app in the Play Store. 另一方面, applicationId用于在Play商店中识别您的应用。 You will change this only if you plan to generate another app based on same code. 仅当您计划基于相同代码生成另一个应用时,才会更改此设置。

From docs ( https://developer.android.com/studio/build/application-id.html ): 来自docs( https://developer.android.com/studio/build/application-id.html ):

When you create a new project in Android Studio, the applicationId exactly matches the Java-style package name you chose during setup. 在Android Studio中创建新项目时,applicationId与您在安装过程中选择的Java样式包名称完全匹配。 However, the application ID and package name are independent of each other beyond this point. 但是,除此之外,应用程序ID和程序包名称彼此独立。 You can change your code's package name (your code namespace) and it will not affect the application ID, and vice versa (though, again, you should not change your application ID once you publish your app). 您可以更改代码的包名称(代码名称空间),它不会影响应用程序ID,反之亦然(但是,再次发布应用程序时不应更改应用程序ID)。 However, changing the package name has other consequences you should be aware of, so see the section about modifying the package name. 但是,更改程序包名称会产生其他后果,因此请参阅有关修改程序包名称的部分。

Some Android API like google map and firebase ask for your package name when you create the key.一些 Android API 像谷歌 map 和 firebase 在创建密钥时询问您的 package 名称。 That package name they refer to is actually your applicationId.他们引用的 package 名称实际上是您的 applicationId。 Yup Google insist on using the term package name for these API key.是的,谷歌坚持为这些 API 密钥使用术语 package 名称。 Don't get it confuse.不要混淆。

Taken from doc ( https://developer.android.com/studio/build/configure-app-module#set_the_application_id ):取自文档( https://developer.android.com/studio/build/configure-app-module#set_the_application_id ):

"Note: The application ID used to be directly tied to your code's package name; so some Android APIs use the term "package name" in their method names and parameter names, but this is actually your application ID. For example, the Context.getPackageName() method returns your application ID. There's no need to ever share your code's true package name outside your app code." “注意:应用程序 ID 曾经直接与您的代码的 package 名称相关联;因此某些 Android API 在其方法名称和参数名称中使用术语“包名称”,但这实际上是您的应用程序 ID。例如,Context。 getPackageName() 方法返回您的应用程序 ID。无需在您的应用程序代码之外共享您代码的真实名称 package。”

Once you upload the app on Play store you can't change the application id for that project , if you want to do then google play store consider as a different application. 在Play商店上传应用程序后,您无法更改该项目的应用程序ID,如果您愿意,那么google play store会将其视为不同的应用程序。

In case of package name you can change it as you want. 如果是包名,您可以根据需要进行更改。

Application id mostly used for: 应用程序ID主要用于:

  • Change the application ID for testing 更改应用程序ID以进行测试

  • Change the application ID for build variants 更改构建变体的应用程序ID

In this case, each build variant should be defined as a separate product flavor. 在这种情况下,每个构建变体应定义为单独的产品风格。 For each flavor inside the productFlavors {} block, you can redefine the applicationId property, or you can instead append a segment to the default application ID using applicationIdSuffix, as shown here: 对于productFlavors {}块中的每个flavor,您可以重新定义applicationId属性,或者您可以使用applicationIdSuffix将段附加到默认应用程序ID,如下所示:

Every Android app has a unique application ID that looks like a Java package name, such as com.example.myapp. 每个Android应用程序都有一个看似Java包名称的唯一应用程序ID,例如com.example.myapp。 This ID uniquely identifies your app on the device and in Google Play Store. 此ID可在设备和Google Play商店中唯一标识您的应用。 If you want to upload a new version of your app, the application ID (and the certificate you sign it with) must be the same as the original APK—if you change the application ID, Google Play Store treats the APK as a completely different app. 如果您要上传新版本的应用,则应用程序ID(以及您与之签名的证书)必须与原始APK相同 - 如果您更改了应用程序ID,Google Play商店会将APK视为完全不同的应用程序。 So once you publish your app, you should never change the application ID. 因此,一旦您发布应用程序,就不应该更改应用程序ID。

And package name is: 包名是:

Although your project's package name matches the application ID by default, you can change it. 虽然默认情况下项目的包名称与应用程序ID匹配,但您可以更改它。 However, if you want to change your package name, be aware that the package name (as defined by your project directory structure) should always match the package attribute in the AndroidManifest.xml file, as shown here: 但是,如果要更改包名称,请注意包名称(由项目目录结构定义)应始终与AndroidManifest.xml文件中的package属性匹配,如下所示:

The Android build tools use the package attribute for two things: Android构建工具使用package属性做两件事:

1- It applies this name as the namespace for your app's generated R.java class. 1-它将此名称应用为应用程序生成的R.java类的命名空间。

Example: With the above manifest, the R class will be com.example.myapp.R. 示例:使用上面的清单,R类将是com.example.myapp.R。

2- It uses it to resolve any relative class names that are declared in the manifest file. 2-它使用它来解析清单文件中声明的任何相对类名。

Example: With the above manifest, an activity declared as is resolved to be com.example.myapp.MainActivity. 示例:使用上面的清单,声明为的活动被解析为com.example.myapp.MainActivity。

Know more from Source Source了解更多

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

相关问题 Package 名称和应用程序 Package 名称有什么区别? - What is the difference between Package name & App Package Name? 更改 applicationId 还是包名称? - Change applicationId or also package name? What's the difference between dart:html vs package:html in dart? - What's the difference between dart:html vs package:html in dart? 更改gradle中的“ applicationId”时出错(未找到包名称“ my_new_app_id”的匹配客户端) - Getting error when changing “applicationId” in gradle (No matching client found for package name “my_new_app_id”) 清单文件中的包名称和Gradle中的应用程序ID之间有什么区别 - what is difference between Package name in Manifest file and Application ID in Gradle 为构建风格更改 package 名称(不仅是 applicationId) - Change package name (not only applicationId) for build flavor Android:产品风格,applicationId(程序包名称)和清单 - Android: product flavor, applicationId (package name) and manifest 重构程序包名称和重命名applicationID仍然使gradle失败 - Refactoring package name and renaming applicationID still gives gradle fail 项目中两个具有相同applicationId和包名称的Android模块 - Two Android modules with the same applicationId and package name in project 如何使用 JNI android 获取应用程序包名称或 applicationId - How to get app package name or applicationId using JNI android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM