I have a project called "app-project" (abbreviated as AP here), which has an "application" module. To make things reusable, this project depends on another project library named "lib-android-network" ( LAN ) and its lib module. It depends on another project called "lib-android-base" (LAB) and its module "lib". All of these projects remain in the same directory in the hierarchy. I am using Gradle and Intellij on Windows 8.1.
ex: directories: root / application-project root / lib-android-network root / lib-android base
I start with the AP project depends on the LAN project, without the LAB project.
To make an AP , see LAN for my settings. gradle AP :
include ':app', "../lib-android-network", "../lib-android-network:lib"
and in the build.gradle of the "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 many attempts before reaching this configuration), but it works fine so far when I need a third LAB project.
As I said, my LAN is dependent on LAB . So I entered the LAN settings.gradle file:
include ':lib', '../lib-android-base', '../lib-android-base:lib'
And in the build.gradle of the LAN module 'lib':
compile project(':../lib-android-base:lib')
This is the same idea that works for the AP → LAN dependency, but when I run Gradle on my first project, I get this error:
Error: (37, 0) Project with path ': ../ lib-android-base: lib' not found in project ': ../ lib-android-network: lib'.
I think because dependent projects should remain inside the parent project as modules, but this is not interesting for me, because I do not want to duplicate the project one inside the other so that it works. I want to keep the same level of the directory hierarchy. I also do not want to add Intellij module dependencies (unless it works), so before I finalize the first configuration, I have a lot of problems.
EDIT
Based on this answer and this sample project I am changing something 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')
Application / 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')
Library / build.gradle:
compile project(":lib-android-base:lib")
But I still get the same error:
Error: (39, 0) Project with empty: lib-android-base: lib 'not found in project: lib-android-network: lib'.
--- EDIT 2 ---
it works if I repeat the gradle configuration of the network project in the application 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 think I would not have to repeat this configuration in my base application whenever I had to add a dependency on the lib-android-network project. This will get confused ...
Is there a “Best Practice” for working with multiple library projects? What is the best way to handle this? Is it adding each lib as a helper module for the top project?