Android Studio Gradle构建报错:Failed to resolve: runtime(未用架构组件)
Hey there, let's tackle this "Failed to resolve: runtime" error you're seeing after running a Gradle build—especially since you mentioned you aren't using any architecture components. The log snippet you shared points to a failure in the :app:compileDebugJavaWithJavac task, which usually ties back to dependency resolution issues or Gradle configuration glitches. Here are some tried-and-true fixes to get you back on track:
Invalidate Caches and Restart Android Studio
Sometimes the IDE's cached data gets corrupted, leading to weird dependency resolution hiccups. Head toFile > Invalidate Caches... > Invalidate and Restartto clear out stale data and give Android Studio a fresh start.Audit Your app-level
build.gradleDependencies
Even without architecture components, double-check your dependencies block for any misconfigured or outdated entries. Look for lines that might incorrectly reference aruntimeartifact—make sure every dependency has a valid group, name, and version. Also, confirm your project-levelbuild.gradleincludes the necessary repositories to pull dependencies:repositories { google() mavenCentral() }Update Gradle Plugin and Wrapper
Outdated Gradle versions often cause compatibility issues that trigger dependency errors. In your project-levelbuild.gradle, update the Android Gradle Plugin to the latest stable version:dependencies { classpath 'com.android.tools.build:gradle:7.4.2' // Replace with the latest stable version }Then match it with the correct Gradle wrapper version (check the official compatibility guidelines to find the right pair). You can update this via
File > Project Structure > Projector edit thegradle/wrapper/gradle-wrapper.propertiesfile directly.Clean and Rebuild Your Project
Leftover build artifacts can sometimes mess with dependency resolution. RunBuild > Clean Projectfirst, followed byBuild > Rebuild Project—this forces Gradle to re-resolve all dependencies from scratch instead of relying on cached files.Dig Into the Full Gradle Sync Log
The log snippet you shared is truncated, so check the complete Gradle sync log (found in the "Gradle" tab at the bottom of Android Studio). It should have more specific details about whichruntimedependency is failing to resolve—this might even be a transitive dependency pulled in by one of your explicit dependencies, even if you aren't using architecture components directly.Disable Gradle Offline Mode
If offline mode is enabled, Gradle might be trying to use cached dependencies that no longer exist or aren't available locally. Go toFile > Settings > Build, Execution, Deployment > Build Tools > Gradleand uncheck "Offline work", then sync your project again.
内容的提问来源于stack exchange,提问作者Amit

