Android Studio Bug Workaround – Project breaks when copied or moved

Since I write training courses about Android development, I frequently have to copy projects from one folder to another. I commonly create a project in a “before” folder, copy the project to an “after” folder, and then do the work being discussed in the course in the project in the “after” folder. When students view the course they can download “before” and “after” copies of the project.

Well one of the pains I’ve been dealing with in the preview release of Android Studio is the fact that when a project is copied from one folder to another, the project keeps pointers to the original folder. One ends up with a mess where some things in the new project point to the new folder and somethings point to the old. Deleting the original folder makes things even worse.

I’ve reported the issue as an Android Studio bug. It appears to have been accepted as an issue but as of this writing the version of Android Studio currently available still has the problem.

The version available as of this writing…

AndroidStudioAbout_AI-130.700763

I’m certain this is an issue that will be addressed so if you’re reading this post substantially beyond the posting date, verify that the problem still exists before doing the steps I list here.

OK so the workaround…

UPDATE: The day after I made this post, I figured out a simpler work around. Please see this post for the new workaround.

The solution I’ve found is to modify the path information contained in 4 of the project files in the destination folder.

Before doing anything, be sure Android Studio is completely closed.

Let’s make the following Assumptions in copying our project to a new folder.

  • The project name is:
    AndroidExample
  • Original project folder:
    C:\Demo\before\AndroidExampleProject
  • Destination project folder:
    C:\Demo\AFTER\AndroidExampleProject

Note: I’m including line numbers just as estimates. Your line numbers will almost definitely be different.

1. File: C:\Demo\AFTER\AndroidExampleProject\AndroidExampleProject.iml (approx. line 7)

Change:

<option name="PROJECT_ABSOLUTE_PATH" value="C:\Demo\before\AndroidExampleProject" />

To:

<option name="PROJECT_ABSOLUTE_PATH" value="C:\Demo\AFTER\AndroidExampleProject" />

2. File: C:\Demo\AFTER\AndroidExampleProject\.idea\gradle.xml (approx. line 6)

Change:

<option name="externalProjectPath" value="C:\Demo\before\AndroidExampleProject\build.gradle" />

To:

<option name="externalProjectPath" value="C:\Demo\AFTER\AndroidExampleProject\build.gradle" />

3. File: C:\Demo\AFTER\AndroidExampleProject\.idea\workspace.xml(approx. line 207)

Note: The “option” element you’re changing will be a child of the “ExternalProjectPojo” element

Change:

<option name="path" value="C:\Demo\before\AndroidExampleProject\build.gradle" />

To:

<option name="path" value="C:\Demo\AFTER\AndroidExampleProject\build.gradle" />

4. File: C:\Demo\After\AndroidExampleProject\AndroidExample\AndroidExample.iml(approx. line 15)

Change:

<option name="PROJECT_ABSOLUTE_PATH" value="C:\Demo\before\AndroidExampleProject" />

To:

<option name="PROJECT_ABSOLUTE_PATH" value="C:\Demo\AFTER\AndroidExampleProject" />

5.
Now open the project in Android Studio

You may be prompted with a dialog indicating that it’s removing a non-existent project. Let it do that. It’s just cleaning up some internal data, it doesn’t appear to have any impact on the original project.

Voila! We now have a copy of our project.

The best news of all … I’m pretty sure that the bug that’s causing us to have to go through all of these steps (rather than simply copying the project folder) is a bug that will soon be fixed.

For information on getting started developing Android applications or working with Android Studio, checkout Jim’s Android programming courses on Pluralsight including his latest course.

Android for .Net Developers Series - Getting Started

Advertisements

4 thoughts on “Android Studio Bug Workaround – Project breaks when copied or moved

  1. Pingback: Android Studio Bug Workaround V2 – Project breaks when copied or moved | hedgehogjim

  2. Thanks for the pointers. I can confirm that this issue still exists in Android Studio 1.1.0. I moved a project from one computer to a flash drive and it still held the pointers to the machine of origin. I hope they fix this soon and make it machine-independent!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s