Gradle cannot resolve all dependencies, custom mav

2019-06-22 04:58发布

问题:

I'm using Crashlytics, which provides a custom Maven url. I'm trying to move the Crashlytics code to a library.

The library build.gradle file is as follows:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

repositories {
    mavenCentral()
    maven { url 'http://download.crashlytics.com/maven' }
}

dependencies {
    compile 'com.crashlytics.android:crashlytics:1.+'
}

When building this library project on its own, all goes well. However, when I add the library as a dependency to another project, gradle sync only succeeds when I add the custom maven url to its build.gradle as well. Otherwise, the following message shows up:

Error:A problem occurred configuring project ':MyApp'.
> Could not resolve all dependencies for configuration ':MyApp:_debugCompile'.
   > Could not find any version that matches com.crashlytics.android:crashlytics:1.+.
     Required by:
         my-app:MyApp:unspecified > my-app:MyLibrary:unspecified

Why do I need to add the maven { url 'http://download.crashlytics.com/maven' } to the MyApp project as well? Is there a better solution?