Change the package name manually in the manifest file.
Click on your R.java class and the press F6 (Refactor->Move...). It will allow you to move the class to other package, and all references to that class will be updated.
@Luch Filip's solution works well if you just want to rename the App package. In my case, I also want to rename the source package too, so as not to confuse things.
Only 2 steps are needed:
Click on your source folder e.g. com.company.example > Shift + F6 (Refactor->Rename...) > Rename Package > enter your desired name.
Go to your AndroidManifest.xml, click on your package name > Shift + F6 (Refactor->Rename...) > enter same name as above.
Step 1 will automatically rename your R.java folder, and you can build straight away.
The simplest way of doing this would be to rename the root app folder from com.example.MyApp to com.newcompanyname.MyNewAppName and then replace all occurrences of the old path to the new path in whatever IDE you're using.
I found another solution for renaming a package in the entire project:
Open a file in the package.
IntelliJ displays the breadcrumbs of the file, above the opened file.
On the package you want renamed: Right click > Refactor > Rename.
This renames the package/directory throughout the entire project.
1) Open the project folder in Android Studio.
2) Select app folder -> Right click, and select refactor.
3) Click on move. It will ask to which package name type you own full package name and it will ask to create a new package yes create new automatically it ask for gradle to sync.
To rename the package name in Android studio, Click on the setting icon in the project section and untick the Compact empty Middle Packages, after that the package will split into multiple folder names, then right click on the folder you need to change the name, click on refactor-> Rename-> Type the name you want to change in -> Refactor -> Refactor Directory, then import R.java file in the whole project. Working for me.
This might help you -
1) Open a file of your package.
2) Android Studio displays the breadcrumbs of the file, above the opened file.
On the package you want renamed: Right click > Refactor > Rename.
For example, if you want to change com.example.app to iu.awesome.game, then:
In your Project pane, click on the little gear icon ( )
Uncheck / De-select the Compact Empty Middle Packages option
Your package directory will now be broken up in individual directories
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
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:
You may need to change the package= attribute in your manifest.
Clean and Rebuild.
Done! Anyway, Android Studio needs to make this process a little simpler.
Select your package and Right-click, Refactor -> Move.
Choose Move package from "your package" to another package and click Ok.
A new dialog appears, says Multiple directories correspond to package "your package" and click Yes.
Enter the new package name except for the last level or last name. Means If you want to rename package name to "info.xyz.yourapplication". Then type down "info.xyz" only leave "yourapplication".
Click Refactor.
A new dialog, Package info.xyz does not exist. Do you want to create it?. Click on Yes.
Click Do refactor.
Right-click on the new package to change the last name. Refactor-> Rename.
Rename package
type new name and click Do refactor.
Delete all old package directories.
Change ApplicationId in build.gradle file and click on sync now
I have not changed any package name. The following two steps worked for me. After doing the following, the application was installed as a NEW one , eventhough there was two applications with the same package name.
1) In the build.gradle
applicationId "mynew.mynewpackage.com"
2) In the AndroidManifest.xml
android:authorities="mynew.mynewpackage.com.fileprovider"
In my case when I moved my MainActivity file to the new package folder structure as prescribed... it refactored my AndroidManifest.xml. Finally after checking Logcat I realized that was the issue, and renamed it back to ".MainActivity" from ".MainActivity"