Steps to Change Package Name in Android Studio Project

0
358

Changing the package name in an Android Studio project involves several steps. Follow this guide carefully to ensure everything updates correctly.

Step 1: Open Project in Android Studio

  • Launch Android Studio and open your project.

Step 2: Change Package Name in AndroidManifest.xml

  1. Open AndroidManifest.xml (found in app/src/main/AndroidManifest.xml).

  2. Locate the package attribute at the top.

  3. Change it to your desired package name.

    Example:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.newpackage.name">
    

Step 3: Change Package Name in the Java/Kotlin Folder

  1. In the Project view, switch to Android mode.
  2. Expand app > java.
  3. Right-click your existing package name and select Refactor > Rename.
  4. Choose Rename Package.
  5. Enter the new package name and click Refactor.
  6. Android Studio will update occurrences of the package name in your code.
  7. Click Do Refactor to confirm.

Step 4: Update build.gradle (Module: app)

  1. Open app/build.gradle.

  2. Locate applicationId inside defaultConfig.

  3. Update it to the new package name.

    Example:

    defaultConfig {
        applicationId "com.newpackage.name"
    }
    
  4. Click Sync Now when prompted.


Step 5: Update google-services.json (if using Firebase)

  • If your project is connected to Firebase, download a new google-services.json file with the updated package name from the Firebase Console.
  • Replace the old google-services.json file in app/.

Step 6: Clean and Rebuild the Project

  1. Go to Build > Clean Project.
  2. Then go to Build > Rebuild Project.

Step 7: Invalidate Cache and Restart

  • Click File > Invalidate Caches / Restart.
  • Choose Invalidate and Restart.

Verifying the Changes

  • Run the app to ensure it works correctly.
  • If you encounter errors, check the log and update any missed occurrences of the old package name.