Renaming package in Android Studio

2020-07-23 05:14发布

问题:

I am trying to rename my Android Studio package as described in the first answer at: Android Studio Rename Package

Trying to change org.springframework.android.showcase to org.springframework.android.showcase2

The refactoring seemly works fine, then I try delete the old package within /gen/org.springframework.android/showcase. This does occur but then it reappears (Within /gen/org.springframework.android/showcase)

When compiling I get over a 100 errors all related to the R.java file references.

Copying the R.java, Manifest.java from the original to the new does not work either. Studio simply deletes these but leaves the BuildConfig.java file.

Is there an easier way because Studio just does not seem to want to play ball?

Below is my Project structure in case it's helpful

回答1:

The reason you are seeing the generated files with the old package name is because you only renamed the source code package. The generated files use the package name defined in the AndroidManifest.xml. If you change the package at the top of the manifest as well you will see the generated files use the new package. Make sure to clean the project and rebuild to see the changes.



回答2:

Try menu: build->clean project



回答3:

Renaming your android app package in android studio is very simple. Right click on your project in project explorer.

And click Open Module Settings. Or use the short key F4. Click the Flavors Tab. Rename the Application Id of your choice – this is your new package name.

Source: http://wazeem.com/639/how-to-rename-package-in-android-studio/



回答4:

For me the package name was renamed by Android Studio everywhere except in manifest.xml. I manually replaced it there after which it compiled fine.