0

I currently try to get a huge Android Studio Project to compile. My problem is that I depend on java classes in a different git repo. I fixed it by adding the repo as a submodule. I'm an absolute newbie to gradle, so my approach was to add root, where the .java files are located as a a sourceset:

  sourceSets {

    main.java.srcDirs += '../../ROOT-OF-SOURCE-FILES/'
}

This resolves the dependencies. In "ROOT-OF-SOURCE-FILES" are a bunch of files not needed for my project and this also causes gradle not to build, because there are also no android files. Next thing I tried is to point to the specific folders I depend on, but then it say "File path does not correspond to package name"

My question is how can I add the classes (including their dependencies) I need or how can I exclude the stuff I don't need (I also tried the exclude with gradle, but that didn't work).

Maiq
  • 23
  • 1
  • 3

1 Answers1

0

You can use exclude to ignore parts of your source tree, see https://discuss.gradle.org/t/how-can-i-exclude-certain-java-files-from-being-compiled/5287:

sourceSets {
  main {
    java {
      srcDirs 'main/src'
      exclude '**/package2/**'
    }
  }
}

Another option is to create a symbolic link to the one branch that you really need for Android Studio, e.g.

src/main/
        package1
        package3
        package2

linked/package1 -> src/main/package1

and

sourceSets {
  main {
    java {
      srcDirs 'linked'
    }
  }
}
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Excluding is out of scope. I tried it and it turns out that there are too many packages to exclude. Using your second option is also not working well, because if the srcDirs point to the folder, where the files are located which I really need, it will say "File path does not correspond to package name" – Maiq May 25 '16 at 11:25