69

I'm using Eclipse. Say I have a project 'ProjectA' in the eclipseworkspace (in a folder ProjectA). I want to copy the project but with a new name (ProjectB) and have all the references in the new project adjusted. I can't find much help for what I thought would be a vary basic operation. I want to try out variations on the original design/code and creating a copy seemed the obvious way to go about it.

Any suggestions please.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
ron
  • 5,219
  • 8
  • 39
  • 44

12 Answers12

96
  1. Copy your project to a new one (Ctrl+c & Ctrl+v).

  2. Change the package-name in your manifest

  3. Rename your main package with refactor. Don't forget to select.

  4. Change your application name in manifest

    application android:icon="@drawable/icon" android:label="**new name**"
    
ggorlen
  • 44,755
  • 7
  • 76
  • 106
Tima
  • 12,765
  • 23
  • 82
  • 125
  • 1
    Please see @iwpSoftware's important addendum -- the original project must be *open* before pasting. – LarsH Mar 02 '12 at 08:25
  • 2
    check AndroidManifest.xml(eclipse ADT always messes things up!!!), then change version to 1, fix and finally in the source code find & replace all the import com.old.R; with import com.new.R; clean and build – max4ever Oct 15 '12 at 08:33
  • 1
    if you fork an app also don't forget to change android:authorities(and the ContentProvider AUTHORITY) or it won't install on the same device with the original app, google maps key change since new keystore, libraries must have same Android Support Library version as the project or won't compile – max4ever Jan 18 '13 at 11:13
  • 3
    A small note - the appname may actually be defined in the strings resource file and look like 'android:label="@string/app_name"' in your manifest file. In this case you can simply update this entry in the strings resource file - i.e. 'new name – Mick Mar 21 '13 at 13:41
  • There's now an automatic tool for that, part of the ADT. see my answer below: http://stackoverflow.com/a/24737634/1180898 – Amir Uval Jul 14 '14 at 13:31
  • I've followed your 1st and 2nd step..but when i look after my package to rename it,I see that java folder is empty.. :( only xml files are copied even they don't have design view.. – Prabs Mar 18 '15 at 12:03
  • "Don't forget to select." - select what? – Solace Jun 16 '15 at 20:23
  • I was confuse with point 1 ,because I am new one. I was confused because I want to copy project from B workspace to A workspace. And I was doing folder copy from B to paste A. In case of same workspace its working perfect. I am just clarifying point 1st for new comers in android development so that new one not getting confused. - you just copy your project into new one (ctrl+c & ctrl+v) means you have to select your existing folder's and copy and then paste at that time one window will open to rename it. – Mohini Jul 24 '15 at 05:33
  • 1
    If you are using Android Studio it seems you must also change the applicationId in your app gradle file for the refactor to work. – matthias_b_nz Nov 21 '15 at 01:43
23

I just want to add an item to Mur Votema's list:

5) Don't forget to open the project you want to copy!

It just cost me some minutes to find out that it doesn't work with closed projects. :-)

iwpSoftware
  • 231
  • 2
  • 3
  • 1
    Thank you, this is the critical piece I was missing! As you noticed, if the project you want to copy from is closed, "Paste" throws an error and there's no indication of anything you can do to make it work. – LarsH Mar 02 '12 at 08:22
17

If you are using Eclipse and all you want to do is clone your Android project and give it a new project name, simply do the a copy/paste (Ctrl-C & Ctrl-V - step 1 in Mur's answer above). Eclipse will ask you for a new project name when you paste and you're done. The Eclipse project name and directory are independent of the application name and package.

jengelsma
  • 8,192
  • 4
  • 21
  • 21
  • 2
    Best answer here. But do remember you need to have project open in order to copy and paste it this way. – mwengler May 02 '12 at 23:09
  • @mwengler What do you mean by an 'open' project and a 'closed' one? – Yatharth Agarwal Nov 06 '12 at 15:12
  • 2
    @YatharthROCK In the project explorer you should see folder-like icons, one for each project. Right click on the icon, the menu coming up will include either `Open Project` if the project is currently closed or `Close Project` if the project is currently open. You may have been leaving all your projects open, you will like the performance improvement if you `Close Unrelated Projects` after right-clicking on the project you are currently working on. – mwengler Nov 07 '12 at 21:32
  • When I do this my all my java files end up with errors related to the R.java file and I see that it is no longer gen'd automatically how do I get the R.java file to regen The first import was com.xxx.myoldappname.R I changed it to import com.xxx.newappname.R but still get the erro becasue the R.java is not regenerating if I could get it to regen all of the errors would disappear and I would be all set So how do I get the R.java file to rebuild. I have tried multiple clean and rebuild but nothing is doing it – Jeff Janes May 03 '14 at 16:04
5

Mandatory tasks:

  1. In Eclipse, Copy and paste the project. (Give the project a new name)
  2. In Manifest, update the Package name and save. (Update Launch Configuration)
  3. Refactor and rename the Package name. (Update references)

Optional tasks:

  1. In Manifest, change the Application label and icon, so after
    installing the application on your device it won't be confused with the first one.
  2. Refactor and rename the java files name, so they won't be confused with the original project files.
  3. If you have used Encodings such as UTF-8 in your project (in order to handle languages other than English) you might need to edit and save those files so their font would be shown correctly.

Note: If you do the 3rd task before 2nd task, some undesired imports would be added to your java classes. You then will need to remove those imports.

Nima K
  • 995
  • 1
  • 8
  • 15
3

There's now an automatic tool for that, part of the ADT.

  1. Make sure the origin project is open in Eclipse, copy & paste to a new name
  2. Right click on the new project > Android Tools > Rename Application Package

Done

Amir Uval
  • 14,425
  • 4
  • 50
  • 74
1

As said above all you have to do is copy+paste the project and rename it ["myApp.11"] but sometimes this feature gets bugged in eclipse. One such case happens when you have more than one version of the jdk. to solve this close eclipse rename the older versions of the jdk with an underscore e.g. _jdk17.2 and retry. if you dont need these versions delete them.

Rubber Duck
  • 3,673
  • 3
  • 40
  • 59
0

I Just wanted to add this after struggling with a code i have at work:

DO NOT USE THE PACKAGE NAME EXPLICITLY IN YOUR JAVA CODE NO MATTER WHAT. YOU MIGHT NEED TO RENAME YOUR PROJECT . EXAMPLES ARE : getResource() and setting the Bitmap source and such and such

it looks like that I had bad references to the package name. it name was used explicitly as a String (e.g "com.pakge.mypkg" ) instead of Context.getPackageName() .

try to reach this method anyways you can 'cos the way i just mentioned it might not work for you... try to reach the method name "getPackageName()" from different other objects.

0

I have to answer not comment as reputation not high enough - to say that I agree @jengelsma has the best answer, just copy and paste, but watch out for the (hidden) SVN files (in .svn folders)! Unless you want the same references as the other project you don't want these.

Team > disconnect and check 'also delete SVN meta data' on your new copy to do this.

Jon
  • 101
  • 1
  • 1
  • 7
0

Just want to add some more points :- Be ensure that the package name must be different for new project and old project if both project are going to install on same machine.

also modify the same in Mainfest.xml under

0

I used the eclipse Luna, I tried to copy an existing project (Project_A) as below

  1. Create a new Java project (its name is as Project_B)
  2. Right click on Project_B (to pop up the context menu)
  3. Select the menu item "Import..." (to show the "Import" dialog)
  4. On the list under the "Select an import source" field to extend the item "General"
  5. Double click on the sub-item "File System" (to show the "File System" page)
  6. Enter the path of "Project_A" directory into the "From directory" field (or click the "Browse..." button to find and select the directory of "Project_A")
  7. Check the checkbox of "Project_A" directory under the "From directory" field
  8. To see if the "Into folder" field is showing folder name as "Project_B" (if not, click "Browse..." button to find and select the "Project_B")
  9. Click the "Finish" button (because the Project_B is empty, need not care any more)
  10. The all contents of Project_A are copied into Project_B, we can run the Project_B as the Project_A (if needed we can refactor the Project_B)
phchen2
  • 377
  • 4
  • 6
0

Another thing I noticed is that if you leave android:label="@string/app_name" it somehow keeps the original app name when you view the copied app in the list of Applications in Settings > Applications > Manage applications but if you change it to android:label="Your App Name" it seems to work ok.

Also be sure to change your icons properly by deleting the old ones and importing the new ones.

ben_nuttall
  • 859
  • 10
  • 20
  • This is because `@string/app_name` is referring to a string in an .xml file in the `values` directory. This is a template set up by Android SDK and thus when changing your application name, you should change this string as well. – d3dave Aug 16 '13 at 21:18
0

I went to the workspace folder on C:/ (path different for all) copied the project folder (Project A), and pasted it with a new name (Project B). Change the name while in explorer. Then, through Eclipse, made a new android project with the new name (Project B). Different way of doing it.

Ccorock
  • 892
  • 12
  • 37