"无法解决所有依赖关系"与第三方库(来自Maven Central)

 素人1963_497 发布于 2023-02-06 14:21

在我的中build.gradle,我定义了一些第三方库,所有这些库都可以在Maven Central中使用.

dependencies {    
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.google.guava:guava:15.0'
    compile 'com.netflix.rxjava:rxjava-core:0.14.2'
    compile 'com.netflix.rxjava:rxjava-android:0.14.2'
}

(我们也有libs(对于Eclipse用户)手动管理的jar ,我过去常常使用这些用于Gradle构建compile fileTree(dir: 'libs', include: '*.jar'),但是我正试图从那里转向更简单的自动化依赖管理.)

无论如何,由于某种原因,获取deps失败:

* What went wrong:
A problem occurred configuring root project 'MyApp-Android'.
> Could not resolve all dependencies for configuration ':_debugCompile'.
   > Could not find com.google.code.gson:gson:2.2.4.
     Required by:
         :MyApp-Android:unspecified
   > Could not find com.google.guava:guava:15.0.
     Required by:
         :MyApp-Android:unspecified
   > Could not find com.netflix.rxjava:rxjava-core:0.14.2.
     Required by:
         :MyApp-Android:unspecified
   > Could not find com.netflix.rxjava:rxjava-android:0.14.2.
     Required by:
         :MyApp-Android:unspecified

我究竟做错了什么?

我想知道我是否应该

repositories {
    mavenCentral()
}

...也在构建文件的顶层(不仅仅是内部buildscript),但添加它没有帮助.

解析度

我太仓促了; 这确实有助于"无法解决依赖关系".之后我得到了编译错误,但这是因为事实上代码(和in libs)中有一些比dependendies上面的四个条目更多的依赖.

所以在我的情况下,我必须添加顶级repositories指向Maven Central 以及我们实际拥有的一些额外的依赖:

compile 'com.squareup.okhttp:okhttp:1.2.1'   
compile 'com.android.support:support-v4:13.0.0'
compile 'com.android.support:support-v13:13.0.0'

(原始,破碎)满build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.1'
    }
}
apply plugin: 'android'

dependencies {
    // compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.google.guava:guava:15.0'
    compile 'com.netflix.rxjava:rxjava-core:0.14.2'
    compile 'com.netflix.rxjava:rxjava-android:0.14.2'
}

android {
    compileSdkVersion 19
    buildToolsVersion "19"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src//... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

}

MagicMicky.. 17

确实你需要添加一个

repositories {
    mavenCentral()
}

在您的顶层build.gradle指定搜索依赖项的位置.

1 个回答
  • 确实你需要添加一个

    repositories {
        mavenCentral()
    }
    

    在您的顶层build.gradle指定搜索依赖项的位置.

    2023-02-06 14:36 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有