0

I'd like to change the settings of my Android project so that the source won't be takned from [project_name]/app/src but instead I could set it to be taken from an external folder.

Project structure The reason for that is that I want my src folder to be shared, so I'd like to locate in under my Dropbox folder on my local computer.

Is there a way to change the path of the SRC folder of an android project in Android Studio? (in Eclipse it was possible)

Here is how it's done in Eclipse: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-45.htm

GyRo
  • 2,586
  • 5
  • 30
  • 38
  • "The reason for that is that I want my src folder to be shared, so I'd like to locate in under my Dropbox folder on my local computer" -- wouldn't you be better served using a version control system? There are plenty of git, Subversion, etc. hosts, or you could host a repository yourself. – CommonsWare Feb 09 '15 at 17:48
  • CommonsWare, to your question- I am working on the same projects in 2 different computers and Dropbox could synchronize the sources automatically for me. This is how I got used to work in Eclipse. – GyRo Feb 09 '15 at 21:11

2 Answers2

1

In your build.gradle add the following to the end of the android node

android {
    ....
    ....

    sourceSets {
        main.java.srcDirs += 'src/main/<YOUR DIRECTORY>'
    }

}

Refer https://stackoverflow.com/a/22028681/403255

Community
  • 1
  • 1
Vinothkumar Arputharaj
  • 4,567
  • 4
  • 29
  • 36
  • Thanks, but this is not what what I am looking for, due to 2 reasons: 1) I need to see the source files in the IDE and not only use them in the build time 2)This refers only for Java file and I'd like to move to external folder everyhing under 'src' which include all the resources in 'res' folder as well. – GyRo Feb 09 '15 at 10:18
  • 1
    This is how it's done; the IDE uses the build script to determine its project structure. There are docs for the other source directory properties in http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure – Scott Barta Feb 09 '15 at 17:25
  • I managed to set an external path for the java files by using: main.java.srcDirs = ['C:\\...'] but not for all the content of the src folder (res, menifest, etc.). I don't mind setting it in XML instead of through the GUI of Intellij but the fact that it can't be done by replacing a single line for the src path is a drawback in compare to Eclipse, in my opinion. – GyRo Feb 09 '15 at 21:05
  • @GyRo I don't know how sourcesets failed for you.It works for me. – likejudo Aug 31 '16 at 00:22
1

Found a workaround to solve this problem - since I couldn't find how to set it from Android Studio configuration, I used symlink to link the app/src folder to dropbox folder. I used this command from the command line:

c:\mklink /j "<path to my android app>\app\src" "<path to my dropbox folder>\src"

It works!
I believe that it can be relevant to anyone who wishes to sync his projects sources through any of the automatic cloud backup services, not only Dropbox. If you work as a freelance and not as part of a team, than this is good enough solution (maybe better) than the standard source control services (Git, SVN, etc.)

GyRo
  • 2,586
  • 5
  • 30
  • 38