Why does Gradle only include classes from my library with project dependency

Viewed 5841

I'm building an Android app that has a dependency on a custom library, and Gradle is only willing to include my custom library when I use a project dependency, not when I use a files dependency to include the library's jar file. I'm building both my app and the library with the API levee 19 SDK.

failing dependencies section from build.gradle:

dependencies {
  compile 'com.android.support:appcompat-v7:+'
  compile files('libs/MyLibrary.jar')
}

If I use the above dependencies section, none of the class in MyLibrary.jar are included in the build apk file, as verified by extracting its classes.dex and running dexdump. I have also verified that all of the classes are present in the jar file I'm using.

If I use the following dependencies section, then all of the classes in MyLibrary are included in the apk file:

dependencies {
  compile 'com.android.support:appcompat-v7:+'
  compile project(':MyLibrary')
}

I'm using Android Studio 0.4.0, Gradle 1.9, and I think the Gradle plugin 0.7.1.

What is going on here? I'd really like to build my app with the API level 18 sdk to test compatibility, but I can't get that working unless I'm able to just use the jar file for my library.

3 Answers
Related