无法确定 com.google.android.gms:play-services-vision:18.0.0 的工件。

3

我无法在Android Studio中构建我的项目。我正在尝试使用Google Vision API进行人脸检测,到目前为止它一直运行良好,但是由于以下错误,我无法清理/构建我的项目

这是我的构建错误消息

Could not resolve all dependencies for configuration ':app:debugRuntimeClasspath'.
Could not determine artifacts for com.google.android.gms:play-services-vision:18.0.0
Could not get resource 'https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-vision/18.0.0/play-services-vision-18.0.0.aar'.
Could not HEAD 'https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-vision/18.0.0/play-services-vision-18.0.0.aar'.
Remote host closed connection during handshake
SSL peer shut down incorrectly

这是我的 build.gradle 文件(应用程序级别)

apply plugin: 'com.android.application'
android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.example.facedetect"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.volley:volley:1.1.1'
    implementation "com.github.bumptech.glide:glide:4.9.0"
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    implementation 'com.google.android.gms:play-services-vision:18.0.0'


    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.mindorks:paracamera:0.2.2'
}
apply plugin: 'com.google.gms.google-services'

项目级别 build.gradle

buildscript {
    repositories {
        google()
        jcenter()

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

    }
}

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

    }
}

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

buildscript {

    dependencies {
        // Add this line
        classpath 'com.google.gms:google-services:4.3.0'
    }

}

当我去掉

标签时
implementation 'com.google.android.gms:play-services-vision:18.0.0

项目构建成功。我添加依赖的方式是否有问题?

你的问题解决了吗? - Sagar Chapagain
3个回答

2
我认为您的问题出在依赖类路径上。您创建了两个buildscript依赖项。相反,您可以在同一个buildscript中包含一个或多个插件(依赖项)。
您可以将根目录下的build.gradle设置如下:
"最初的回答"
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.3.0'
    }
}

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

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

此外,你不必单独编写Google Maven URL maven { url 'https://maven.google.com'},因为使用google()就可以实现同样的功能。将两者结合起来更加方便。

1
我解决了。看起来我需要使缓存失效并重新启动Android Studio和电脑。感谢您的帮助!

0

我有同样的问题

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find com.google.mlkit:face-detection:17.0.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/google/mlkit/face-detection/17.0.2/face-detection-17.0.2.pom
       - https://repo.maven.apache.org/maven2/com/google/mlkit/face-detection/17.0.2/face-detection-17.0.2.pom
       - https://jcenter.bintray.com/com/google/mlkit/face-detection/17.0.2/face-detection-17.0.2.pom
       - https://storage.googleapis.com/download.flutter.io/com/google/mlkit/face-detection/17.0.2/face-detection-17.0.2.pom
     Required by:
         project :app
   > Could not find com.google.mlkit:face-detection:17.0.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/google/mlkit/face-detection/17.0.2/face-detection-17.0.2.pom
       - https://repo.maven.apache.org/maven2/com/google/mlkit/face-detection/17.0.2/face-detection-17.0.2.pom
       - https://jcenter.bintray.com/com/google/mlkit/face-detection/17.0.2/face-detection-17.0.2.pom
       - https://storage.googleapis.com/download.flutter.io/com/google/mlkit/face-detection/17.0.2/face-detection-17.0.2.pom
     Required by:
         project :app > project :google_mlkit_face_detection

我的Gradle

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.0'
        // START: FlutterFire Configuration
        classpath 'com.google.gms:google-services:4.3.10'
        // END: FlutterFire Configuration
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()


    }
}

并且

另一个上我有:

    implementation 'com.google.mlkit:face-detection:17.0.2'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接