1

I'm developing an android library that depends on some third party aars and jars.

Currently, these dependencies are declared in the library module's gradle buildscript like so:

repositories {
        flatDir{
            dirs 'libs', 'android-libs'
        }
}

dependencies{
    compile(name: 'threetenabp-1.0.5', ext: 'aar')
    compile fileTree(include: ['*.jar'], dir: 'libs')
}

However, this results in the dependencies' classes being built into the aar, potentially causing conflicts when the library is used in an application.

How can I reference these dependencies from my library without actually packaging them into the library?

I have tried changing the declarations from "compile" to "provided" and then compiling the files into the application, but when I do this my library fails to build.

duggulous
  • 2,427
  • 3
  • 23
  • 40
  • I am not certain, but i think this can help you : https://stackoverflow.com/questions/31731014/what-does-transitive-true-in-gradle-exactly-do-w-r-t-crashlytics – Henrique César Madeira Oct 24 '17 at 20:02
  • Hmm, thanks, but the discussion there seems to center around the function of the "transitive" flag. While that is related to dependencies, I don't think it applies to my problem. – duggulous Oct 24 '17 at 20:33

1 Answers1

0

After some reading at https://docs.gradle.org/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies I eventually figured out that using compile fileTree will package the dependencies into the output library. To avoid this, declare each dependency individually, using the following syntax:

dependencies {
compile: name: 'filename-without-extension' 
}

And the dependencies will no longer be packaged into the output.

The project making use of the output aar will still need to include the flat-dir repository that holds the jar files, like so:

repositories {
        flatDir{
            dirs 'libs'
        }
}
duggulous
  • 2,427
  • 3
  • 23
  • 40