7

I'm using Android Studio 3.4 and I would like to copy and rename (clone) one of my existing projects and reuse it under a different project name.

I have tried changing the package name and refactor it, but I'm somehow stuck.

Do I need to manually modify the Gradle files?

Do I need to manually modify the AndroidManifest.xml file?

A step-by-step guide would be really appreciated.

bart
  • 1,003
  • 11
  • 24

3 Answers3

15

You can follow this steps:

  1. (Not in Android Studio) Make a copy / duplicate the existing 'OldProject' directory.
  2. (Not in Android Studio) Rename the copied directory to 'NewProject'.
  3. Start Android Studio 3.4.
  4. Select 'Open an existing Android Studio project'.
  5. Navigate to the 'NewProject' directory, select it and click 'Open'.
  6. Build -> Clean project.
  7. File -> Sync project with gradle file.
  8. Click the '1:Project' side tab and choose Android from the drop-down menu.
  9. Expand the app -> java folder.
  10. Right-click com.example.android.oldproject and select Refactor -> Rename.
  11. Give a new name to the new project in the Rename dialog.
  12. Select 'Search in comments and strings' and 'Search for text occurrences'. Click Refactor.
  13. The 'Find: Refactoring Preview' pane appears, click 'Do Refactor'.
  14. Expand the res -> values folder and double-click the strings.xml file.
  15. Change the app_name string value to "New Project".

Check the file and sync the project with the Gradle file:

  1. In Android Studio Project pane, expand Gradle Scripts and open build.gradle (Module: app).
  2. In android -> defaultConfig -> applicationId check that the value of the applicationID key is "com.example.android.newproject". If the value isn't correct, change it manually.
  3. File -> Sync project with gradle file

Make sure that the app and package names are correct in the AndroidManifest.xml file:

  1. Expand the app -> manifests folder and double click AndroidManifest.xml.
  2. Check that the 'package' name is correct. It should be "com.example.android.newproject". If not, change it manually.
bart
  • 1,003
  • 11
  • 24
  • With AS 3.6.3, after your Step 10, there is a Warning: "Multiple directories correspond to package ". We are expected to choose "Rename directory" or "Rename package". I choose "Rename package". – Zonker.in.Geneva May 18 '20 at 09:19
  • 2
    I had to manually update settings.gradle (Project Settings) after following bart's steps. – Stef May 27 '20 at 12:34
1

I think probably simpler to simply create a new project folder in your local Windows directory, rename with the name you want. Coppy all the files from within your existing (Cloning) directory and paste them directly into your new folder. Then, simply Open in Android Studio.

1

I had same question and the @bart answer helped me a lot. Nevertheless, after doing all said above, i received an error:

"Unsupported Modules Detected: Compilation is not supported for the following modules: (previousname)App. Unfortunately, you can't have non-Gradle Java modules and Android-Gradle modules in one project."

Looking around, I found this question.

So I resolved by doing what @D_Alpha suggested:

1- close the project

2- close Android Studio IDE

3- delete the .idea directory

4- delete all .iml files

5- open Android Studio IDE and import the project

The answer is taken from HERE

(version Android Studio: v.4.0)

Community
  • 1
  • 1
Marco
  • 133
  • 2
  • 13