Similarities and differences between applicationId and packageName

About the author: CSDN content partner and technical expert, built an APP with tens of millions of daily users from scratch , and led the advertising team to generate over ten million in daily advertising revenue.
Focus on sharing original series of articles in various fields, specializing in java backend, mobile development, commercialization, artificial intelligence, etc. I hope you will support me a lot.

Insert image description here

1. Introduction

We continue to summarize and learn basic knowledge , review the past and learn new things.

Today we record the similarities and differences of applicationId & packageName.

2. Overview

When you create a new project in Android Studio, the applicationId is exactly the same as the Java-style package name selected when creating it.
Other than that, though, the app ID and package name have nothing to do with each other. You can change the package name (code namespace) of your code and this will not affect the app ID and vice versa (but again, the app ID must not be changed after publishing your app)

  • Application id and package name have clear division of labor
    • application id is responsible for the process ID of the App
    • package name is responsible for the package name of R and the relative package names of the four major components such as Activity in Manifest.

If applicationId is not specified in build.gradle, the default value of application id is the package attribute value of manifest.

Although application IDs look just like traditional Java package names, the naming rules for application IDs are more restrictive:

  • Must contain at least two paragraphs (one or more dots).
  • Each paragraph must begin with a letter.
  • All characters must be alphanumeric or underscore [a-zA-Z0-9_].

2.1 Change package name

By default, the project's package name matches the app ID. If you want to change the package name, it is important to note that the package name (defined by the project directory structure) should always match the package attribute in the AndroidManifest.xml file. As follows:

<?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" >

The Android build tools use the package attribute to serve two purposes:

  • It uses this name as the namespace for the R.java classes generated by the application.
  • It will use this name to resolve any relevant class names declared in the manifest file.

3. Recommended reading

Java column

SQL Column

Data Structures and Algorithms

Android learning column

ddd

Guess you like

Origin blog.csdn.net/fumeidonga/article/details/132939572