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

本文记录了在引入MPAndroidChart图表库时遇到的依赖失败问题,并分享了解决方案。错误在于将Maven仓库地址误放于buildscript部分,正确做法是将其置于allprojects的repositories中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

刚刚犯了一个低级错误。

引用 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'
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

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

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

我将

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

这一句错误地放置在了 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
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值