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.gradle and the real file structure.
  • ๐Ÿ”ด Application crash at startup, if the package name is AndroidManifest.xml out of sync with build.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. applicationId and paths to addiction.
  • ๐Ÿ“„ AndroidManifest.xml - contains the attribute package, which must match the applicationId.
  • ๐Ÿ“ Package structure in src/main/java - the physical location of the classes.
  • ๐Ÿ”— R.java and other auto-generated files - they refer to old paths.
โš ๏ธ Attention: If your project uses Firebase, Google Play Services or other services tied to applicationId, their configuration will also have to be updated manually (for example, in google-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 applicationId will 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:

  1. Create a new branch specially for renaming (for example, rename/package-refactor).
  2. Disconnect all lint-checkers and code inspections during refactoring (Analyze โ†’ Inspect Code โ†’ Configure โ†’ Disable all).
  3. Use the tool refactor in 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:

  1. Synchronize the project with Gradle (File โ†’ Sync Project with Gradle Files).
  2. Clean the project (Build โ†’ Clean Project).
  3. 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 applicationId should 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:

  1. Open Project View (left panel, select Project in the drop-down menu).
  2. Find the root package of your application (usually app/src/main/java/com/oldcompany/oldapp).
  3. Right-click on the package folder and select Refactor โ†’ Rename.
  4. In the window that appears, enter a new package name (for example, com.newcompany.newapp) and click Refactor.
  5. 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 (especially layouts i menus) 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:

  1. Manually replace old imports in problem files (use Ctrl+Shift+R for global search).
  2. Check build.gradle for the presence of custom ones sourceSets or java.srcDirs.
  3. Delete folders build and .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/bash

OLD_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 "" with sed -i (without quotes).
  • ๐Ÿšจ Before running required test the script on a copy project.

After executing the script:

  1. Delete folders build and .idea.
  2. Open the project in Android Studio and wait indexing.
  3. Run Build โ†’ Clean Project and Build โ†’ 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 folders app/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:

  1. Return to the last one working commit (git checkout last_commit).
  2. Repeat the rename, but step by step (first applicationId, then packages, then manifest).
  3. 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:

  1. Update settings.gradle:
    include ':app', ':core', ':feature-auth'
    

    rootProject.name = "NewProjectName"

  2. For each module, update build.gradle (if it has its own applicationId for tests).
  3. Check inter-module dependencies:
    implementation project(':core')

    Make sure that the paths to the modules do not contain old names.

  4. Update AndroidManifest.xml in each module (if any).

Features for Dynamic Feature Modules:

  • ๐Ÿ“ฆ The package name in the module manifest must match the main one applicationId.
  • ๐Ÿ”— In build.gradle module, check:
    android {
    

    dynamicFeatures = [":feature-auth"]

    }

  • ๐Ÿ”„ After renaming, run BundleTool to generate a new .aab.

For projects with Flavors (different assemblies for dev, prod):

  • ๐Ÿญ Update applicationIdSuffix to build.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):

  1. Create new app in Google Play Console s new applicationId.
  2. Publish it as a separate product (the old app will remain available).
  3. Use deep links or promo pagesto redirect users from the old app to the new one.
  4. If necessary, export reviews and statistics via Google Play API.

To change display name applications (what users see in Play Market):

  1. Open app/src/main/res/values/strings.xml.
  2. Find the line:
    Old name
  3. Replace it with a new name:
    New name
  4. 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:

  1. Download a new one google-services.json for the new applicationId from Firebase Console.
  2. Place it in app/ (replacing the old file).
  3. Update classpath for the Google Services plugin in build.gradle (project level):
    classpath 'com.google.gms:google-services:4.4.0'
  4. 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 (update target_include_directories).
  • ๐Ÿ“„ Header files (.h), where paths to Java classes can be hardcoded.
  • ๐Ÿ”— JavaVM and JNIEnv links to classes (for example, in RegisterNatives).

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:

  1. Clean the folder app/.externalNativeBuild.
  2. 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:

  1. Increase the database version. in @Database:
    @Database(entities = [...], version = 2)
  2. Create Migration to migrate data:
    static final Migration MIGRATION_1_2 = new Migration(1, 2) {
    

    @Override

    public void migrate(SupportSQLiteDatabase database) {

    // Update tables if necessary

    }

    };

  3. 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:

  1. Keep the old one applicationId, but change:
    • Application name (app_name in strings.xml).
    • Icon and graphic resources.
    • Description in Google Play Console.
  • Create a new application with new 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.