4

In Android Studio I'm trying to compile an Android application module which uses an Android library.
The library includes a jar file for Bugsense (included automatically by gradle).

Although the library module compiles correctly, the application module fails because it is looking for the Bugsense jar file that is used within the library module.

I do have a workaround which allows the project to compile. By also including the Bugsense dependency in the project everything works.

My question is: How do I make the project compile without duplicating the Bugsense dependency?

Here is my build.gradle file for the library project.

buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.6.+' } } apply plugin: 'android-library' repositories { mavenCentral() maven { url 'http://www.bugsense.com/gradle/' } } android { compileSdkVersion 15 buildToolsVersion "19.0.0" defaultConfig { minSdkVersion 15 targetSdkVersion 15 } } dependencies { compile 'com.bugsense.trace:bugsense:3.6' } 

The library project is called "util"

Following is the android section of the build.gradle for the application

android { compileSdkVersion 15 buildToolsVersion '19.0.0' defaultConfig { minSdkVersion 15 targetSdkVersion 15 } dependencies { compile project(':util') } } 

When I compile this I get the following error:

* What went wrong: A problem occurred configuring project ':br'. > Failed to notify project evaluation listener. > Could not resolve all dependencies for configuration ':br:_DebugCompile'. > Could not find com.bugsense.trace:bugsense:3.6. Required by: dss:br:unspecified > dss:util:unspecified 

I can make the compile work by adding Bugsense to the repositories section of the build.gradle file for the application. Following is the code I added to the build.gradle file for the application project.

repositories { mavenCentral() maven { url 'http://www.bugsense.com/gradle/' } } 

Remember, the above code is in the build.gradle for the application project AND the library.

How do I avoid adding the Bugsense dependency to both the application and library projects?

UPDATES:

I'm using Gradle 1.8

I'm compiling from the command line with "gradle clean assembleDebug"

The following is the complete build.gradle file for the application project:

buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.6.+' } } apply plugin: 'android' repositories { mavenCentral() //maven { url 'http://www.bugsense.com/gradle/' } } android { compileSdkVersion 15 buildToolsVersion '19.0.0' defaultConfig { minSdkVersion 15 targetSdkVersion 15 testPackageName "com.myapp.test" } dependencies { compile project(':common') compile project(':util') } } dependencies { instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.3' instrumentTestCompile 'com.squareup:fest-android:1.0.+' instrumentTestCompile 'com.squareup.spoon:spoon-client:1.0.+' instrumentTestCompile 'com.google.guava:guava:15.0' } configurations { spoon } dependencies { spoon 'com.squareup.spoon:spoon-runner:1.0.5' } 
5
  • 1
    Dependencies should be transitive with gradle. I have used dependencies from a library project many times with no issues. Something must be wrong with your setup. I was using bugsense a few months ago without issue. Can you post your entire gradle builds and also mention what version of gradle you are running. Also specify with command you are using to do the build. Commented Dec 10, 2013 at 23:38
  • Matt Wolfe, I've used a similar technique for library projects before and it has worked. However, in that case I was using jar files that were in a libs directory in the project - not files being acquired by Gradle. Can you describe how you were using Bugsense - was it in an included library or directly with the application project? Thanks - I appreciate you taking the time to look at this. Commented Dec 11, 2013 at 0:22
  • This might be a gradle 1.9 issue. I was reading awhile back there was some problem using it with android. Not sure if those issues have been resolved. I'm still on 1.8 for what it's worth. I don't see anything above that looks wrong so it's tough to say. I would try gradle 1.8 though. Commented Dec 11, 2013 at 0:36
  • I am actually using Gradle 1.8 (1.9 is not supported by the Android Gradle plugin yet). I fixed the post to reflect correct version. Commented Dec 11, 2013 at 0:49
  • Get anywhere with this? Commented Sep 8, 2014 at 16:54

1 Answer 1

2

It's the expected behavior. Only the repository declarations for the project whose configuration is currently resolved are taken into account, even when transitive dependencies are involved. Typically, repositories are declared inside the root project's allprojects { .. } or subprojects { ... } block, in which case this problem can never occur.

PS: dependencies { .. } needs to go outside the android { ... } block.

Sign up to request clarification or add additional context in comments.

1 Comment

Why is this expected? I would expect it find dependencies of the dependency and download them as well or merge with the current dependencies. Is there a reason why we can't do that?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.