Android Studio is an official
The idea is to move all classes and packages to our desired package and then delete the empty package.
Let us take a look at an example to understand this better.
Let's say we have an android project that looks like this. If packages are in compact, we can expand them by clicking the gear icon at the top right of the image and unchecking the "Compact Empty Middle Packages" option.
Once we uncheck the option, our packages will be expanded as shown below. Here, we're going to remove "my" package. So drag and drop the "application" package and its "classes" to the "example" package.
Android Studio will then ask for our confirmation to move everything as shown below. Simply click "OK" and then "YES".
As the final step, it will show a dialog to confirm refactoring. Click "REFACTOR".
Android Studio will take between a few seconds to minutes to refactor everything based on the size of our project. Once done, our packages will be moved to the "example" package and "my" package will be empty.
Now, we can delete "my" package by selecting it and clicking the "Delete" button on the keyboard.
And we're done! We have deleted "my" package from the Android Studio project successfully.
Note: Let's say we deleted the "application" package and not "my" package. Then we'd need to change the package name in
AndroidManifest.xml
andbuild.gradle
files after moving all the classes.
Free Resources