2

I have been trying to add a library project as a dependency to another library project in Android Studio without success. Below is my project structure:

- apps
  - demo (depends on android utilities & android ui)
- libraries
  - android utilities
    - utilities
  - android ui
    - ui (depends on android utilities)

I used the following as guide Add local Library Project as a dependency to multiple Projects in Android Studio

android utilities/build.gradle

...

android utilities/utilities/build.gradle

apply plugin 'com.android.library'

...

android ui/settings.gradle

include ':ui'
include ':utilities'
project(':utilities').projectDir = new File(settingsDir, '../android utilities/utilities')

android ui/build.gradle

...

android ui/ui/build.gradle

apply plugin 'com.android.library'

...

dependencies {
    compile project(':utilities')
}

I have both Android Utilities and Android Ui setup as separate projects, I am able to compile the Android Utilities project without issues. But, I am not able to compile the separate Android Ui project. Android Studio itself doesn't indicate any errors, but gradle produces multiple errors about packages from the utilities library not existing.

Community
  • 1
  • 1
Remel Pugh
  • 36
  • 6
  • Does utilities contain a build.gradle file? – Gabriele Mariotti Oct 21 '15 at 21:27
  • Yes, I updated the question to reflect that those files do exist, however, if you think it would be better to include all the contents of the gradle files I can definitely do that. – Remel Pugh Oct 22 '15 at 09:44
  • It seems correct. Did you try to run gradle clean? – Gabriele Mariotti Oct 22 '15 at 10:05
  • I did, executing "Build\Clean Project" from the IDE gives me the same errors as when I attempt to build. I have to run gradlew clean from the command line in order to get a successful clean. But, cleaning doesn't seem to help either. I have also tried recreating the projects from scratch in a new folder. I appreciate the help as I feel like it is something simple that I am just overlooking. – Remel Pugh Oct 22 '15 at 13:27
  • Same problem here. Did you ever find a solution? – enl8enmentnow Mar 09 '16 at 19:58
  • Unfortunately, I haven't found a solution to this issue, the only work around that came up with was to push the library to my own private maven repository. – Remel Pugh Mar 10 '16 at 21:21

2 Answers2

1

I had similar problem in my project but managed to resolve it. Do you have more than 1 build flavor?

What I ended up doing is adding following in library (/ui/ui/build.gradle in your case), where buildFlavor1 and buildFlavor2 - are build variants used in your app. I think the problem was because Gradle is not aware of possible configurations when resolving dependencies, so he cannot properly pick the library for every build flavor. Hope this helps!

configurations {
    buildFlavor1DebugCompile
    buildFlavor2DebugCompile
    buildFlavor1ReleaseCompile
    buildFlavor2ReleaseCompile
}

dependencies {
    ...

    buildFlavor1DebugCompile project(path: ':utilities', configuration: 'buildFlavor1Debug')
    buildFlavor2DebugCompile project(path: ':utilities', configuration: 'buildFlavor2Debug')
    buildFlavor1ReleaseCompile project(path: ':utilities', configuration: 'buildFlavor1Release')
    buildFlavor2ReleaseCompile project(path: ':utilities', configuration: 'buildFlavor2Release')
}
Armaxis
  • 161
  • 1
  • 9
0

You do not have the right syntax. This:

include 'ui'

should be this:

include ':ui'

(you missed the colon)

Jim
  • 10,172
  • 1
  • 27
  • 36
  • Thank you for pointing that out, unfortunately, that was just an oversight on my part, the actual settings.gradle file does include the colon. I have corrected the sample. – Remel Pugh Oct 22 '15 at 09:27