Home ┬╗ Android ┬╗ intellij idea – How to move and rename a project in android studio?

intellij idea – How to move and rename a project in android studio?

Posted by: admin April 23, 2020 Leave a comment

Questions:

This should be a really simple question ­čÖé

I have a project that works fine. Now I wanted to rename it and to change the path of the projectfolder. First it seemd simple: right click -> “move” and “refactor/rename”.

After moving and renaming my project folder and my apk modul there was not the same project-structur as before. My project libs have been included twice.
I looked in the ‘.iml’ files and saw that the previous path was included – so I changed this. After this I could compile my project over the command line but not with the IDE. There I got this error:

NullPointerException: no project directory specified

Whats the default way to move and rename a project?
I solved my problem by making a new project and copying all files, but it would be very cool to know the solution of this “problem”.

EDIT:

Origin Project-Structure:

MyProject
--- libraries
--- MyApp

After Moving:

MyProject
--- MyProject (new path)
--- MyProject (old path)

I think I have to do more than just copy the project. Somehow I have to specify the “new” project, havn’t I?

How to&Answers:

Close the project in Android Studio (File -> Close Project). Move the project and rename it by moving its home folder/directory. Open the new project from Android Studio (File -> Open)

Answer´╝Ü

In Android studio 0.8.+, you can click F6 to move it.

If you use 1.0.2 or higher, make sure you select the Project view for the Refactor -> Move menu option to become available.

Thanks to @DavidsAlias for pointing this out.

Answer´╝Ü

Move project files as you like and then:

Tools -> Android -> Sync Project with Gradle Files

Answer´╝Ü

To move the project in your filesystem using Android Studio 1.1.0:

  • Close the project in Android Studio (File -> Close Project)
  • Move the project folder to desired location
  • Import the project into Android Studio (File -> Import Project…)

Answer´╝Ü

For Android Studio 3, it seems this should be enough:

  1. Move/rename project outside of Android Studio.
  2. Tools -> Android -> Sync Project with Gradle Files
  3. Build -> Rebuild Project

I could not deploy to the emulator after moving and renaming a project. Doing the steps above solved it.

Answer´╝Ü

In Android Studio, I found both of the following to work OK for a project which has been copied|moved|renamed.

Approach: Import

  1. Build > Clean Project
  2. File > Close Project
  3. Copy, Move, and/or Rename Folder
  4. Delete /old_name.iml (no longer needed)
  5. File > New > Import Project…

Approach: Syn Project with Gradle Files

  1. Build > Clean Project
  2. File > Close Project
  3. Copy, Move, and/or Rename Folder
  4. Delete /old_name.iml (no longer needed)
  5. File > Open
  6. Tools > Android > Sync Project with Gradle Files

Both have the same outcome.

Import is one less step. Import is conveniently located on the welcome screen and File > New menu.

Sync Project with Gradle Files is a somewhat more obscure menu item. However, Sync Project with Gradle Files is a good fallback if you click open when intending to Import.

Answer´╝Ü

This is what I do to copy/move a project. I am using Android Studio version 2.3.2

  1. Copy entire project directory to desired location
  2. Rename project directory to whatever you choose
  3. In the new project, find the workspace.xml file and manually update. Mine is located in the /.idea folder of the main project directory.
  4. When you are done changing statements in workspace.xml, start android studio and open an “Existing Project.” Select Build/Rebuild and rebuild project.

Here are some example statements that need to be changed:

<entry file="file://$PROJECT_DIR$/app/src/main/java/com/NEW_SITE_NAME/NEW_SITE_PACKAGE)/MainActivity.java">

<option name="name" value="NEW_ROOT_DIRECTORY_NAME" />

<option name="KEY_STORE_PATH" value="C:\... YOUR KEYSTORE PATH ...\keystore.jks" />

<option name="KEY_ALIAS" value="newrootdirectoryname" />

<option name="name" value="NEW_ROOT_DIRECTORY_NAME" />

There are other statements and many statements are identical. You should be able to get the idea. The key to doing this correctly is using the same naming methodology already in place in the existing workspace.xml file. If you utilize search and replace this is fairly simple process and takes only a few minutes.

Hope this helps someone!

Answer´╝Ü

For Android 3.3.2+

  1. Set your project to the project menu
  2. Select the folder name
  3. In the top menu bar Refactor > Move

Be sure to select the folder with the project name

  1. Select the directory you want to move to and confirm the move
  2. Close all projects and Import > (moved project)
  3. Uninstall the app from your device

    Important!!

  4. Turn off Instant Run to avoid the apk install process from looking for existing slices (the cache clean does not do this, apparently). This is from the SO answer here.
    File > Preferences > Build, Execution,Deployment > Instant Run > Uncheck the enabled box

  5. Top menu bar — File > Invalidate Caches / Restart (I invalidate only)

  6. Run the app
    10.You can now turn Instant Run back on in Preferences.

That should do the trick

Answer´╝Ü

In Android studio 1.5

  1. Choose the project level view hierarchy.
  2. choose the project folder example com.example.app1 and right click -> Refactor -> move… or F6.
  3. check Move package ‘com.example.app1’ to another package and it may generate warning just choose OK and enter your new path for example ‘com.hi.app2’ and click ok and it will ask for create a new folder choose ok.
  4. close project from File -> close project
  5. choose open exiting Android studio project
  6. just Delete the all old folders for example here example and app1.
  7. Clean and Rebuild project.

This will update move and rename the project path.

Answer´╝Ü

I just successfully moved my C:\ project into my portable M:\ drive.

  1. Create an Identical project in the desired file path.
  2. Open original project
  3. Find the Java files on the side bar copy them all to the clipboard.
  4. Open the “new” project
  5. Paste the files in the appropriate java folder (overwrite as needed)
  6. Do the same for your activity files, pasting them to the layout folder. (overwrite as needed).
  7. Save the new project and close the application.
  8. Launch Android Studio
  9. Open your “new” project.
  10. Android Studio will ask you to choose between the original or the Project Settings.
  11. Choose the Project settings, ignoring the default settings button.
  12. Android Studio will re-build your “new” project in the new file path destination.
  13. The Emulator will appear broken, select repair device.
  14. Run your “new” project.
  15. All should be running well. (remembering that the original is still safe and sound, launching the original will take you to step 10, choose the default settings to revert to the previous state.

I know it’s a bit of a drag, but this is the only working method I have found to move a project from one destination to another and still have a viable work product.

PS: I was searching for this query about an hour ago, with no success. After getting a positive result myself I thought I would share the result with the community… even if the thread is two years old and already marked as answered. After all, it may help the next person who is searching for a quick result, like I was.

Answer´╝Ü

What works for me:
1. Moving Project:

Close Android Studio .You can try to copy and paste the project normally. If there is Path error due to path to long. What I do normaly is compressing the project to rar file. copy paste to new location and extract It. For winrar use extract here as the actual root folder is inside the rar

2. Rename the project:

Rename the root folder to your new project name.

3. Open In Android Studio

Notice that when you open android studio, it will open the old project file by default. Close the project by going to File>Close Project. Then open your new project.

Answer´╝Ü

In my case, after moving the project to another folder what worked was:

  1. Build -> Rebuild Project
  2. File -> Invalidate Caches / Restart…