Android Gradle build with sub projects

settings.gradle must define all the modules. It won’t load other settings.gradle found in the tree to load more module.

You’ll have to either

  1. define a module for the facebook SDK in the top level settings.gradle. Yes it’s redundant with the other settings.gradle.

  2. publish Project B somehow (as well as its dependencies so in this case the facebook SDK library), somewhere (a corporate artifact repository for instance) and access it from Project A.

While #1 is better, it makes the ProjectB -> Facebook dependency tricky as the path will be different depending on the settings.gradle used. One way to fix this is to split the module name/path from its actual location on disk. this is done inside the settings.gradle file.

In your top level settings.gradle file, do

include 'facebook-sdk'
project(':facebook-sdk').projectDir = new File('Libraries/ProjectBRoot/Libraries/FacebookSDK/facebook')

In the setting.gradle file inside your Project B, do the same with the different relative path:

include 'facebook-sdk'
project(':facebook-sdk').projectDir = new File('Libraries/FacebookSDK/facebook')

This makes both project setup define the same ‘facebook-sdk’ module located at the same absolute location on disk.

All projects depending on this module should just declare the dependency as

compile project(':facebook-sdk') 

Leave a Comment