0

What is the best way to add this small sexy library (which does not use maven yet) to my project?

I see an 'import module' and 'import project' option under the File menu, so I assume I should use one of these? I have tried with both and while the project source does pop up in Android Studio I cannot use any of the library content.

There are many questions on SO regarding importing libraries to Android Studio, but most either use a project which has a jar file, or are using a much older version so I'm not too sure how to do this. This question seems similar to mine, I have tried to import the folder as a module, and added this to my build.gradle:

compile project(':ChromaHashView:library')

And this popped up in the settings.gradle

include 'ChromaHashView'

But I get an error saying the ':ChromaHashView:library' could not be found in my project.

Community
  • 1
  • 1
Daniel Wilson
  • 18,838
  • 12
  • 85
  • 135

1 Answers1

2

What's in the include statement in your settings.gradle file has to match what's in the compile project statement in your build.gradle.

So:

build.gradle

dependencies {
    compile project(':ChromaHashView:library')
}

settings.gradle

include ':ChromaHashView:library'

The ChromaHashView project is a standalone Gradle project with a build.gradle, settings.gradle and Gradle wrapper at its project root, and two modules (demo and library).

However, to include the modules in a different project, you have to bypass its root-level build and settings files and include the submodules directly as submodules in your target project, which is what you're doing with the modifications above. Another way of saying that is that Gradle only supports one settings.gradle file per project, and the Android Studio project already has one, so to include new modules you have to merge the changes into the existing settings file.

Scott Barta
  • 79,344
  • 24
  • 180
  • 163