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:
- Original project folder:
- Destination project folder:
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)
<option name="PROJECT_ABSOLUTE_PATH" value="C:\Demo\before\AndroidExampleProject" />
<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)
<option name="externalProjectPath" value="C:\Demo\before\AndroidExampleProject\build.gradle" />
<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
<option name="path" value="C:\Demo\before\AndroidExampleProject\build.gradle" />
<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.