How to rename package name in Android Studio

If you are working on an Android Project and working with IntelliJ's IDEA Android Studio and wondering how to rename java package name, here is how you can do it,

Steps to Rename package Name: Android Studio
  1. Open your project, make sure you are in Project View
  2. Expand your app module and look for java, when you expand it you will see all your packages,
  3. Right click on the package example and go to Refactor -> Rename ..., you can also use shortcut Shift + F6
  4. You would see a warning window,
    Multiple directories correspond to package
    also generated:
    Do you want to rename the whole package or directory 
    C:\Users\c2c\AndroidStudioProjects\MyApp\app\src\main\java\com\example\myapp only?
    you can select Rename Package
  5. You would see an Rename window, change your package name and and click refactor
  6. Under Refactoring, you can see what code will be changed, click do refactor after validating,
    Directory to be renamed to com.example.myapp1, Package to be renamed to myapp1
    References in code to directory com.example.myapp, package com.example.myapp (10 references in 9 files)
      (9 usages found)
        Unclassified usage  (5 usages found)
            app  (5 usages found)
                com.example.myapp  (5 usages found)
            (1 usage found)
                        1 package com.example.myapp;
            (1 usage found)
                        1 package com.example.myapp;
            (1 usage found)
                        1 package com.example.myapp;
            (1 usage found)
                        1 package com.example.myapp;
            (1 usage found)
                        1 package com.example.myapp;
        Usage in Android manifest  (1 usage found)
            app  (1 usage found)
                app\src\main  (1 usage found)
                    AndroidManifest.xml  (1 usage found)
                        3 package="com.example.myapp">
        Usage in Android resources XML  (3 usages found)
            app  (3 usages found)
                menu  (1 usage found)
                    menu_main.xml  (1 usage found)
                        4 tools:context="com.example.myapp.MainActivity">
                navigation  (2 usages found)
                    nav_graph.xml  (2 usages found)
                        10 android:name="com.example.myapp.FirstFragment"
                        20 android:name="com.example.myapp.SecondFragment"
    References in generated code to directory com.example.myapp, package com.example.myapp (10 references in 9 files)  (1 usage found)
        Unclassified usage  (1 usage found)
            app  (1 usage found)
                com.example.myapp  (1 usage found)
            (1 usage found)
                        4 package com.example.myapp;
  7. Note: You would require to make appropriate changes to build.gradle file manually.
  8. Build your project again and you should be done!

Another way of doing it is by creating a new package instead and copying all your contents there - but here you would require to manually update your AndroidManifest.xml and build.gradle file.

Hello there!,

You are using AdBlocker!

I am an independent developer trying to help fellow developers and students to resolve issues faced on a day-to-day basis, we 'Code to Care' . There is a lot of expenses involved in hosting and managing a website that's the reason we have ads.

A humble request to you to disable adBlocker on and support us pay our bills.

Cod2care - Line's of code for change.

To see contents reload page after unblocking
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities. Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, Tips-n-tricks, How Tos, Blogs, Articles, etc. on various platforms like Windows, Mac, Linux, Mobile platforms, etc. Technologies/Languages like Java, Objective-C, PHP, .Net, Android, SharePoint, jQuery, HTML, CSS, etc.