Android Studio Bug Workaround V2 – Project breaks when copied or moved

As you’ll recall, I posted yesterday about working around the issue in Android Studio where copying a project to a new folder creates problems because the Android Studio project keeps references to the original folder. After my post yesterday, I figured out an easier way to work around the problem.

You still have to modify just as many files but the steps are easier to follow and perform than my suggestion from yesterday.

So the new workaround…

We’ll use the same assumptions as yesterday.

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

The cool thing about this workaround is that after copying the project to the folder, you always make the same (relatively simple) changes. There’s nothing specific about the destination folder in the changes we make.

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

Be sure that Android Studio is completely closed.

In both of the following files, change the value for PROJECT_ABSOLUTE_PATH to be blank

  • C:\Demo\AFTER\AndroidExampleProject\AndroidExampleProject.iml (approx. line 7)
  • 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="" />

In both of the following files remove the full path before build.gradle (including the slash ” \ “) and replace it with $PROJECT_DIR$/

  • 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="$PROJECT_DIR$/build.gradle" />
  • C:\Demo\AFTER\AndroidExampleProject\.idea\workspace.xml (approx. line 207)
    • 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="$PROJECT_DIR$/build.gradle" />

And with that, you’re ready to open the destination project in Android Studio.

When you save the project, Android Studio will automatically save the new folder as the PROJECT_ABSOLUTE_PATH value.

I’m finding these changes much easier to manage than the ones I walked through yesterday. But as I mentioned yesterday, the best news of all is that I suspect that this will be a short lived bug and we won’t have to deal with this workaround for long.

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

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

      • Hi Pete – yea I was kind’a bummed to see that. FWIW: I reported the bug via the standard bug channel and they’ve just recently asked me for more info on it. Hopefully, that means it’ll be addressed soon.

  1. The trick is, not to chose “Open existing project”, but to “import existing project” in android studio 🙂 And then all paths are automatically updated 🙂

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