6

I have an android project with a package name like com.example.alexander.app and I want to change this to a name containing only three parts, like com.alexapps.firstapp. However, after searching several sites, I still have no idea how to do that in AndroidStudio (2.1.3).

I found the following answer, which do not fully answer my question:

  • Answer 1 requires the file R.java which I cannot find
  • Answer 2 looked very good by using methods in AndroidStudio. Unfortunately, even after cleaning and rebuilding the project, the package name was not changed on my single activity.
  • Answer 3: I searched for the string, and found more than 1000 hints!! Therefore I have not continued with this solution to replace more than 1000 hits, as this does not sound right. I have only 1 (one!) single activity in this test app...
  • Answer 4: Very good answer, but only useful if you want to change each of the package name parts (and neither increasing nor decreasing the number of parts in the package name).

So is there a way to remove a part of a package name with AndroidStudio?

Community
  • 1
  • 1
Alex
  • 41,580
  • 88
  • 260
  • 469

1 Answers1

7

The easiest thing to do is right click the folder/package, and refactor. This however i think is limited to the final folder, and does not remove a hierarchy.

So the solution in this scenario, is to

  1. create a new folder
  2. move all the folders/files into it. (this should initate a refactor on each file)
  3. Rename any references to your activities etc in the manifest to the correct package names (it should have done this for you)
  4. Clean and rebuild (to fix the R file)
IAmGroot
  • 13,760
  • 18
  • 84
  • 154
  • @Alex Happy to hear :) I don't imagine it to be a common task, so should be ok – IAmGroot Dec 13 '16 at 13:31
  • 1
    @Alex, In theory, it should be the domain name of your company, backwards. aka: `www.alexapps.com` -> `com.alexapps.appname`. However, in reality, you may not be a company with a domain name. But could still base it on that concept with a desired domain name, should you ever buy it. Just got to make sure it doesnt already exist too. – IAmGroot Dec 13 '16 at 13:38