如何强制Android Studio中使用相对路径? [英] How to force Android Studio to use relative paths?

查看:3680
本文介绍了如何强制Android Studio中使用相对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android Studio中创建1.0.2每个项目包含引用项目自身的绝对路径的几个文件。 我不能即使我想,更遑论与其他开发人员共享项目移到我自己的项目目录。

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 alone share the project with other developers.

撇除文件应用程序/构建,这些都含绝对路径的文件:

Excluding files in app/build, these are the files containing absolute paths:

.idea/workspace.xml
.idea/modules.xml
.idea/libraries/support_v4_21_0_3.xml
.idea/libraries/appcompat_v7_21_0_3.xml
.idea/gradle.xml
.gradle/2.2.1/taskArtifacts/taskArtifacts.bin
.gradle/2.2.1/taskArtifacts/fileSnapshots.bin
app/app.iml

如何强制Android Studio中使用相对路径的一切?

How do I force Android Studio to use relative paths for everything?

修改:通过与香草IDEA试验,我这绝对路径的起源缩小到特定类型的模块,其中Android的工作室似乎总是使用没有为你提供一个选择。但我还是没有更进一步地理解如何消灭它们。

Edit: By experimenting with vanilla IDEA, I've narrowed down the origin of these absolute paths to a specific type of module, which Android Studio apparently always uses without offering you a choice. But I'm still no closer to understanding how to eradicate them.

在IDEA 14.0.2,如果你创建一个空的项目或Android项目与应用模块,该项目不包含任何绝对路径。如果创建一个摇篮:Android的模块项目,那么它包含了相同的文件作为一个Android Studio项目的绝对路径

In IDEA 14.0.2, if you create an empty project or an Android project with an "Application Module", the project does not contain any absolute paths. If you create a project with a "Gradle: Android Module", then it contains absolute paths in the same files as an Android Studio project.

编辑#2: IDEA-134587

推荐答案

我碰到了相同的问题,但上述相矛盾的 JetBrains公司的意见以及<一个href=\"http://stackoverflow.com/questions/16736856/what-should-be-in-my-gitignore-for-an-android-studio-project\">this回答。此外,我的同事从同一来源$ C ​​$ C工作(含未展开路径)和Android Studio版本并没有遇到的问题,所以我一直敲我的头撞在墙上。

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.

我们终于解决了问题的时候,我们意识到许多的路径我用附带的符号链接。就我而言,我有一个符号链接设置为〜/工作,使其指向/ 部分/驱动器/带/空间。在Android的工作室我所有的源从简称〜/工作/源,而不是 /一些/驱动器/带/空间/源。当我改变了一切,让Android Studio中提到的东西与他们的实际路径,在 $ PROJECT_DIR $ $ MODULE_DIR $ 变量奇迹般地开始工作,我.iml文件不再得到破坏。情况因人而异。

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:不要使用符号连接在你的项目路径

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

这篇关于如何强制Android Studio中使用相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆