解决 MPAndroidChart 无法引入依赖的问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/briblue/article/details/77305697

刚刚犯了一个低级错误。

引用 MPAndroidChart 这个开源的图表库的时候,按照官方的提示去引入依赖库,结果同步的时候,怎么都编译不过。

提示的信息就是:

Failed to resolve: com.github.PhilJay:MPAndroidChart:v3.0.2

可我记得自己明明就按照配置说明进行的配置的啊。

先看官方文档。

这里写图片描述

然后,再比较自己的配置文件。

buildscript {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
    testCompile 'junit:junit:4.12'
}

初看,没有什么问题。但就是编译不通过,百思不得其解。

但是后来看到 stackoverflow 上的答案时,才明白了错误所在。

我将

maven { url "https://jitpack.io" }

这一句错误地放置在了 buildscript{} 中,正确的应该是这样的。

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

看来,写程序还是要细心为好,小小的一个失误有时候会让你怀疑人生。

参考

stackoverflow

猜你喜欢

转载自blog.csdn.net/briblue/article/details/77305697
今日推荐