Copy existing project with a new name in Android Studio
If you use Gradle - don't forget to change applicationId attribute in app/build.gradle file.
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.
As free3dom pointed out, here's what should be done:
- Create a copy using file manager
- Manually edit the app's
build.gradle
file to change the package name (you can use the file manager). - Manually edit
AndroidManifest.xml
to change the package name. - Run
gradle sync
. - Open the project in Android Studio, and refactor the package name.
- 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:
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 toRefactor -> 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.
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 toRefactor
thenRename
.
Android Studio will give you a warning saying that multiple directories correspond to the package you are about to refactor.
Click onRename package
and notRename directory
.
After this step, your project is now completely under the new name.- Open up the res/values/strings.xml file, and change the name of the project.
- Don't forget to change your application ID in the "Gradle Build Module: app".
- 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).
SoBuild -> Clean project
thenBuild -> Rebuild project
.
Now you can run your new cloned project.