Android Studio 0.3.4 doesn't have 'mark directory as' anymore?

7,660 views
Skip to first unread message

David Laurell

unread,
Nov 9, 2013, 8:02:30 AM11/9/13
to adt...@googlegroups.com
Hi,

Up until now we could mark different directories as test source root so we would get auto complete stuff in junit test classes. Now this option seems to have disappeared.

I'm using the gradle-android-test-plugin to write unit tests with Robolectric. The tests are put in src/main/test and we could do the following hack to get Android Studio to resolve the dependencies in the test classes:

    testCompile 'junit:junit:4.10'
    testCompile 'org.robolectric:robolectric:2.1.+'
    testCompile 'com.squareup:fest-android:1.0.+'

    //Used for Android Studio so it finds the references
    instrumentTestCompile 'junit:junit:4.10'
    instrumentTestCompile 'org.robolectric:robolectric:2.1.+'
    instrumentTestCompile 'com.squareup:fest-android:1.0.+'

I would rather that Android Studio could resolve the testCompile dependencies and mark junit directories as test source roots too. Then we can have both instrumentTests on a device and running local junit tests out of the box!

Anyone have any solutions for this?

Scott Barta

unread,
Nov 11, 2013, 1:21:23 PM11/11/13
to adt...@googlegroups.com
In this release we removed UI for features that aren't supported by Gradle (when working with Gradle-based projects). The "Mark Directory As" menu was one of those. We're working on getting the dependency scopes to mark folders correctly in Android Studio, but until that's fixed there's no workaround that I'm aware of.


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jürgen Cruz

unread,
Nov 14, 2013, 11:03:32 AM11/14/13
to adt...@googlegroups.com
I too would like this feature back. I know marking directories as source will not change the gradle build file but the thing is I have a custom plugin that registers more sourcesets which obviusly AS won't catch but at least before I could use this feature so the IDE would understand.

Also, since you changed the project structure window I can't set up libraries and things which my custom plugin uses. I have to manually edit the iml file and keep it under Version control to restore it everytime I load the project. Is annoying.

Brian Parent

unread,
Nov 14, 2013, 2:15:50 PM11/14/13
to adt...@googlegroups.com
Same here - I have multiple source sets and I'm using Jake Whartons plugin to run regular junits - this is making developing in those separate source folders a real pain.

Adam Brown

unread,
Nov 19, 2013, 2:57:28 PM11/19/13
to adt...@googlegroups.com
Ah ya this is a pain. Without the exclude option, things like the find symbol function also search in the build/ dir and you get results from .class files. We really need a way to hide & ignore bin & build.

Scott Barta

unread,
Nov 19, 2013, 3:05:56 PM11/19/13
to adt...@googlegroups.com
Find Symbol isn't searching build/ for me. Can you file a bug with a reproducible case?

One of our goals in removing the option is to understand what folks were using it for, and if it's to work around bugs, we'd much prefer to just fix the bugs.


--

James Landrum

unread,
Nov 19, 2013, 4:16:42 PM11/19/13
to adt...@googlegroups.com
I tried to add the Assets folder and it created it as a source folder. While fundamentally, there's hardly a difference (Especially when Gradle ignores this), it does make working with it as if it were a folder a little wonky. 

I also noticed that creating a test folder used to automatically mark it as a test folder, shouldn't AS pick up on this and not have made it a source folder?

Adam Brown

unread,
Nov 19, 2013, 4:19:40 PM11/19/13
to adt...@googlegroups.com
Sorry I meant the open file dialog, so (using the Eclipse shortcut binding) I do Ctrl + Shift + R, begin type the class name to open it's file, and both the .java and .class files come up in the results.

Also, it's just kind of nice to only see the things we are actually interested in in the project browser: src, res, assets, ect.


--
You received this message because you are subscribed to a topic in the Google Groups "adt-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adt-dev/v0AluPBcoy0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adt-dev+u...@googlegroups.com.

Jürgen Cruz

unread,
Nov 19, 2013, 4:40:33 PM11/19/13
to adt...@googlegroups.com
In my case, Is not a bug per se, is just that AS will only pick sourceSets made from android plugin. if AS could pick any sourceSet and configurations then I wouldn't need the mark directory as function.

I would also like to see if the location of *.iml files can be configurable or something. right now, 3 of my apps depend on a common library project and everytime I open one of the app projects it overwrites parts of the iml file which I have under version control and is annoying. I would lke a copy of the library iml file in each app project so they change only their copies avoiding conflicts.

Siva Velusamy

unread,
Nov 19, 2013, 6:06:40 PM11/19/13
to adt...@googlegroups.com
On Tue, Nov 19, 2013 at 1:16 PM, James Landrum <thyme....@gmail.com> wrote:
> I tried to add the Assets folder and it created it as a source folder. While
> fundamentally, there's hardly a difference (Especially when Gradle ignores
> this), it does make working with it as if it were a folder a little wonky.

Could you expand on what is wonky about this?

>
> I also noticed that creating a test folder used to automatically mark it as
> a test folder, shouldn't AS pick up on this and not have made it a source
> folder?

src/test/java, src/instrumentTest/java should be automatically marked
as test source folders. You should be able to customize those in your
build.gradle (http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure).
When you import a project, the folders specified by your build.gradle
should be appropriately marked.

Is that not the case? If so, could you please file a bug.

Scott Barta

unread,
Nov 19, 2013, 6:21:36 PM11/19/13
to adt...@googlegroups.com
I still can't reproduce problems with Open File and seeing both .java and .class names. A reproducible bug with screenshots would help us out a lot.

Scott Barta

unread,
Nov 19, 2013, 6:26:12 PM11/19/13
to adt...@googlegroups.com
We really want the Gradle build files to be the sole source of truth for project structure. We strongly discourage you from treating .iml files as part of the project that should be checked into source control.



On Tue, Nov 19, 2013 at 1:40 PM, Jürgen Cruz <supe...@gmail.com> wrote:
In my case, Is not a bug per se, is just that AS will only pick sourceSets made from android plugin. if AS could pick any sourceSet and configurations then I wouldn't need the mark directory as function.

I would also like to see if the location of *.iml files can be configurable or something. right now, 3 of my apps depend on a common library project and everytime I open one of the app projects it overwrites parts of the iml file which I have under version control and is annoying. I would lke a copy of the library iml file in each app project so they change only their copies avoiding conflicts.

--

Adam Brown

unread,
Nov 19, 2013, 6:32:34 PM11/19/13
to adt...@googlegroups.com
Scott, I can get you a repro when I get home from my personal projects.

Adam Brown

unread,
Nov 19, 2013, 7:08:20 PM11/19/13
to adt...@googlegroups.com
"We really want the Gradle build files to be the sole source of truth for project structure." <- that sounds fantastic


--
You received this message because you are subscribed to a topic in the Google Groups "adt-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adt-dev/v0AluPBcoy0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adt-dev+u...@googlegroups.com.

Xavier Ducrohet

unread,
Nov 20, 2013, 1:00:52 PM11/20/13
to adt...@googlegroups.com
For those using the Robolectric plugin, we hear your pain. I'd like to make the current plugin extensible enough so that we can have additional sourcesets added by other plugins.

We're going to need to add more sourcesets ourselves anyway (ui automator, lint), so we'll have to figure out how to do this soon.

--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Roman Mazur

unread,
Nov 20, 2013, 2:21:50 PM11/20/13
to adt...@googlegroups.com
>src/test/java, src/instrumentTest/java should be automatically marked 
src/test/java is not marked in my project

Roman Mazur

unread,
Nov 20, 2013, 2:26:47 PM11/20/13
to adt...@googlegroups.com
>We're going to need to add more sourcesets ourselves anyway (ui automator, lint), so we'll have to figure out how to do this soon.
Awesome. And some means for adding custom generated sources (like what plugin puts into build/source directories) would be great too.

Xavier Ducrohet

unread,
Nov 20, 2013, 2:32:38 PM11/20/13
to adt...@googlegroups.com
Siva misspoke. src/test/java is not currently marked as a source folder because the current plugin doesn't use this folder at all.

Jürgen Cruz

unread,
Nov 20, 2013, 2:36:16 PM11/20/13
to adt...@googlegroups.com
Xavier, It would be good to be able to add sourceSets to the android plugin. But actually, I made a custom plugin for robolectric which simply uses the JavaPlugin sourceSets. I can access them from the build file like this:

gradle.projectEvaluated {
  sourceSets.each { set ->
    //Do something with the sourceSet
  }
}

Which means that they are available even if out of Android plugin. Can't Android Studio read this sourceSets? I mean, while you make the android plugin extensible. this could be a solution.

Also I add different Configurations for different dependencies like testCompile, testDebugCompile, testFlavorCompile. And I think this configurations can also be accessed quite easily as well. can't this configuration be read and then add the dependencies to the iml file or something?

Siva Velusamy

unread,
Nov 20, 2013, 2:42:48 PM11/20/13
to adt...@googlegroups.com
On Wed, Nov 20, 2013 at 11:32 AM, Xavier Ducrohet <x...@android.com> wrote:
> Siva misspoke. src/test/java is not currently marked as a source folder
> because the current plugin doesn't use this folder at all.

Sorry, what I meant was:

In an android app/library (build.gradle says "apply plugin:
'android'"), src/instrumentTest/java should be automatically marked as
a test root.
For a java module (build.gradle has "apply plugin: 'java'"),
src/test/java will be automatically marked as a test root.

Xavier Ducrohet

unread,
Nov 20, 2013, 2:55:08 PM11/20/13
to adt...@googlegroups.com
The problem is that we don't consider Android project to be java project, so we only read our model. I don't think we want to read both, but we could read the normal source set and pass them in our model.

Ultimately we're going to change the way we handle sourcesets once we can reuse the default one. There's some work that's been done by Gradleware to allow this but it's not there yet AFAIK. When that happens I'm not sure you'll be able to use them as is.

anyway, as I said we're aware of it and want to make it possible to have a custom plugin use different source sets.


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Xavier Ducrohet

unread,
Nov 20, 2013, 2:55:16 PM11/20/13
to adt...@googlegroups.com
Yeah that's a good idea.


On Wed, Nov 20, 2013 at 11:26 AM, Roman Mazur <mazur...@gmail.com> wrote:
>We're going to need to add more sourcesets ourselves anyway (ui automator, lint), so we'll have to figure out how to do this soon.
Awesome. And some means for adding custom generated sources (like what plugin puts into build/source directories) would be great too.

--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Sara Haider

unread,
Nov 21, 2013, 12:39:04 AM11/21/13
to adt...@googlegroups.com
I'm having the same problem except with different build variants. Android Studio detects some variants as source sets and others as not. The variants in the same project are being detected differently on my machine and my co-workers'. This used to be easily resolved with Mark Directory As... but now we have no way :(

In this situation, it everything is an android plugin; we don't have java plugins, yet we are still facing this problem.

Please help :(

Jonas Bengtsson

unread,
Nov 21, 2013, 1:04:14 PM11/21/13
to adt...@googlegroups.com
Good to hear that you're working on it. Is there an issue to star on b.android.com regarding this? (I didn't find one)

Cheers,
 Jonas

Jake Wharton

unread,
Nov 21, 2013, 1:11:11 PM11/21/13
to adt...@googlegroups.com
Only one variant is enabled at a time leaving the others to exist merely as normal folders. Are you saying that when switching which variant is enabled it doesn't add all of the folders for that variant and disable all of the ones for the other variants?

David Jeffrey

unread,
Nov 22, 2013, 11:36:59 AM11/22/13
to adt...@googlegroups.com
For the minute as a temporary fix I'm just opening up my .iml file and dropping this in every time AS stops marking it as a source file:

      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />

Which makes AS pick it up just fine.

Bernd Bergler

unread,
Nov 22, 2013, 1:37:15 PM11/22/13
to adt...@googlegroups.com
I created a custom gradle task which inserts the test directly into the iml file.
its quite a hack but it works ;)

task addTest() {

  def src = ['src/test']
  def  file = file("Project.iml")

  doLast{
    def parsedXml = (new XmlParser()).parse(file)
    def node = parsedXml.component[1].content[0]
    src.each{
      def path = 'file://$MODULE_DIR$/'+"${it}"
      def set =  node.find { it.@url == path}
      if( set == null) {
        new Node(node, 'sourceFolder', [ 'url' :'file://$MODULE_DIR$/'+"${it}", 'isTestSource':"true"])
        def writer = new StringWriter()
        new XmlNodePrinter(new PrintWriter(writer)).print(parsedXml)
        file.text = writer.toString()

Adam Brown

unread,
Nov 22, 2013, 6:18:19 PM11/22/13
to adt...@googlegroups.com
The Gradle project structure editor needs a place to select the Java language level target. I'm having trouble convincing AS that I really am compiling Java 1.7 and thus should be allowed to use multi-catch...


--
You received this message because you are subscribed to a topic in the Google Groups "adt-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adt-dev/v0AluPBcoy0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adt-dev+u...@googlegroups.com.

Jürgen Cruz

unread,
Nov 22, 2013, 6:48:25 PM11/22/13
to adt...@googlegroups.com
You can simply put this

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

And android studio automatically sets it to JDK7

Scott Barta

unread,
Nov 22, 2013, 6:49:03 PM11/22/13
to adt...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.

David Jeffrey

unread,
Nov 24, 2013, 7:32:29 PM11/24/13
to adt...@googlegroups.com
It's a nasty hack but I wrote a little Python script: https://gist.github.com/david-theappchaps/7634471#file-keeptestsrc-py that monitors the .iml file and inserts the tag to mark src/test/java as a test source folder whenever it discovers it's missing. AS picks the change up without having to manually refresh anything so it's convenient, if ugly, in case anyone finds it useful.

Olexandr Tereshchuk

unread,
Dec 27, 2013, 6:35:49 AM12/27/13
to adt...@googlegroups.com
Can this issue be solved with new 0.7.3 android gradle plugin ?

Понеділок, 25 листопада 2013 р. 02:32:29 UTC+2 користувач David Jeffrey написав:

Renzo Fernando Crisóstomo Medina

unread,
Jan 8, 2014, 8:57:21 AM1/8/14
to adt...@googlegroups.com
Your task is amazing! Thanks! Are you running it manually or setting it as a dependency for another task called by the IDE?

Mozart Petter

unread,
Jan 8, 2014, 8:59:25 PM1/8/14
to adt...@googlegroups.com
Hey Renzo,
I'm using it, and on my setup I just set a dependency on the build task for it:

task addTest(dependsOn: 'build') {
...
}

It works fine. :)

Nate Bourgoin

unread,
Mar 18, 2014, 12:31:46 PM3/18/14
to adt...@googlegroups.com
Mozart, this looks super similar to https://github.com/sababado/gradle-android-add-dir

In both cases, it works for just a moment the reverts its status. Is this working on the Android Studio 0.5 / android gradle plugin 0.9?

Jeremiah Bargar

unread,
Apr 17, 2014, 11:47:19 AM4/17/14
to adt...@googlegroups.com
I see this in Find in Path as well. When I use that feature, I immediately have to collapse all the build directories in order to get to the real results. Big pain.

This on Android Studio 0.5.3 with a basic Android project structure.


On Tuesday, November 19, 2013 4:19:40 PM UTC-5, Adam Brown wrote:
Sorry I meant the open file dialog, so (using the Eclipse shortcut binding) I do Ctrl + Shift + R, begin type the class name to open it's file, and both the .java and .class files come up in the results.

Also, it's just kind of nice to only see the things we are actually interested in in the project browser: src, res, assets, ect.
On Tue, Nov 19, 2013 at 12:05 PM, Scott Barta <sba...@google.com> wrote:
Find Symbol isn't searching build/ for me. Can you file a bug with a reproducible case?

One of our goals in removing the option is to understand what folks were using it for, and if it's to work around bugs, we'd much prefer to just fix the bugs.
On Tue, Nov 19, 2013 at 11:57 AM, Adam Brown <adamw...@gmail.com> wrote:
Ah ya this is a pain. Without the exclude option, things like the find symbol function also search in the build/ dir and you get results from .class files. We really need a way to hide & ignore bin & build.


On Saturday, November 9, 2013 5:02:30 AM UTC-8, David Laurell wrote:
Hi,

Up until now we could mark different directories as test source root so we would get auto complete stuff in junit test classes. Now this option seems to have disappeared.

I'm using the gradle-android-test-plugin to write unit tests with Robolectric. The tests are put in src/main/test and we could do the following hack to get Android Studio to resolve the dependencies in the test classes:

    testCompile 'junit:junit:4.10'
    testCompile 'org.robolectric:robolectric:2.1.+'
    testCompile 'com.squareup:fest-android:1.0.+'

    //Used for Android Studio so it finds the references
    instrumentTestCompile 'junit:junit:4.10'
    instrumentTestCompile 'org.robolectric:robolectric:2.1.+'
    instrumentTestCompile 'com.squareup:fest-android:1.0.+'

I would rather that Android Studio could resolve the testCompile dependencies and mark junit directories as test source roots too. Then we can have both instrumentTests on a device and running local junit tests out of the box!

Anyone have any solutions for this?

--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Cheng Yang

unread,
Apr 21, 2014, 1:54:22 PM4/21/14
to adt...@googlegroups.com
I noticed the approach stopped working in Android Studio 0.5.5
The directory are test when the project start to sync, but somehow reverted later, 
Reply all
Reply to author
Forward
0 new messages