1

I'm trying to declare my own custom libraries as dependencies in Gradle. I need to declare that 'Project A' is dependent and must compile 'Project B'.

The 'settings.gradle' file for Project A (which includes Project B: mylibrary) would look like this:

include ':app', ':mylibrary'

project(':mylibrary').projectDir = new File(settingsDir, '../mylibrary/lib')

And I'd make sure that 'build.gradle' had:

compile project(':mylibrary')

Previously, I had ALL my Android Studio Projects in '~/AndroidStudioProjects' (I develop on a Mac). However, I have done some "organising" of my file structure. 'Project A', which uses and relies on classes/methods from 'Project B' (i.e. 'mylibrary'), are no longer in the same, base, root directory (previously ~/AndroidStudioProjects; my projects now reside in different directories).

How do I declare a project location in Gradle that is an outside project?

user1234
  • 689
  • 1
  • 8
  • 22

1 Answers1

0

You cannot. Gradle provides two methods to include projects to multi-project build. These are

  • include(projectPaths)
  • includeFlat(projectNames)

include expect that your projects has common root directory, like below, and you use this command in Root directory settings.gradle

ProjectMain
  ProjectA
  ProjectB

includeFlat expect that your projects reside in same directory, but you use this command in one of the child directories' settings.gradle. Good example here.

ProjectMain
ProjectA
ProjectB

If you made some arrangements for directories, best choice for you to use symbolic link approach.

Community
  • 1
  • 1
Atilla Ozgur
  • 14,339
  • 3
  • 49
  • 69
  • What's the proper way then to go about including libraries? With my previous methods, I could make a change in the library, and it would be reflected throughout any project that uses the library. I do not want to have to compile and recompile and include my library as a separate .jar file every time. – user1234 Nov 27 '14 at 02:47
  • @user1234 that means including your library projects as symbolic link in main project. – Atilla Ozgur Nov 27 '14 at 06:30