Android

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:

  1. In AS top-left corner, choose Project panel
  2. Right next to Project panel, click on the settings logo
  3. In the new option list, uncheck Compact Middle Packages
  4. Apply Refactor-Rename for each folder
  5. After rename, check the Compact Middle Packages
  6. Manually update the applicationId in module level build.gradle

Finally, there may be code related with the old package name, to verify that:

  1. rm -rf app/build
  2. grep -r "originalPackageName" . 2>/dev/null

If there is output for step 2, maybe related code needs update.

上一篇 下一篇

猜你喜欢

热点阅读