noun explanation
- Package properties: In the Androidmanifest.xml file.
- Package Name: The application's bundle name.
- Application ID: The ApplicationID property under the module Defaultconfig block.
Set Application ID
Each Android application has a unique application ID like the Java package name, such as Com.example.myapp. On Android devices and Google Store, the application ID is your app's unique identity. If you want to upload a new version of the application, the application ID must be the same as the original. If you change the application ID of the new version of the application, then the Goolge store will consider it a completely different application. So, never change the application IDfrom the first time you upload the app.
The application ID is defined in the ApplicationID property of the module Build.gradle, as follows:
android { defaultConfig { "com.example.myapp" 15 24 1 "1.0" } ...}
When you create a new project in Android Studio, you can set the ApplicationID property, at which point the Application ID and package name are exactly matched. In addition, the two are completely independent. Of course, you can change the package name, but this does not affect the application ID. and vice versa (again: After you upload the application, do not modify the application ID, do not modify the application ID, do not modify the application ID). However, you should be aware that there is another consequence of modifying the package name. This section is described in modifying the package name (below).
Although the application ID looks similar to the traditional Java package name, there are more restrictions on the naming conventions for application IDs:
- A minimum of two segments (at least one. Separate)
- Each paragraph must begin with a letter
- All characters can only be letters, numbers, and underscores
Note: Previously, the application ID was directly bound to the package name. Therefore, some Android APIs use "package name" in either the method name or the parameter name, but actually refer to the application ID. Give me a chestnut Context.getPackageName()
. method returns the application ID. So there's no need to share the real package name outside of your application code.
Warning: If you use WebView, consider using your package name as the prefix for your application ID, otherwise you may meet
Issue 211768.
Modify the application ID of the build version
When building an APK for your application, the build tool identifies the APK (as shown below) using the application ID defined in the Defaultconfig block in the Build.gradle file. However, if you want to create different versions of the application and display different information in the Google Store, such as "Free Edition" and "Professional Edition". You need to build different versions that have the same application ID.
In this case, each build should define a different product flavor, and each flavor within the productflavors{} block. For each flavor, you can redefine the ApplicationID property, or add a prefix to the default ApplicationID, as follows:
android { defaultConfig { "com.example.myapp" } productFlavors { free { ".free" } pro { ".pro" } }}
After this definition, the application ID for "free" is "Com.example.myapp.free".
On the build type, you can also use the suffix as follows:
android { ... buildTypes { debug { ".debug" } }}
The "Free Debug" version now has a application ID of "Com.example.myapp.free.debug" because Gradle applies the build type first after the product flavor is applied. This is useful if you want to install both debug and release two versions on the same phone, because no two applications can have the same application ID.
Remember that the same application has a different application Id,google app market that will be considered as two applications. So, if you want to adapt different device configurations (for example, different API levels) and would like to use the same information to distribute multiple applications. Then for each version, you must use the same application ID and different versioncode.
Warning: To be compatible with the previous SDK tools, if you do not define the ApplicationID attribute in Build.gradle, the build tool will use the package name in Androidmanifest.xml as the application ID. In this case, renaming the package name means renaming the application ID at the same time.
Tip: If you need to reference the application ID in the manifest file, you can use the ${applicationid} placeholder in the properties of manifest. Gradle will replace this identity as the true application ID at build time. See Inject Build Variables into the Manifest for more details.
Test Private Application ID
By default, the build tool applies the application ID to your instrumentation test APK using the application ID (attached. test) of the specified build. For example, a test application that builds a version of "Com.example.myapp.free" the Real Application ID is "Com.example.myapp.free.test".
Usually this is not necessary, you can define the Testapplicationid property in the Defaultconfig or Productflavor block to modify the application ID.
Note: To avoid naming conflicts with test applications, the build tool uses a test application ID to generate R.class namespaces for test applications.
Modify Package Name
Although the package name does match the application ID by default, you can still modify it. If you want to modify the package name, please note that the package name (project directory structure) and the package attribute in Androidmanifest.xml are fully corresponding. As shown below:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp" android:versionCode="1" android:versionName="1.0" >
For Android build tools, the package attribute is used for two things:
The namespace that is applied to your application to generate the R.java class.
For example: In the manifest file above. The R class is "COM.EXAMPLE.MYAPP.R"
The relative path used to parse any class in the Androidmanifest.xml file.
For example: In the manifest file above. An activity is defined as \ and will be parsed as com.example.myapp.MainActivity.
Therefore, the value of the package property should always be the same as the project's package name. Of course, you can set the child package name for the project. These files must be imported into the R class from the namespace of the package property, and any components defined in manifest must add the child package name (or write the full path).
If you need to completely rename the package name, make sure that you have updated the package properties. Until you rename the package with the tools of Android studio, these are automatically kept in sync. (If you do not keep syncing, your code will not parse the R class correctly because it is no longer under the same package, and manifest will not correctly recognize your activities and other components).
You must pin the package property in the Androidmanifest.xml file, and if you add an additional manifest file, be aware that the package name provided by the highest priority manifest file is always used to merge the final manifest. MORE: [Merge multiple Manifest Files.
Hope to be known: Although your project can set the package property is not equal to ApplicationID, and then egg. The build tool will replicate the application ID and set the value of the package property unique to your application when it is last built. So, if you check the Androidmanifest.xml file after the build is successful, don't be surprised that the package property has changed. On the Android platform and Google Store, the package attribute is the only credential that is truly your application. So, once built with primitive values (using the namespace's R class to resolve components in manifest), the build tool discards the value of the package property and replaces it with the application ID.
Original link: https://developer.android.com/studio/build/application-id.html#change_the_package_name
Links and differences between Android package properties, package name and application ID