Skip to content Skip to sidebar Skip to footer

How To Force Android Studio To Use Relative Paths?

Every project created in Android Studio 1.0.2 contains several files that reference the project's own absolute path. I can't even move my own project directory if I want to, let a

Solution 1:

In general, don't consider any of the .iml files or the contents of the .idea folder to be part of the project, and don't share any of those files, don't check them into source control, and don't move them with the project. Think of them as cache files.

The Gradle files are the source of truth, so if you're having troubles with absolute paths, close the project, delete the non-shareable files, and re-import it from the Gradle build scripts.

Solution 2:

I ran into the exact same problem, but the solution suggested above contradicts JetBrains' advice as well as this answer. Also, my co-worker working from the same source code (with unexpanded paths) and Android Studio version wasn't having the problem, so I kept banging my head against the wall.

We eventually solved the problem when we realized that many of the paths I used included symlinks. In my case, I had a symlink set up for ~/work so that it pointed to /some/drive/with/space. Within Android Studio all of my source was referred to from ~/work/source rather than /some/drive/with/space/source. When I changed everything so that Android Studio referred to things with their actual paths, the $PROJECT_DIR$ and $MODULE_DIR$ variables magically started working and my .iml files were no longer getting corrupted. YMMV.

TL;DR: Don't use symlinks in your project paths!

Solution 3:

Also, be sure to not keep the files within .gradle as part of your shared project.

Also, one set of files that you might want to share though are your files under .idea/copyright though as that allows you to have shared copyright settings.

So a possible .gitignore file might be:

.gradle .idea !.idea/copyright/[YourCopyrightFile].xml !.idea/copyright/profile_settings.xml *.iml build local.properties

Solution 4:

Hmm. I just don't see the same absolute paths in those files, I only see references to MODULE_DIR and PROJECT_DIR, such as:

./app/app.iml: <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />

or:

./.idea/workspace.xml:    <entry file="file://$PROJECT_DIR$/.idea/libraries/appcompat_v7_21_0_2.xml">

I wonder if this is Linux issue only, or something in your settings?

Post a Comment for "How To Force Android Studio To Use Relative Paths?"