Reputation: 6839
I would like to copy my Android project and create a new project from 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 it's for Eclipse. How can I do this in Android Studio?
Upvotes: 126
Views: 177845
Reputation: 2808
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 was test6
)
In the left file-overview pane, click: Project (where it might currently say android).
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)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>
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"
Upvotes: 23
Reputation: 1
The simplest way would be to upload the project files to a Github repository and cloning or downloading the repo again to your computer
Upvotes: 0
Reputation: 277
In android studio 4.1.1:
Step 1 You copy the project in the file explorer and give it a new name.
Step 2 Open the copied project in the android studio and go to the Gradle Scrips files and change the name of the project to the new name in the settings and build files.
Step 3 Go to the properties Gradle file and add the line: android.overridePathCheck=true
Upvotes: 0
Reputation: 83
Perhaps this will help someone.
For Android Studio 4.x Projects, you need following steps:
rootProject.name='newProjectName'
.Upvotes: 4
Reputation: 6703
In Android Studio 4.0
you need only these few steps:
applicationId
inside app/build.gradle
com.domain.appname
to com.domain.newappname
highlight appname
)Upvotes: 9
Reputation: 11
The EASIEST (and definitely the quickest) way to do requires WINRAR, 7zip or similar archiving software:
Find the project folder in windows explorer - double click to open this folder.
Create a new folder and name it "Backup."
While still in the project folder, select all files / folders, except the "backup" folder.
Right-click and select "add to archive" or "create archive" (command will be different depending on your archiving software)
Name the archive and click ok.
Move this archive to the "Backup" folder.
You're Done - to open the backup archive, open "Backup" folder and right-click on the backup file. Select "Extract" or create a new folder to which the files will be extracted and hit "ok" then open the project as you normally would from Android Studio, etc.
Upvotes: 1
Reputation: 95
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 is important if you need to change all parts of the package name. For example, from com.example.originalproject to org.mydomain.newproject. Otherwise, the refactor/rename operation will only let you change "originalproject" to "newproject", and it will leave "com.example" unchanged. There is a good video that shows this: https://www.youtube.com/watch?v=dMK-RBVLeIY
Upvotes: 3
Reputation: 567
As of February 2020, for Android Studio 3.5.3, the simplest answer I found is this video.
Note 1: At 01.24 "Find" tab appears below. Click "Do Refactor" and continue as in the video.
Note 2: If you have any Java/Kotlin files "Marked as Plain Text" you need to modify the package name at the top manually, i.e. package com.example.thisplaceneedstobemanuallyupdated
Note 3: Be careful about letter cases while renaming, just as in the video.
Note 4: If you want to update the project name on title bar of project window, modify rootProject.name = 'YourProjectName'
inside "settings.gradle" file under "Gradle Scripts" directory.
Upvotes: 1
Reputation: 65
Requirement and test on Android Studio 3.5
Make sure your old project working properly with your existing android studio library.
Note: if adb run showing activity not found, edit your Run/Debug Configuration. Module should point to module application e.g. app.
Upvotes: 2
Reputation: 350
Go to the source folder where your project is.
->Settings.gradle
.':your new project name '
Upvotes: 3
Reputation: 1027
If you use Gradle - don't forget to change applicationId attribute in app/build.gradle file.
Upvotes: 49
Reputation: 4936
As free3dom pointed out, here's what should be done:
build.gradle
file to change the package name (you can use the file manager).AndroidManifest.xml
to change the package name.gradle sync
.That seems to work without any problems.
Upvotes: 42
Reputation: 21
I had problems with this following:
on Android Studio version: 3.3.2
until I killed the .idea/workspace.xml file.
$ cp -rv Testcopysource/ TestCopyDest
$ rm TestCopyDest/.idea/workspace.xml
$ stdio.sh & # Run Android Studio on Linux
Prior to doing that Android Studio would still point to the original source folder and all renames were applied to the original source files (within Testcopysource in my example above).
Upvotes: 0
Reputation: 421
I'm using Android 3.3 and that's how it worked for me:
1 - Choose the project view
2 - Right click the project name, which is in the root of the project and choose the option refactor -> copy
, it will prompt you with a window to choose the new name.
3 - After step 2, Android will make a new project to you, you have to open that new project with the new name
4 - Change the name of the app in the "string.xml", it's in "app/res/values/string.xml"
Now you have it, the same project with a new name. Now you may want to change the name of the package, it's described on the followings steps
(optional) To change the name of the package main
5 - go to "app/java", there will be three folders with the same name, a main one, an (androidTest)
and a (test)
, right click the main one and choose format -> rename
, it will prompt you with a warning that multiple directories correspond to that package, then click "Rename package". Choose a new name and click in refactor. Now, bellow the code view, here will be a refactor preview, click in "Do refactor"
6 - Go to the option "build", click "Clean project", then "Rebuild project".
7 - Now close the project and reopen it again.
Upvotes: 2
Reputation: 6759
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
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.
Build -> Clean project
then Build -> 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
Failed to finalize session : INSTALL_FAILED_INVALID_APK: Split lib_slice_0_apk was defined multiple times
Just delete build folder of appmodule and Rebuild the project!
This will fix the issue!
Upvotes: 3
Reputation: 756
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
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.
Build -> Clean project
then Build -> Rebuild project
.Upvotes: 51
Reputation: 93
I'm following these steps and it's been working so far:
Upvotes: 9
Reputation: 71
When you copy your project you will also need to delete the original remnant intermediate build (someActivity$4.class) files from the C:...\AndroidStudioProjects(project_name)\app\build\intermediates\classes\release... directories. Otherwise you will almost certainly have build failures for the new project if yo attempt to compile the copied project. Refactoring won't solve this.
Upvotes: 2
Reputation: 363835
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.
Upvotes: 17
Reputation: 18978
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.
Upvotes: 81