15

I have following directory structure:

D:\PROJECT  
+---javaGradleProject1  
+---javaGradleProject2  
+---javaGradleProject3  
\---AndroidProject  
    |   build.gradle
    |   settings.gradle
    \---AndroidModule
            build.gradle

Android module depends on all of java gradle projects that are at the same level in root directory as AndroidProject.

In AndroidProject/settings.gradle I have:

include ':AndroidModule'

include 'javaGradleProject1'
project(':javaGradleProject1').projectDir = new File(rootDir, '../javaGradleProject1')

include 'javaGradleProject2'
project(':javaGradleProject2').projectDir = new File(rootDir, '../javaGradleProject2')

include 'javaGradleProject2'
project(':javaGradleProject2').projectDir = new File(rootDir, '../javaGradleProject2')

And then in AndroidProject/AndroidModule/build.gradle I have dependencies set like this:

compile project(':javaGradleProject1')
compile project(':javaGradleProject2')
compile project(':javaGradleProject3')

This structure of dependency perfectly works and project builds when I invoke

gradle build

on AndroidProject/build.gradle.

But when I try to synchronize my IntelliJ with current gradle dependency settings I receive

Error: Unable to find module with Gradle path ':javaGradleProject1'
Error: Unable to find module with Gradle path ':javaGradleProject2'
Error: Unable to find module with Gradle path ':javaGradleProject3'

and because of that my project cannot be run from Run Configurations (it does not compile at all in IDE). I was trying to add these dependencies manually by hitting F4 and module dependencies but after synchronization all of my changes are overwritten (actually, IntelliJ just removes it).

Is there anything wrong in my gradle structure?

I have tested it on IntelliJ IDEA 14.1.4 and Android Studio 1.3.

P. Grosicki
  • 151
  • 1
  • 3

6 Answers6

19

I was able to solve this by deleting the settings.gradle file from every Gradle project that I wanted to use as dependency (clearing the contents of this file was not enough).

NOTE: As I have little knowledge of Gradle and Android Studio, I cannot provide information about why the presence of this file does not allow Android Studio to include the Gradle project as a module.

Alex Barceló
  • 322
  • 2
  • 6
1

Add a colon (:) before the names of your modules when you add it in settings.gradle, e.g. for the first one, change this:

include 'javaGradleProject1'
project(':javaGradleProject1').projectDir = new File(rootDir, '../javaGradleProject1')

to this:

include ':javaGradleProject1'
project(':javaGradleProject1').projectDir = new File(rootDir, '../javaGradleProject1')

Now in addition to compiling, IntelliJ / Android Studio should give you code completion.

Aralox
  • 1,441
  • 1
  • 24
  • 44
1

In my case I had to change the external module name to lowercase only.

0

Right click project, Select

"Configure Project Subset ..."

and select your module, rebuild your project.

Varun Bhatia
  • 4,326
  • 32
  • 46
  • I don't see this option in the context menu when I right click on my project. Could you provide more info? – Aralox Jul 25 '16 at 01:29
  • Right click the 'Project' tab. Choose your project. Right click on it and you should see this option. I just verified this today itself. – Varun Bhatia Jul 25 '16 at 05:05
  • Alright, I think my problem is that I'm using IntelliJ IDEA instead of Android Studio. But I've resolved this problem, so It's all good. Thanks anyway Varun. – Aralox Jul 25 '16 at 05:38
  • I guess you can upvote the answer if it worked for u. Just increases the credibility of answers. – Varun Bhatia Jul 26 '16 at 15:07
0

Tried all the available solutions, and in last I have commented the include ':app' in settings.gradle and this resolved the issue in my case

Vikas
  • 21
  • 4
0

In my case non of the answers above resolved it. Finally, I went to settings.gradle file and inside the dependencyResolutionManagement block, I changed the repositoriesMode to "PREFER_PROJECT"

repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)

That was all I did and it worked like magic, maybe such can help you too, you can try it out.

Peter Akwa
  • 77
  • 1
  • 6