当前位置: 首页 > 知识库问答 >
问题:

如何修复在android中编译项目时无法找到依赖项的错误?

文志学
2023-03-14

当我尝试构建我的项目时,我遇到了这些错误,它似乎认为我有两个相同的库,但我不确定为什么:

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.legacy:legacy-support-core-utils:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.appcompat:appcompat:1.0.1.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.legacy:legacy-support-v4:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.inject:guice:4.1.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.firebase:firebase-appindexing:16.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.android.gms:play-services-analytics:16.0.5.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.android.gms:play-services-ads:17.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-runtime:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-extensions:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.room:room-runtime:2.1.0-alpha02.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-core-utils:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.appcompat:appcompat:1.0.1.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-v4:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.inject:guice:4.1.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.firebase:firebase-appindexing:16.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.android.gms:play-services-analytics:16.0.5.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.android.gms:play-services-ads:17.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-runtime:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-extensions:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.room:room-runtime:2.1.0-alpha02.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-core-utils:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.appcompat:appcompat:1.0.1.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-v4:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.inject:guice:4.1.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.firebase:firebase-appindexing:16.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-analytics:16.0.5.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-ads:17.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-runtime:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-extensions:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.room:room-runtime:2.1.0-alpha02.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.room:room-testing:2.1.0-alpha02.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve androidx.legacy:legacy-support-core-utils:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve androidx.appcompat:appcompat:1.0.1.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve androidx.legacy:legacy-support-v4:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.inject:guice:4.1.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.firebase:firebase-appindexing:16.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.android.gms:play-services-analytics:16.0.5.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.android.gms:play-services-ads:17.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-runtime:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-extensions:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve androidx.room:room-runtime:2.1.0-alpha02.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-core-utils:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.appcompat:appcompat:1.0.1.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-v4:1.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.google.inject:guice:4.1.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.google.firebase:firebase-appindexing:16.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-analytics:16.0.5.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-ads:17.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-runtime:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-extensions:2.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.room:room-runtime:2.1.0-alpha02.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.room:room-testing:2.1.0-alpha02.
Open File
Show Details

这是我的build.gradle文件

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
    applicationId "com.andydaykin.timer"
    minSdkVersion 24
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
    dexOptions {
        // release & debug is in project animators
        matchingFallbacks = ['release', 'debug']
    }
    debug {
        debuggable true
    }
}
compileOptions {
    targetCompatibility 1.10
    sourceCompatibility 1.10
}
}

allprojects {
repositories {
    google()
    jcenter()
    maven { url 'https://maven.google.com' }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'

implementation ('androidx.legacy:legacy-support-core-utils:1.0.0') {
    force = true
}
implementation 'androidx.appcompat:appcompat:1.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

implementation 'com.google.guava:guava:24.1-jre'
implementation 'com.google.inject:guice:4.1'
implementation 'com.google.firebase:firebase-appindexing:16.0.2'
implementation 'com.google.android.gms:play-services-analytics:16.0.5'
implementation 'com.google.android.gms:play-services-ads:17.0.0'

implementation "androidx.lifecycle:lifecycle-runtime:2.0.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0"

def room_version = "2.1.0-alpha02"

implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"

testImplementation "androidx.room:room-testing:$room_version"
}

这是我的顶级gradle构建文件:

{

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
}
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

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

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
}

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

}

我想这个错误发生在升级到Android Studio后,但我不记得了。我的Android Studio版本现在是3.2.1。我能够让这个项目以前建立。

共有3个答案

欧阳元魁
2023-03-14

如果您使用的是Android Studio 3和Gradle版本4。那么就不需要maven了。尝试删除

        maven {
            url 'https://maven.google.com/'
            name 'Google'
             }

只要有,

    buildscript {
    repositories {
        google()
        jcenter()

}
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

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

allprojects {
    repositories {
        google()
        jcenter()    
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
邴星洲
2023-03-14

我认为这个错误发生在升级到android studio之后

当您将编译更改为实现时,问题才刚刚开始。


假设A、B和C是三个模块,它们之间的关系如下

C


在使用编译时,C可以直接访问A。但在使用实现时,这是不可能的。有一个api将具有与编译相同的效果。

夹谷星纬
2023-03-14

在您的顶层Gradle文件添加类路径为谷歌服务插件。

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
    classpath 'com.google.gms:google-services:4.0.1'
}

您应该检查您的互联网连接、代理或防火墙。

交叉检查以通过以下方式禁用Gradle脱机。

窗户:

设置

Mac:

偏好

 类似资料:
  • 问题内容: 我正在使用JNI的Java项目中。JNI调用了一个我自己编写的自定义库,比方说mylib.dll,它依赖于一个第三方库libsndfile-1.dll。 当我运行程序时,它崩溃 我搜索了该网站(和其他网站),并尝试了许多修复程序: 我跑了依赖沃克。DW发出了一些警告-libsndfile所需的两个库MPR.DLL和SHLWAPI.DLL具有“未解决的导入”-但DW FAQ表示可以安全地

  • 问题内容: 我最近将Jenkins机器上的Android SDK从rev13更新到rev15,并且不得不重做一些自定义构建内容以适应rev14中所做的更改。我在工作站上解决了这个问题,并检查了结果,希望一切都变得柔和。而是,构建失败并显示以下错误: 通过以Jenkins用户身份直接在Jenkins工作区目录中运行,并使用与Jenkins使用的相同的Android SDK,Ant和JDK,我可以成功

  • 我正在从事一个使用JNI的Java项目。JNI调用我自己编写的自定义库,比如mylib。这取决于第三方库libsndfile-1。dll。 当我运行我的程序时,它会崩溃 我搜索了这个网站(和其他网站),并尝试了一些修复: > 我修复了mylib中的方法名称。dll,如此处所建议。方法名称不知怎么被编译器弄乱了,但我添加了链接器标志,dll方法名称现在与jni头文件中的名称完全匹配。 我将所有这些D

  • 我在使用以下内容进行构建时遇到问题: mvn清理-U安装-Dmaven.test.skip=true 人工制品不在nexus中,而是在我的本地存储库中创建的。 [错误]无法在项目mis-core上执行目标:无法解决项目x. y. z: mis-core: ejb: 0.0.1-SNAPSHOT的依赖关系:无法在https://company.net:8080/nexus/content/repos

  • 问题是gradle找不到依赖项的jar,但gradle找错了地方。Gradle一直在错误的目录(谷歌和Android支持libary的目录)中搜索文件.... 在以下位置搜索:文件:/d://programme/androis-sdks/extras/android/m2repository/org/springframework/android/spring-android-rest-templ