Android Studio rename a package
2021-03-25 本文已影响0人
JaedenKil
Simple scenario: Need to rename a package, say from com.aa.bb to com.cc.dd.
The usual method won't work: In project panel, choose package folder, refactor - rename, which will only rename the last part of the package name.
Solution:
- In AS top-left corner, choose
Projectpanel - Right next to
Projectpanel, click on the settings logo - In the new option list, uncheck
Compact Middle Packages - Apply
Refactor-Renamefor each folder - After rename, check the
Compact Middle Packages - Manually update the
applicationIdin module levelbuild.gradle
Finally, there may be code related with the old package name, to verify that:
rm -rf app/buildgrep -r "originalPackageName" . 2>/dev/null
If there is output for step 2, maybe related code needs update.