1K Views
Steps to Change Package Name in Android Studio Project
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
-
Open
AndroidManifest.xml(found inapp/src/main/AndroidManifest.xml). -
Locate the
packageattribute at the top. -
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
- In the Project view, switch to Android mode.
- Expand
app > java. - Right-click your existing package name and select Refactor > Rename.
- Choose Rename Package.
- Enter the new package name and click Refactor.
- Android Studio will update occurrences of the package name in your code.
- Click Do Refactor to confirm.
Step 4: Update build.gradle (Module: app)
-
Open
app/build.gradle. -
Locate
applicationIdinsidedefaultConfig. -
Update it to the new package name.
Example:
defaultConfig { applicationId "com.newpackage.name" } -
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.jsonfile with the updated package name from the Firebase Console. - Replace the old
google-services.jsonfile inapp/.
Step 6: Clean and Rebuild the Project
- Go to Build > Clean Project.
- 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.