P. Grosicki
P. Grosicki

Reputation: 151

IntelliJ and Android Gradle dependencies - unable to find module

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.

Upvotes: 15

Views: 5415

Answers (6)

Peter Akwa
Peter Akwa

Reputation: 115

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.

Upvotes: 0

Vikas
Vikas

Reputation: 21

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

Upvotes: 0

Joris Oudejans
Joris Oudejans

Reputation: 11

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

Upvotes: 1

Aralox
Aralox

Reputation: 1459

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.

Upvotes: 1

Varun Bhatia
Varun Bhatia

Reputation: 4386

Right click project, Select

"Configure Project Subset ..."

and select your module, rebuild your project.

Upvotes: 0

Alex Barceló
Alex Barceló

Reputation: 322

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.

Upvotes: 19

Related Questions