I would like to copy my android project and create a new project form the same files just with a different name. The purpose of this is so I can have a second version of my app which is ad supported in the app store.
I found this answer here:
Android - copy existing project with a new name
But its for eclipse, how can I do this in Android Studio?
When refactoring the package name in Android Studio, you may need to click the little cogwheel up to the right by the package/android/project/etc - navigator and uncheck 'compact empty middle packages' in order to see each part of the package name as an own directory. Then for individual directories do refactor.
This should be a comment, but don't have enough points for that.
I've tried from nt.bas answer and gnyrfta answer which works well for me.
Quoting from nt.bas answer:
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 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.
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
thenRename
.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 notRename directory
.After this step, your project is now completely under the new name.
So
Build -> Clean project
thenBuild -> Rebuild project
.Up to this point you only rename your whole project name. To rename packaging name you need to follow gnyrfta answer which was described as:
When refactoring the package name in Android Studio, you may need to click the little cogwheel up to the right by the package/android/project/etc - navigator and uncheck 'compact empty middle packages' in order to see each part of the package name as an own directory. Then for individual directories do refactor.
PS: If you're having an
Just delete build folder of appmodule and Rebuild the project!
This will fix the issue!
Currently the best way to do it is without copying the project.
You can do it using diffent flavors in your
build.gradle
file.In this way you have only a copy of the files and you can handle the difference easily.
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.
Open the project you want to clone in Android Studio. (In this example, the old project name was
test5
and the new project name wastest6
)In the left file-overview pane, click: Project (where it might currently say android).
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:
Open Gradle scripts/build.gradle (Module:app) and change the line to the same line with your new project name:%fig4
As free3dom pointed out, here's what should be done
build.gradle
to change package name (you can use the file manager)AndroidManifest.xml
to change package nameThat seems to work without any problems
Go to the source folder where your project is.
->Settings.gradle
.':your new project name '