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
Project
panel - Right next to
Project
panel, click on the settings logo - In the new option list, uncheck
Compact Middle Packages
- Apply
Refactor
-Rename
for each folder - After rename, check the
Compact Middle Packages
- Manually update the
applicationId
in module levelbuild.gradle
Finally, there may be code related with the old package name, to verify that:
rm -rf app/build
grep -r "originalPackageName" . 2>/dev/null
If there is output for step 2, maybe related code needs update.
网友评论