How to clone a project in Android Studio

- Andrés Cruz

En español
How to clone a project in Android Studio

A fairly common process when developing software is that at some point we want to clone it to quickly and easily reuse its components, in PHP it is easy, we just have to copy and paste the project, rename the root folder, change the configurations of the path, maybe the database and we're pretty much ready to start working with our copied or cloned project.

In Android Studio, this cloning is not so simple; So if we want to open, for example, an android studio project on another computer or reinstall our Android Studio or something like that, we must perform some of the previous steps and copy certain key sections of the source project (project to copy) into our new project (project to copy). destination or cloned) and performing some extra steps.

Creating the target/cloned project in Android Studio

The first difference between copying and pasting that we would do with a PHP project is that we must first create a new project in Android Studio by doing the traditional steps:

File - New - New Project

Very pending with the name of the package or package which you can obtain from the AndroidManifest of the project which we will use later.

And this newly created project would be our target project.

Once our destination project has been created, the best thing we can do is close Android Studio to avoid any generation of a process by it to the base project or blocking a file that we want to replace.

Now we must replace the key files, first the application resources which are in the folder:

/app/src/main

We copy them from the project to be cloned to our destination or base project.

Now we go with the libraries in case they exist, we copy and paste them:

Copy /app/libs

Like these two files:

 

Override /build.gradle Override /gradle.properties

And the folder:

Override /gradle/wrapper

And of course, the AndroidManifest.xml:

Replace /app/src/main/AndroidManifest.xml

We are almost done, now we can open our Android Studio together with the base project to which we copied all the sources.

Surely it will give many errors, for the moment do not worry, first we must replace the name of the package with that of our new project (destination project) in each of the files including our manifest, for this we use the combination CONTROL + SHIFT + R and a window will open in which we must copy indicate the text to replace:

remplace in Path

Then we go to the grandle file and synchronize it.

Now from the menu of our Android Studio:

Build -> Clean Project Build -> Rebuild Project

If everything went well, we would already have our project cloned. In case there is an error, it is likely that you need to copy some more file or folder that you created manually in the destination project.

In summary:

Create a project Replace /app/src/main Copy /app/libs Replace /app/src/main/AndroidManifest.xml Replace /app/build.gradle Replace /build.gradle Replace /gradle.properties Replace /gradle/wrapper Replace the package name Build -> Clean Project Build -> Rebuild Project

The order in which you want to replace the source files to the destination is up to you and logically does not influence anything.

Andrés Cruz

Desarrollo con Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz en Udemy

Acepto recibir anuncios de interes sobre este Blog.