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.

6 Answers 6

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

1

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

Comments

0

Right click project, Select

"Configure Project Subset ..."

and select your module, rebuild your project.

4 Comments

I don't see this option in the context menu when I right click on my project. Could you provide more info?
Right click the 'Project' tab. Choose your project. Right click on it and you should see this option. I just verified this today itself.
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.
I guess you can upvote the answer if it worked for u. Just increases the credibility of answers.
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

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.