我无法在 Android Studio 中构建我的项目。我正在尝试使用谷歌视觉 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
项目构建成功。我添加依赖项的方式有问题吗?
我认为你的依赖类路径有问题。您创建了两个构建脚本依赖项。相反,您可以在同一个构建脚本中包含一个或多个插件(依赖项)。
你可以拥有 root 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()
会为您做同样的事情。
我想通了。看起来我需要使缓存无效并重新启动 android studio 和我的电脑。感谢您的帮助!
我也有同样的问题
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
我的毕业典礼
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'