【发布时间】:2021-02-14 12:58:08
【问题描述】:
我正在尝试将 android-youtube-player 添加到我的 android 项目中。当我将它添加到 gradle 依赖项时,gradle sync 完成并出现以下警告:
Failed to resolve: lifecycle-runtime-2.2.0
尝试运行应用程序会产生以下错误:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find recyclerview-1.1.0.jar (androidx.recyclerview:recyclerview:1.1.0).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/androidx/recyclerview/recyclerview/1.1.0/recyclerview-1.1.0.jar
> Could not find lifecycle-runtime-2.2.0.jar (androidx.lifecycle:lifecycle-runtime:2.2.0).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/androidx/lifecycle/lifecycle-runtime/2.2.0/lifecycle-runtime-2.2.0.jar
我的 build.gradle 文件:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.****.********"
minSdkVersion 22
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation "androidx.fragment:fragment-ktx:1.2.0"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.5'
}
没有implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.5'没有问题
我已尝试清理项目并删除 .gradle 文件夹,但没有帮助。是不是我做错了什么?
【问题讨论】:
-
确保在顶级
build.gradle文件中的repositories闭包中有google()。 -
@CommonsWare 我在顶级 build.gradle 中有
allprojects {repositories {google() jcenter()}}。 -
嗯...出于某种原因,您的项目正在尝试提取 JAR 文件,而这两个都是 AAR 文件。并且the POM file for that YouTube library 没有请求
androidx.lifecycle:lifecycle-runtime,而是请求RecyclerView工件的不同版本。您可以尝试在模块的build.gradle中为这两个工件添加implementation行,看看 Gradle 是否会按预期将它们解析为 AAR。 -
@CommonsWare 我尝试添加
RecyclerView和lifecycle-runtimeimplementation行,但出现了同样的错误。还是谢谢。 -
@CommonsWare 它并没有太大帮助,但我尝试在
repositories中用maven { url 'https://maven.google.com' }替换google(),它成功了!感谢您的帮助。
标签: java android android-studio gradle