Rename package in Android Studio

0 votes
How do you rename packages in the new IDE Android Studio, based on IntelliJ IDEA? Is there automatic refactoring included?

I want to do bulk refactoring, but need help in doing so. I worked two years with Eclipse and in Eclipse it's a one-click operation.
Feb 23, 2022 in Others by Soham
• 9,700 points
47,639 views

1 answer to this question.

+1 vote

In Android Studio, you can do this: For example, if you want to change com.example.app to my.awesome.game, then:

  1. In your Project pane, click on the little gear icon ( Gears icon )

  2. Uncheck the Compact Empty Middle Packages option
    Compact Empty Middle Packages

  3. Your package directory will now be broken up into individual directories

  4. Individually select each directory you want to rename, and:

  • Right-click it

  • Select Refactor

  • Click on Rename

  • In the pop-up dialog, click on Rename Package instead of Rename Directory

  • Enter the new name and hit Refactor

  • Click Do Refactor in the bottom

  • Allow a minute to let Android Studio update all changes

  • Note: When renaming com in Android Studio, it might give a warning. In such case, select Rename All
    Enter image description here

  1. Now open your Gradle Build File (build.gradle - Usually app or mobile). Update the applicationId in the defaultConfig to your new Package Name and Sync Gradle, if it hasn't already been updated automatically:
    Refactor Directories

  2. You may need to change the package= attribute in your manifest.

  3. Clean and Rebuild.
    Clean and Rebuild

  4. This should help you with your doubt. 

answered Feb 23, 2022 by Aditya
• 7,680 points

Related Questions In Others

0 votes
1 answer

Error: IllegalArgumentException: Unable to locate adb in Android Studio v2.3

when you try to move an Android project ...READ MORE

answered Dec 16, 2020 in Others by Gitika
• 65,910 points
2,283 views
0 votes
1 answer

Unable to detect adb version, adb output in Android Studio 3.3.2

To avoid this ERROR, start with changing ...READ MORE

answered Feb 11, 2022 in Others by Soham
• 9,700 points
1,599 views
0 votes
0 answers
0 votes
0 answers

Open Contact information in Contact List using Phone Number of Contact Android Studio

I am making an app that has ...READ MORE

Jun 7, 2022 in Others by polo
• 1,480 points
544 views
0 votes
1 answer

I want to restrict the opening of Browser on URL Click

You can call it as a web ...READ MORE

answered Aug 7, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
4,860 views
0 votes
1 answer

How can Blockchain be implemented for android development?

Essentially you need to understand what is ...READ MORE

answered Aug 10, 2018 in Blockchain by Johnathon
• 9,090 points
1,035 views
0 votes
1 answer

What is the future of flutter?

Hi@MD, Flutter is a rather new cross-platform framework ...READ MORE

answered Jul 17, 2020 in Others by akhtar
• 38,230 points
903 views
0 votes
1 answer

What is Flutter?

Hi@akhtar, Flutter is an app SDK for building ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,440 points
1,067 views
0 votes
1 answer

How to get current time and date in Android

In order to get the current date ...READ MORE

answered Feb 23, 2022 in Others by Aditya
• 7,680 points
1,712 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP