Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy and rename a project in Android Studio 3.4?

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.

like image 635
bart Avatar asked Jul 18 '19 21:07

bart


People also ask

How do I copy and rename an Android project?

Select your project then go to Refactor -> Copy... . Android Studio will ask you the new name and where you want to copy the project. Provide the same. After the copying is done, open your new project in Android Studio.

Can I duplicate a project in Android Studio?

Select Project Details under the project's thumbnail. Select the More menu. Select Duplicate.


2 Answers

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.
like image 55
bart Avatar answered Sep 22 '22 03:09

bart


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)

like image 23
Marco Avatar answered Sep 20 '22 03:09

Marco