Android Studio Project Cloning

Thread Starter

MrAl

Joined Jun 17, 2014
11,396
Hi,

Recently i was trying to clone a project in AS and it's very difficult. I followed the directions i found on the web but they dont work.
They say to use "refactor" and it does do something but does not clone the project because the apk file still loads into Android as the same project name and thus takes over the original project that was already installed.
For example, say i create a project "Proj004", and add some components and code. I then load it into a cell phone and it shows up with a little icon and the name under it "Proj004".
Now i use "refactor" and if i remember right that does make a new project but the name stays the same even though it shows a new name with the old name. What happens is say i import as "Proj005". It will show "Proj005" as the source but will still show "Proj004" in the title bar. Now ignoring the title bar i buld the project, but then i load it into the phone it acts like an "update" to Proj004 and so it takes over the original Proj004 and thus there is no new project icon or name that is supposed to show up as Proj005.

So "refactor" does not actually work completely by itself.
I was able to change some other things but it was hackaday and i dont remember exactly what i changed to get it to do an actual new project.
So i was wondering if there is some written procedure for cloning that actually works entirely, not just part way.

Thanks.

PS
I wrote a Windows program that searches the entire project directory and found that there are literally thousands of entries with the name "Proj004" in them including files and some directories and many many lines of code within files. So there must be a lot that has to be changed to get a new project from an old one.
 

BobaMosfet

Joined Jul 1, 2009
2,110
Sadly, this is one of the problems with Google (amateurs & hacks) producing products they know nothing about how to actually, properly, design. Cloning projects has been broken since the beginning, and frankly one of the main reasons I stopped writing for Androids.
 

atferrari

Joined Jan 6, 2004
4,764
Sorry BM, your comment does not justify the existence of so many with the same name.

Hoy refactoring and cloning do go along here?

And BTW, what actually cloning is, in this context?

Maybe my questions could go in reverse order...
 

Thread Starter

MrAl

Joined Jun 17, 2014
11,396
Hi,

Cloning means copying the entire project which you then call by another name so you can start a new project where you left off in the old one.
So say you have a project "Mine001" and then you clone it and call it "Mine002".
Now if you had one view and three buttons in Mine001 you now have the same in Mine002.
The difference is now you can modify Mine002 without messing up Mine001, and another reason for doing a clone is so that you dont have to start from scratch with a new project you want to do, you just clone an old one that is close to what you want to start with in the new project.

Refactoring is what they are calling cloning or just changing the name of a project and possibly all the directories that go with it.
So if you load your project into a cell phone and it tells you it is "Mine001" then when you refactor to Mine002 it willl now load as Min002 and leave the old app Mine001 alone. Otherwise it would update Mine001. It does not work however.

The problem i was having was even if i copied all the directories to a new root directory it would still see it as Mine001 so it would only be able to update the old app not create a new one when i went to load into the phone.

Refactoring however, does not work. It does not create a new project it just renames some things and then it may not even build after that, that's how bad it is.

I managed to clone a project for real though, but i had to modify things by hand too and i cant remember all the steps i took.
I guess i will have to try again and this time keep track of what i was changing so i could do it again next time.
 

Thread Starter

MrAl

Joined Jun 17, 2014
11,396
Hello again,

Ok i think i did this, because i just did another clone and it seems to work...
This example takes myapplication001 and makes a clone called myapplication002
and note all the text case is exactly as shown here (no caps where caps are not shown).

First you copy the entire project directory and rename that directory:
"MyApplication001_Copy(1)" to "MyApplication002".

Then open the IDE and import the project. This is a little tricky because the new directory
does not show up in the menu for import. Thus you have to type it in
and import, then close the project then close the IDE then repopen the IDE
then the project which may have the old name and the new name in the menu
that comes up when you first open the IDE. It changes later to the correct
names. Ignore any red line errors indicators.

Once open again, use menu 'refactor/rename' app/java/com.example.myapplication001
to: app/java/com.example.myapplication002
by right clicking on 'com.example.myapplication001' and click "refactor" then "rename" then
by clicking "rename project" entering in that text "myapplication002"
and check all the boxes then click "refactor".

Then go into: app/manifests/AndroidManifest.xml and change this line:
package="com.example.myapplication001">
to:
package="com.example.myapplication002">

Then go into tree item: Gradle Scripts/settings.gradle (Project Settings)
and change (note the use of single quotes here) this line:
rootProject.name='My Application 001'
to:
rootProject.name='My Application 002'

Close the project.
Close the IDE.
Reopen the IDE and see that the right names for the project show up in the IDE project menu and that once you open it the project gets pseudo built.
After that you can modify code and build to debug or release as usual.

By "pseudo built" i mean the IDE starts to sync the project so you can view
your preview, and it may also build a debug version but im not sure about that
part of it.
 
Last edited:

nsaspook

Joined Aug 27, 2009
13,086
Hi,

Cloning means copying the entire project which you then call by another name so you can start a new project where you left off in the old one.
So say you have a project "Mine001" and then you clone it and call it "Mine002".
Now if you had one view and three buttons in Mine001 you now have the same in Mine002.
The difference is now you can modify Mine002 without messing up Mine001, and another reason for doing a clone is so that you dont have to start from scratch with a new project you want to do, you just clone an old one that is close to what you want to start with in the new project.

Refactoring is what they are calling cloning or just changing the name of a project and possibly all the directories that go with it.
So if you load your project into a cell phone and it tells you it is "Mine001" then when you refactor to Mine002 it willl now load as Min002 and leave the old app Mine001 alone. Otherwise it would update Mine001. It does not work however.

The problem i was having was even if i copied all the directories to a new root directory it would still see it as Mine001 so it would only be able to update the old app not create a new one when i went to load into the phone.

Refactoring however, does not work. It does not create a new project it just renames some things and then it may not even build after that, that's how bad it is.

I managed to clone a project for real though, but i had to modify things by hand too and i cant remember all the steps i took.
I guess i will have to try again and this time keep track of what i was changing so i could do it again next time.
This why 'git' revision control (and other systems) was invented, to reduce the need to clone and copy source files during software development. You can start with a original source (from any source), create a new branch, modify it to your hearts content with every change tracked, merge or cherry pick the differences back into another possible 'Master' branch. Using remote git servers you can pull complete projects, the work in progress and/or push project updates that can be retrieved from anywhere on the planet linked to the same base source tree.

https://code.tutsplus.com/tutorials/working-with-git-in-android-studio--cms-30514
 
Last edited:

Thread Starter

MrAl

Joined Jun 17, 2014
11,396
This why 'git' revision control (and other systems) was invented, to reduce the need to clone and copy source files during software development. You can start with a original source (from any source), create a new branch, modify it to your hearts content with every change tracked, merge or cherry pick the differences back into another possible 'Master' branch. Using remote git servers you can pull complete projects, the work in progress and/or push project updates that can be retrieved from anywhere on the planet linked to the same base source tree.

https://code.tutsplus.com/tutorials/working-with-git-in-android-studio--cms-30514
Hi,

Looks interesting just not sure i like having my project on someone else's server.
Have to give this some thought.
 

nsaspook

Joined Aug 27, 2009
13,086
Hi,

Looks interesting just not sure i like having my project on someone else's server.
Have to give this some thought.
You don't need to put it up on a server to have the revision control branch capability. It's very useful to try things locally on a new branch of your code with the option to checkout the original version and start a new branch and then the fold in the working changes from your experimental branch all while having one core set of code files.
 
Top