Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy existing project with a new name in Android Studio

People also ask

Can you rename a project in Android Studio?

First, open the project directory by right-clicking on the project name and click at show in explorer option. Step 2: Close the android studio, and go to the window explorer of the project directory and rename the root folder with a new name.

How do I add an existing project to Android Studio?

Launch Android Studio, and click File > New > Import Project. Locate your project directory, click the build. gradle file you created above to select it, and then click OK to import your project.

Can I change package name Android?

Step 1: To rename package name in Android studio open your project in Android mode first as shown in the below image. Step 2: Now click on the setting gear icon and deselect Compact Middle Packages. Step 3: Now the packages folder is broken into parts as shown in the below image.


The steps in the link you specified should also work for Android Studio. Just make a copy (using a file manager) of the entire module folder and give it a new name. Now open it up and use Refactor -> Rename (right click on the item you want to rename) to rename your module and package.

See this for details about refactoring in IntelliJ/Android Studio.


If you use Gradle - don't forget to change applicationId attribute in app/build.gradle file.


As free3dom pointed out, here's what should be done:

  1. Create a copy using file manager
  2. Manually edit the app's build.gradle file to change the package name (you can use the file manager).
  3. Manually edit AndroidManifest.xml to change the package name.
  4. Run gradle sync.
  5. Open the project in Android Studio, and refactor the package name.
  6. Run gradle sync, again.

That seems to work without any problems.


If you are using the newest version of Android Studio, you can let it assist you in this.

Note: I have tested this in Android Studio 3.0 only.

The procedure is as follows:

  1. In the project view (this comes along with captures and structure on the left side of screen), select Project instead of Android.
    The name of your project will be the top of the tree (alongside external libraries).
    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.

  2. After the copying is done, open your new project in Android Studio.
    Packages will still be under the old project name.
    That is the Java classes packages, application ID and everything else that was generated using the old package name.
    We need to change that.
    In the project view, select Android.
    Open the java sub-directory and select the main package.
    Then right click on it and go to Refactor then Rename.
    Android Studio will give you a warning saying that multiple directories correspond to the package you are about to refactor.
    Click on Rename package and not Rename directory.
    After this step, your project is now completely under the new name.

  3. Open up the res/values/strings.xml file, and change the name of the project.
  4. Don't forget to change your application ID in the "Gradle Build Module: app".
  5. A last step is to clean and rebuild the project otherwise when trying to run your project Android Studio will tell you it can't install the APK (if you ran the previous project).
    So Build -> Clean project then Build -> Rebuild project.
    Now you can run your new cloned project.

This is a combination nt.bas's answer and step 9 of Civic's answer with visual examples because it took me a while to find out what was intended since I am new to Android Studio. It has been tested in Android Studio 3.2.1.

  1. Open the project you want to clone in Android Studio. (In this example, the old project name was test5 and the new project name was test6)

  2. In the left file-overview pane, click: Project (where it might currently say android).

fig0

  1. Right mouse button click on the project within the file explorer pane and click refactor>clone.

fig1

  1. Change the "New name" to your new project name and click ok.

fig2

  1. File>open>New window>Select your new project>Open in new project window. In the new window, wait until the bottom line of Android studio is finished/says:"Gradle Sync Finished".

16

17

14

  1. In the file overview pane: right mouse button click (RMB) on: app.java/< your old project name> (not the com.example.<your old project name>(androidTest) one, not the com.example.<your old project name>(test) one, just the blank one)

fig8

  1. Enter the new name of your package and select both checkmarks, click refactor.

fig9 fig10

  1. In the bottom left bar click "Do refactor".

fig12

  1. Open app/res/values/strings.xml and change name of the old project (e.g. test5) to the new name of the project in line:

    <string name="app_name">test5</string>
    

fig3

  1. Open Gradle scripts/build.gradle (Module:app) and change the line to the same line with your new project name:%fig4

    applicationId "com.example.a.test5"

fig4

  1. A yellow line will appear at the top of your code pane, requesting gradle sync. Press "sync now".

fig5

  1. in top bar, press build>Clean project.

fig13

  1. If it says "Gradle build finished" in the bottom left, you click "Build>Rebuild project".

fig14

fig15

  1. Now you should be able to compile and run your project again (if it worked in the first place).

The purpose of this is so I can have a second version of my app which is ad supported in the app store.

Currently the best way to do it is without copying the project.
You can do it using diffent flavors in your build.gradle file.

 productFlavors {
        flavor1 {
            applicationId = "com.example.my.pkg.flavor1"
        }
        flavorAdSUpport {
            applicationId = "com.example.my.pkg.flavor2"
        }
  }

In this way you have only a copy of the files and you can handle the difference easily.


I'm following these steps and it's been working so far:

  1. Copy and paste the folder as used to.
  2. Open Android Studio (v3.0.1).
  3. Select Open an existing Project.
  4. Close the message that will pop up with title: "Import Gradle Projects".
  5. At left side on Android Tab go to: app -> java -> select the first folder (your project folder)
  6. Refactor => Rename... (Shift + F6)
  7. Rename Package, Select both options - Put the new folder's name in lowercase.
  8. Do Refactor
  9. Select: Sync Project with Gradle Files at toolbar.
  10. Build => Clean Project
  11. Go to app -> res -> values -> strings.xml, and change the app name at 2nd line.