A step by step explanation of how to rename project's package name!

This has been 3rd time that IDEA is destroying my work after rename procedure. This morning, I lost 4 hours of work! And yet, I cannot find a tutorial showing how to rename the project. This task is a piece of cake in Eclipse.

I am talking about renaming Android project package.

On the net, I can find such steps:
1. go to Manifest file
2. manually rename the package
3. a new folder in /gen will appear (you new package name)
4. click R.java class
5. F6 and move it to new /gen folder.

I did this previously, as well as this morning and I lost 99% of /src content. Hours of work gone in 1s.

Thanks in advance!

I use IDEA 11, latest update.

4 comments
Comment actions Permalink

This sequence of steps is correct. Actually there are very few actions in IntelliJ IDEA that can delete your source code, and certainly none of these steps are supposed to cause this effect. Even if you accidentally delete the source code, you can almost always recover it from the local history (VCS | Local History | Show History).

When you're saying you lost 99% of src/ content, what was the 1% that was left?

0
Comment actions Permalink

Do not get me wrong, IDEA is so good that I am its evangelist.

But renaming is killing me. I thought it was fixed, but it seems not.

This was the case. In /src I had 3 packages with its sub-packs.

/src
------/google/
-----/myproject/
----/facebook

I renamed "myproject" to "myprojectnew" in Manifest and then I've got a new folder in /gen with R.java already moved to it. Then I renamed the Module (the top most root folder) to something else. After that I got 2 modules:
1. a new one with all the files without R.java
2. another module with old name and with R.java file.

I clicked on R.java, F6, moved it to a new module (its /gen folder) and then a longer process started of approx 45s. After that I lost "myprojectnew" dir, while google and facebook folders remained.

I will now try that feature you suggested to retrieve my files. I just hope its still there as I shuu down IDEA.

0
Comment actions Permalink

OK, I tried again. A rename was successful, but after rename I cannot access some string, like string/app_name and similar. Also, renamed projects crashes.

Does it seem like a bunch of random errors? So weird and unpredictable.

Can you try to rename a complex project this way and see if it works?!

0
Comment actions Permalink

It seems that THE BEST WAY is just to Ctrl+F6 (rename) the main package. I will rename the Manifest as well.

What this method DOES NOT do:
- rename custom XML elements, e.g. com.old.mycoolelement will not rename to com.new.mycoolelement. Compile will pass but you will receive run-time errors. this has to be done manually.

I haven't found other issue. I renamed a very complex project and I think that other issues would appear.

So can you do 2 things:

1. Write a rename help page for others. Do not suggest the old way, as IDEA 11 is smart to do everything via simple renaming of the main package.

2. Fix the rename issue I described here and publish the patch.

Thanks in advance.

0

Please sign in to leave a comment.