I have a project named 'app-project' (abbreviate here as AP) that have a module "app". To make things reusable, this project depends on another project library named 'lib-android-network' (LAN) and his module lib. It depends on another project named 'lib-android-base' (LAB) and his module "lib". All these projects stay in the same directory in the hierarchy. I use Gradle and Intellij on Windows 8.1.
ex: directories: root/app-project root/lib-android-network root/lib-android-base
I start with project AP depends on project LAN, without project LAB.
to make AP see LAN my settings.gradle of AP was:
include ':app', "../lib-android-network", "../lib-android-network:lib"
and in build.gradle of 'app' module I have:
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':../lib-android-network:lib')
I don't know how (I have to make a lot of attempts until reach this configuration) but it works perfectly until now, when need the third, LAB, project.
As I say now I have LAN depends on LAB. So I put in LAN settings.gradle file:
include ':lib', '../lib-android-base', '../lib-android-base:lib'
And in build.gradle of LAN 'lib' module:
compile project(':../lib-android-base:lib')
It's the same idea that works for AP - > LAN dependency, but when I run Gradle against my first project I get this error:
Error:(37, 0) Project with path ':../lib-android-base:lib' could not be found in project ':../lib-android-network:lib'.
I think it's because the dependent projects should stay inside the parent project as modules, but Its not interesting for me, because I don't want to have duplicate the project one inside another to make it work. I want to leave same directory hierarchy level. I don't want to add Intellij modules dependencies too (unless sure work), cause before I reach the first worked configuration, I have a lot of problems doing this.
EDIT
Based on this answer and this example project I change somethings in my own project to make it more correct:
AP project:
settings.gradle:
include ':lib-android-network', ':lib-android-network:lib'
project(':lib-android-network').projectDir = new File(settingsDir, '../lib-android-network')
project(':lib-android-network:lib').projectDir = new File(settingsDir, '../lib-android-network/lib')
app/build.gradle:
compile project(':lib-android-network:lib')
LAN project:
settings.gradle:
include ':lib-android-base', ':lib-android-base:lib'
project(':lib-android-base').projectDir = new File (settingsDir, '../lib-android-base')
project(':lib-android-base:lib').projectDir = new File (settingsDir, '../lib-android-base/lib')
lib/build.gradle:
compile project(":lib-android-base:lib")
But I'm still getting the same error:
Error:(39, 0) Project with path ':lib-android-base:lib' could not be found in project ':lib-android-network:lib'.
--- EDIT 2 ---
it works if I repeat the settings.gradle configuration of network project into app project, but
include ':lib-android-base', ':lib-android-base:lib', ':lib-android-network', ':lib-android-network:lib'
project(':lib-android-base').projectDir = new File(settingsDir, '../lib- android-base')
project(':lib-android-base:lib').projectDir = new File(settingsDir, '../lib-android-base/lib')
But I guess I shouldn't have to repeat this configuration in my base application whenever I had to add a dependency to lib-android-network project. It will get confused...
Is there a "Best Practice" to deal with a several library projects? Which is the best way to deal with it? Is it adding each lib as sub module for the top project?