Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove parts of an android package name with AndroidStudio?

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?

like image 707
Alex Avatar asked Dec 13 '16 13:12

Alex


People also ask

Can we change package name in Android Studio?

Step by Step Implementation Step 2: Now click on the setting gear icon and deselect Compact Middle Packages. Step 3: Now the packages folder is broken into parts as shown in the below image. Step 4: Now right-click on the first package name (com) and Refactor > Rename.

Can we change package name in Android after release?

From Dianne Hackborn: Things That Cannot Change: The most obvious and visible of these is the “manifest package name,” the unique name you give to your application in its AndroidManifest.

Does package name matter Android studio?

No it wont have any change. You follow the same steps as before but with your new package. Just upload it as a new app. That's all.


1 Answers

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)
like image 144
IAmGroot Avatar answered Sep 18 '22 01:09

IAmGroot