Android Studio - How to copy a project?

2019-01-30 08:36发布

Alright, I've done some searching and seem to be coming close to the answer I'm looking for. But for fear of messing something up with my current project (I'm a first time app developer and I'm quite pleased so far... I'd like to stay that way), I'm looking for a nice and clear step by step on how to copy a project. I know some things in certain places need to be imported/renamed but I'm not sure exactly what/where.

So, is there a good step by step on how to do this or am I missing it? If not, can someone explain it to me in detail?

EDIT: I want to copy one app project to make another app project that's very similar. I'm using Android Studio for my apps. I want to be able to use one app to make another that's just like it (with differences of course). So instead of making a new project and making all the xml/java files and adding all the images, etc. I want to be able to use what I already have and duplicate it to make another app that's totally separate from the original. I'm not using Eclipse at all, I'm using Android Studio for my apps.

9条回答
啃猪蹄的小仙女
2楼-- · 2019-01-30 09:19

I've come across this question periodically because I've always wanted to be able to quickly accomplish what you're asking - completely copy a project to a new one and be able to go back and run the old version. I never tried any of the answers with the ridiculous number of steps because I was always concerned I would miss some hardcoded path and I would end up corrupting my primary copy.

My Answer:

I figured out after doing work with Android libraries that Android Studio pretty much treats an app the same as a library. They're both modules. So you can create a new empty project, then go to File -> New -> Import Module and browse to an app from another project. If you want to rename the app, from the Project view, you can right click and select Refactor -> Rename...

Also, Android Studio lets you have multiple apps in the same project. If your purpose is to develop two similar (like paid vs free) apps, you could put a lot of the overlapping functionality into a library and then customize the apps to be slightly different.

查看更多
看我几分像从前
3楼-- · 2019-01-30 09:23

I’m a newcomer to Android stuff, but this somewhat crude process worked fine for me:

In Android Studio:

  1. Create a new empty project.
  2. Go into the project you want to clone.
  3. In the Project structure, select all your Java class files – except for MainActivity (use click, then up-arrow with click to select them all in one go), and copy them to the clipboard .
  4. Go into your new Project, and paste the java class files into the appropriate folder. Any reference to PACKAGE NAME is AUTOMATICALLY UPDATED.
  5. Repeat steps 3 and 4 for everything else (drawables , XML layouts etc).
  6. Copy and paste MainActivity source code from old project to your new one(manually change the package name).
  7. You may have to do a few more manual changes (eg if you tag any class names in XML).
  8. For the Manifest, copy and paste the contents again, and then manually change the package name.
  9. This should be ready to build.
查看更多
爷、活的狠高调
4楼-- · 2019-01-30 09:25

I find the other suggested solutions too complicated. This is how I do it.

In Android Studio I select the project folder in the project view, right click it, select "Refactor" and "Copy..." (or just press F5). In the dialog I just give the copy a new project name and select a new folder.

In order to select the project folder you first have to make sure the project view shows the entire project, not just the "App".

That's it! Just one single step. No need to use File explorer or Finder to copy files. Android Studio copies all the files into the new folder and makes the necessary refactoring.

I don't know if this is a new feature i Android Studio or if there are other issues with this way of doing it. However I quite often use this method to create copies of projects as "forks" in order to try out different ways to solve a problem without changing the original project and it seems to work fine.

查看更多
登录 后发表回答