重置电脑后Android Studio中Gradle无法找到anko-commons依赖
解决Gradle无法找到anko-commons:0.8.3依赖的问题
核心修复步骤
调整仓库配置位置:新版Android Gradle Plugin(AGP 7.0+)已不再支持模块级
build.gradle中配置仓库,需将仓库定义移至项目根目录的settings.gradle:- 删除模块
build.gradle末尾的repositories代码块 - 在根目录
settings.gradle中添加如下配置:dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() maven { url "https://jitpack.io" } } }
- 删除模块
清理Gradle缓存:
执行File -> Invalidate Caches... -> Invalidate and Restart,重启Android Studio后重新同步项目。检查网络代理:
重置电脑后代理配置可能变更,进入File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle确认代理设置正确,或尝试关闭代理后重新同步。核对依赖拼写:
确认依赖org.jetbrains.anko:anko-commons:0.8.3的组名、模块名及版本号无拼写错误,该版本确实存在于Maven仓库中。
原配置及错误信息
模块build.gradle配置
plugins { id 'com.android.application' id 'kotlin-android' } apply plugin: 'kotlin-android' android { compileSdkVersion 33 buildToolsVersion "30.0.3" compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } configurations.all { resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' } } defaultConfig { applicationId "com.{redacted}" minSdkVersion 28 targetSdkVersion 33 versionCode 1 versionName "1.0" manifestPlaceholders = [auth0Domain: "@string/com_auth0_domain", auth0Scheme: "@string/com_auth0_scheme"] testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { useSupportLibrary true } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } buildFeatures { viewBinding true compose true } kotlinOptions { jvmTarget = '1.8' } namespace 'com.{redacted}' composeOptions { kotlinCompilerExtensionVersion '1.3.2' } packagingOptions { resources { excludes += '/META-INF/{AL2.0,LGPL2.1}' } } } dependencies { implementation 'commons-codec:commons-codec:1.3' implementation 'com.auth0.android:auth0:2.9.3' implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'com.diegodobelo.expandingview:expanding-view:0.9.4' implementation 'androidx.recyclerview:recyclerview:1.3.0' implementation 'androidx.cardview:cardview:1.0.0' implementation 'com.google.android.material:material:1.9.0' implementation('com.googlecode.json-simple:json-simple:1.1.1') { exclude group: 'org.hamcrest', module: 'hamcrest-core' } implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3' implementation 'androidx.navigation:navigation-ui-ktx:2.5.3' implementation 'org.chromium.net:cronet-embedded:108.5359.79' implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.2' //noinspection GradleCompatible implementation 'com.android.support:appcompat-v7:28.0.0' //noinspection GradleCompatible implementation 'com.android.support:design:28.0.0' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1' implementation 'androidx.navigation:navigation-fragment:2.5.3' implementation 'androidx.navigation:navigation-ui:2.5.3' implementation 'androidx.preference:preference:1.2.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'com.google.android.things:androidthings:1.0' implementation 'com.google.guava:guava:31.1-jre' implementation files(file('../libs/emv-anet-sdk.aar').absolutePath) implementation 'org.apache:apache:29' implementation 'org.apache.commons:commons-lang3:3.12.0' implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1' implementation 'androidx.activity:activity-compose:1.5.1' implementation platform('androidx.compose:compose-bom:2022.10.00') implementation 'androidx.compose.ui:ui' implementation 'androidx.compose.ui:ui-graphics' implementation 'androidx.compose.ui:ui-tooling-preview' implementation 'androidx.compose.material3:material3' implementation platform('androidx.compose:compose-bom:2022.10.00') implementation platform('androidx.compose:compose-bom:2022.10.00') testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' implementation 'androidx.core:core-ktx:1.10.1' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.anko:anko-commons:0.8.3" implementation 'com.github.felHR85:UsbSerial:6.1.0' implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' implementation 'com.github.jaiselrahman:FilePicker:1.3.2' implementation(platform('com.squareup.okhttp3:okhttp-bom:5.0.0-alpha.11')) implementation("com.squareup.okhttp3:okhttp") implementation('com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.11') implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.11' implementation 'com.github.davidmigloz:number-keyboard:3.1.0' androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00') androidTestImplementation 'androidx.compose.ui:ui-test-junit4' androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00') androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00') debugImplementation 'androidx.compose.ui:ui-tooling' debugImplementation 'androidx.compose.ui:ui-test-manifest' }
Gradle错误信息
Could not find org.jetbrains.anko:anko-commons:0.8.3. Required by: project :app
内容的提问来源于stack exchange,提问作者Jason Chan
相关产品推荐
相关产品推荐

