Renaming an Android project is a task that every developer faces sooner or later. Whether you are just starting to work on an application and want to give it a more meaningful name, or your project has grown from a test sandbox into a full-fledged product, changing the package name, application name, or even the module structure requires a careful approach. Unlike simply renaming a file, this involves dozens of configuration files, manifests and dependencies, where one typo can lead to build failure or a broken APK.
In this article we will analyze all possible scenarios: from the basic changes applicationId to Gradle to complete refactoring of the package structure while maintaining compatibility. You will learn how to avoid common mistakes (for example, inconsistencies in package names in the manifest and Java/Kotlin code), what tools will speed up the process, and what to do if the application stops starting after renaming it. The material is relevant for Android Studio Giraffe 2023+ i Gradle 8.x, but the basic principles also apply to earlier versions.
Why simply renaming files does not work
Many beginners try to rename an Android project in the same way as a regular folder in Explorer - through F2 or the context menu. This is gross errorwhich leads to:
- ๐ด Build failures due to mismatch of paths in
settings.gradleand the real file structure. - ๐ด Application crash at startup, if the package name is
AndroidManifest.xmlout of sync withbuild.gradle. - ๐ด Lost connections between modules (for example, if the project uses dynamic feature modules).
- ๐ด Problems with the version control system (Git will see the renaming as deleting old files and creating new).
The fact is that an Android project is not just a set of files, but a complex system with hard connections between:
- ๐
build.gradle(module level and project) - the paths to the dependencies are stored here.applicationIdand paths to addiction. - ๐
AndroidManifest.xml- contains the attributepackage, which must match theapplicationId. - ๐ Package structure in
src/main/java- the physical location of the classes. - ๐
R.javaand other auto-generated files - they refer to old paths.
โ ๏ธ Attention: If your project uses Firebase, Google Play Services or other services tied toapplicationId, their configuration will also have to be updated manually (for example, ingoogle-services.json).
Preparing the project for renaming
Before making changes, complete required preparatory steps:
Commit all changes in Git (or create a backup of the project)|Close all instances of Android Studio|Check the project for build errors (Build โ Make Project)|Disable Gradle synchronization (File โ Settings โ Build, Execution, Deployment โ Gradle โ Uncheck "Auto-reload")|Make sure you have write permissions to all project files
-->
If you work in a team:
- ๐ฅ Agree on the renaming with other developers - the change
applicationIdwill affect all branches. - ๐ Schedule work during the period of minimal activity in the repository.
- ๐ง Prepare a script to automatically correct imports in the code (can be used sed or Regex in the IDE).
For complex projects (with several modules or dynamic features) it is recommended:
- Create a new branch specially for renaming (for example,
rename/package-refactor). - Disconnect all lint-checkers and code inspections during refactoring (
Analyze โ Inspect Code โ Configure โ Disable all). - Use the tool
refactorin Android Studio, rather than manual editing.
โ ๏ธ Attention: If your project uses Native code (JNI), renaming packages may break the connection between the Java/Kotlin and C++ layer. In this case, manual editing will be required. header files. CMakeLists.txt and header files.
Manually editing files|Via Refactor in Android Studio|Scripts (sed, Python)|Never renamed|Another way
-->
Method 1: Changing applicationId in Gradle (base method)
This is the easiest and safest way if you need just change application identifier (what is visible in Google Play Console and is used to sign the APK). The physical structure of the packages will remain the same.
Open the file app/build.gradle (or build.gradle your module) and find the block:
android {defaultConfig {
applicationId "com.oldcompany.oldapp"
// other settings...
}
}
Replace the value applicationId with a new one, for example:
applicationId "com.newcompany.newapp"
After that:
- Synchronize the project with Gradle (
File โ Sync Project with Gradle Files). - Clean the project (
Build โ Clean Project). - Rebuild the APK (
Build โ Rebuild Project).
This is enough if:
- โ
You do not change the physical structure of the packages (for example,
com.oldcompany.oldappโcom.newcompany.newapp, but the files remain in the same folder). - โ Your application does not use Broadcast Receivers or Servicesregistered in the manifest with an explicit package indication.
- โ
You do not plan to publish the update to Google Play under the same certificate (in this case
applicationIdshould remain the same).
If after the change applicationId the application does not start, check the file AndroidManifest.xml - perhaps the old value in the attribute remains there package.
Method 2: Complete renaming the package (structure + code)
If you need to change not only applicationId, but also physical location of files (for example, move classes from com.oldcompany.oldapp to com.newcompany.newapp), use the built-in tool Refactor in Android Studio.
Step-by-step guide:
- Open Project View (left panel, select
Projectin the drop-down menu). - Find the root package of your application (usually
app/src/main/java/com/oldcompany/oldapp). - Right-click on the package folder and select
Refactor โ Rename. - In the window that appears, enter a new package name (for example,
com.newcompany.newapp) and clickRefactor. - Confirm changes in all files (Android Studio will prompt you to update imports, manifest and Gradle).
What happens under the hood:
| File/Folder | What changes | Notes |
|---|---|---|
src/main/java/... |
Physically moving folders and files | All imports in the code are updated automatically |
AndroidManifest.xml |
Attribute package |
Must match the new one applicationId |
build.gradle |
applicationId (if not changed previously) |
May remain old if you want to separate logical and physical name |
res/values/strings.xml |
References to classes (for example, in android:name) |
Requires manual verification |
.gitignore, README.md |
Mentions of an old package | Does not update automatically |
After refactoring:
- ๐ Check all files with the extension
.xml(especiallylayoutsimenus) for links to old classes. - ๐ง Run
Invalidate Caches / Restart(File โ Invalidate Caches). - ๐ฑ Test the application on the device - some Broadcast Receivers or Content Providers may not register due to incorrect paths.
What to do if Refactor did not find all the references?
If, after renaming the package, some classes do not compile due to imports not found, try:
- Manually replace old imports in problem files (use
Ctrl+Shift+Rfor global search). - Check
build.gradlefor the presence of custom onessourceSetsorjava.srcDirs. - Delete folders
buildand.idea, then reload the project.
Method 3: Renaming through the terminal (for experienced)
If you prefer to work with the command line or need to rename hundreds of files using a template, you can use a combination sed, find i mv. This method riskybut gives full control over the process.
Example script for renaming a package com.oldcompany.oldapp โ com.newcompany.newapp:
#!/bin/bashOLD_PACKAGE="com/oldcompany/oldapp"
NEW_PACKAGE="com/newcompany/newapp"
1. Rename folders
find . -type d -name "$OLD_PACKAGE" | while read dir; do
new_dir="${dir//$OLD_PACKAGE/$NEW_PACKAGE}"
mv "$dir" "$new_dir"
done
2. Replace imports in Java/Kotlin files
find . -name ".java" -o -name ".kt" | xargs sed -i "" "s/$OLD_PACKAGE/$NEW_PACKAGE/g"
3. Update AndroidManifest.xml
sed -i "" "s/package=\"$OLD_PACKAGE\"/package=\"$NEW_PACKAGE\"/g" app/src/main/AndroidManifest.xml
4. Update build.gradle
sed -i "" "s/applicationId \""$OLD_PACKAGE\"/applicationId \""$NEW_PACKAGE"\"/g" app/build.gradle
Warnings:
- ๐จ This script does not handle cases when the package name appears in strings (for example, in logs or comments).
- ๐จ For Windows replace
sed -i ""withsed -i(without quotes). - ๐จ Before running required test the script on a copy project.
After executing the script:
- Delete folders
buildand.idea. - Open the project in Android Studio and wait indexing.
- Run
Build โ Clean ProjectandBuild โ Rebuild Project.
โ ๏ธ Attention: If your project uses Dagger 2, Room or other code-generating libraries, after renaming packages you may need to clear the annotation cache (Build โ Clean Project+ delete foldersapp/build/generated).
Problems after renaming and their solutions
Even with careful renaming, errors may occur. Here are the most common ones and how to fix them:
| Error | Cause | Solution |
|---|---|---|
Package 'com.oldcompany.oldapp' not found |
Not all imports were updated | Global search (Ctrl+Shift+F) by old package name |
Manifest merger failed |
Mismatch package in the manifest and applicationId |
Check both values in AndroidManifest.xml and build.gradle |
R cannot be resolved |
Not generated R.java due to errors in resources |
Check all layoutfiles for links to old classes |
Installation failed due to invalid APK |
Incorrect signature or applicationId |
Remove the old version of the application from the device before installation |
ClassNotFoundException at startup |
Paths in AndroidManifest.xml for Activity/Service |
Check the attributes android:name in the manifest have not been updated |
If after renaming the project no longer builds:
- Return to the last one working commit (
git checkout last_commit). - Repeat the rename, but step by step (first
applicationId, then packages, then manifest). - Use
git diffto see which files were modified incorrectly.
The most common error is a mismatch between applicationId and attribute package in AndroidManifest.xml. Always check both values after renaming!
Renaming for multi-module projects
If your project consists of several modules (for example :app, :core, :feature-auth), the process becomes more complicated:
- Update
settings.gradle:include ':app', ':core', ':feature-auth'rootProject.name = "NewProjectName" - For each module, update
build.gradle(if it has its ownapplicationIdfor tests). - Check inter-module dependencies:
implementation project(':core')Make sure that the paths to the modules do not contain old names.
- Update
AndroidManifest.xmlin each module (if any).
Features for Dynamic Feature Modules:
- ๐ฆ The package name in the module manifest must match the main one
applicationId. - ๐ In
build.gradlemodule, check:android {dynamicFeatures = [":feature-auth"]
} - ๐ After renaming, run
BundleToolto generate a new.aab.
For projects with Flavors (different assemblies for dev, prod):
- ๐ญ Update
applicationIdSuffixtobuild.gradle:productFlavors {dev {
applicationIdSuffix ".dev"
}
prod {
// without suffix
}
} - ๐ง Check
manifestPlaceholdersif they use${applicationId}.
How rename the project for Google Play
If your application is already published in Google Play Consolerenaming requires special care. It is important to distinguish here:
- ๐ Package name. (
applicationId) โ cannot change for an existing application This will create a new listing. - ๐ท๏ธ Application name (
android:label) โcan be changed without restrictions. - ๐ Package structure in code โcan be changed, but this will not affect the published application.
If you you still need to change applicationId (for example, when rebranding a company):
- Create new app in Google Play Console s new
applicationId. - Publish it as a separate product (the old app will remain available).
- Use deep links or promo pagesto redirect users from the old app to the new one.
- If necessary, export reviews and statistics via Google Play API.
To change display name applications (what users see in Play Market):
- Open
app/src/main/res/values/strings.xml. - Find the line:
Old name - Replace it with a new name:
New name - Update the name in Google Play Console (section
Store Listing โ App Name).
โ ๏ธ Attention: If you use Firebase or Google Analytics, renaming applicationId will require creating a new project in these services and transferring data manually.
FAQ: Frequently asked questions about renaming Android projects
Is it possible to rename a project without breaking Git history?
Yes, if you use the tool Refactor in Android Studio. It preserves the connection between old and new files, and Git recognizes this as a rename (rename) rather than a delete/create. To make sure the history is not lost, do:
git log --follow -p -- path/to/renamed/file
If you renamed manually, use:
git add -A
git commit -m "Rename package from old to new"
What should I do if Push Notifications (FCM) stop working after renaming?
The problem is that Firebase Cloud Messaging is tied to applicationIdAfter renaming:
- Download a new one
google-services.jsonfor the newapplicationIdfrom Firebase Console. - Place it in
app/(replacing the old file). - Update
classpathfor the Google Services plugin inbuild.gradle(project level):classpath 'com.google.gms:google-services:4.4.0' - Sync the project with Gradle.
If users of the old application need to receive notifications, you will have to support both applicationId at the same time (through two different projects in Firebase).
How to rename a project if it uses Native code (JNI/C++)?
When working with Native code package renaming affects:
- ๐ Paths in
CMakeLists.txt(updatetarget_include_directories). - ๐ Header files (
.h), where paths to Java classes can be hardcoded. - ๐
JavaVMandJNIEnvlinks to classes (for example, inRegisterNatives).
Example of correction in CMakeLists.txt:
# Old:target_include_directories(native-lib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../java/com/oldcompany/oldapp)
New:
target_include_directories(native-lib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../java/com/newcompany/newapp)
After changes:
- Clean the folder
app/.externalNativeBuild. - Rebuild the project (
Build โ Rebuild Project).
Is it possible to rename the project if it uses Room Database?
Yes, but please note that Room can store full class names in the database (for example, in @Entity or @TypeConvertersAfter renaming the package:
- Increase the database version. in
@Database:@Database(entities = [...], version = 2) - Create
Migrationto migrate data:static final Migration MIGRATION_1_2 = new Migration(1, 2) {@Override
public void migrate(SupportSQLiteDatabase database) {
// Update tables if necessary
}
}; - Add migration in
Room.databaseBuilder:Room.databaseBuilder(context, AppDatabase.class, "db-name").addMigrations(MIGRATION_1_2)
.build();
If you do not migrate, the application will crash error IllegalStateException: Room cannot verify the data integrity.
How to rename a project if it is published on Google Play?
If your application is already in Google Playyou you can't edit applicationId without creating a new listing Alternative options:
- Keep the old one
applicationId, but change:- Application name (
app_nameinstrings.xml). - Icon and graphic resources.
- Description in Google Play Console.
- Application name (
applicationId and:
- Use deep links to redirect users.
- Add a banner to the old application with a proposal to switch to a new one.
- Export reviews via Google Play API.
- Contact Google Play support with a request to transfer reviews and statistics (this is possible in exceptional cases, for example, when rebranding of the company).
If you just want to update the name of the application in the store, just change app_name in strings.xml and update Store Listing in Google Play Console.