Android Canary 13 构建项目无法解析第三方库问题求助
问题排查与解决方案
原始问题描述
我使用的是Android Canary 13(Bubble Bee)版本,目前遇到无法解析任何第三方库的问题。我已尝试添加多款不同的第三方库,但项目构建阶段均无法解析这些库。添加依赖后执行项目同步操作时,能正常下载依赖、同步成功,但项目内无法识别对应库,尝试构建项目时会抛出对应错误:
app模块build.gradle配置
plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'androidx.navigation.safeargs' id 'com.google.gms.google-services' id 'kotlin-kapt' } android { compileSdk 31 defaultConfig { applicationId "com.ra.rightads" minSdk 21 targetSdk 31 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 } kotlinOptions { jvmTarget = '1.8' } dataBinding { enabled = true } buildFeatures { viewBinding true } } dependencies { implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' def nav_version = "2.3.5" implementation 'androidx.core:core-ktx:1.6.0' implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.1' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' // Navigation dependencies implementation "androidx.navigation:navigation-fragment:$nav_version" implementation "androidx.navigation:navigation-ui:$nav_version" implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version" androidTestImplementation "androidx.navigation:navigation-testing:$nav_version" implementation "androidx.navigation:navigation-compose:2.4.0-alpha10" //Firebase dependencies implementation "com.google.firebase:firebase-core:19.0.2" implementation "com.google.firebase:firebase-auth:21.0.1" implementation "com.google.firebase:firebase-firestore:23.0.4" implementation "com.google.android.gms:play-services-auth:19.2.0" implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'com.google.firebase:firebase-database:20.0.2' implementation 'com.google.firebase:firebase-analytics:19.0.2' implementation 'com.google.firebase:firebase-storage:20.0.0' //Google material dependencies implementation 'com.google.android.material:material:1.4.0' // Picasso implementation 'com.squareup.picasso:picasso:2.71828' // Retrofit implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation 'com.squareup.retrofit2:converter-scalars:2.1.0' // Okhttp implementation 'com.squareup.okhttp3:logging-interceptor:4.7.2' // Glide implementation 'com.github.bumptech.glide:glide:4.11.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' //Viewpager implementation 'androidx.viewpager2:viewpager2:1.0.0' //Hilt dependency implementation("com.google.dagger:hilt-android:2.38.1") //Multidex implementation 'com.android.support:multidex:1.0.3' //Kapt kapt 'com.github.bumptech.glide:compiler:4.11.0' // sdp and ssp for dp and sp values implementation 'com.intuit.sdp:sdp-android:1.0.6' implementation 'com.intuit.ssp:ssp-android:1.0.6' }
项目级build.gradle配置
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() maven { url 'https://maven.google.com' } maven { url 'https://jitpack.io' } } dependencies { def nav_version = "2.3.5" classpath 'com.android.tools.build:gradle:7.0.3' classpath 'com.google.gms:google-services:4.3.10' classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" classpath('com.android.support:multidex:1.0.3') // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } task clean(type: Delete) { delete rootProject.buildDir }
解决步骤
- 清理冗余依赖:删除app模块build.gradle中重复声明的navigation、material组件依赖,保留唯一版本的声明即可。
- 补全Hilt配置:
- 在项目级build.gradle的
buildscript.dependencies中添加hilt插件依赖:
classpath "com.google.dagger:hilt-android-gradle-plugin:2.38.1"- 在app模块build.gradle的plugins块中添加hilt插件:
id 'dagger.hilt.android.plugin'- 在app模块build.gradle的dependencies块中添加hilt编译依赖:
kapt "com.google.dagger:hilt-android-compiler:2.38.1" - 在项目级build.gradle的
- 替换废弃仓库:将项目级build.gradle中的
jcenter()替换为mavenCentral(),JCenter已停止维护,无法稳定拉取依赖。 - 补充全局仓库配置:在项目级build.gradle中添加和buildscript同级的allprojects配置,指定全局依赖拉取仓库:
allprojects { repositories { google() mavenCentral() maven { url 'https://jitpack.io' } } } - 清理缓存重建:执行Android Studio菜单
File > Invalidate Caches...,勾选清理文件系统缓存选项,重启IDE后重新同步项目即可。
注:Android Canary属于测试通道版本,本身存在功能不稳定的可能性,如果以上操作完成后问题仍然存在,可切换到Android Studio正式版验证。
内容的提问来源于stack exchange,提问作者Mr uNiQue
相关产品推荐
相关产品推荐

