Android构建失败:无法解析kotlin-gradle-plugin等依赖包
Hey, let's break down your issue first — from the error logs and your build config, the root cause is clear: Gradle is trying to use a local proxy at 127.0.0.1:1088 to download build dependencies, but that proxy connection is being refused. This is why it can't fetch the kotlin-gradle-plugin and google-services artifacts it needs to configure the Android project, leading to the build failure.
Here are the most likely fixes you can try, ordered by simplicity:
1. Check your system proxy settings
- First, make sure any proxy tool you might use is actually running and listening on port 1088. If you don't need a proxy right now, just turn off your system's global HTTP/HTTPS proxy and re-run the build. That should let Gradle connect directly to the Maven repositories.
2. Verify Gradle's own proxy configuration
Gradle might have its own proxy settings separate from your system:
- Look for a
gradle.propertiesfile in your project root (create it if it doesn't exist) and check for lines like these:systemProp.http.proxyHost=127.0.0.1 systemProp.http.proxyPort=1088 systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyPort=1088 - If you find these, either comment them out (add a
#at the start of each line) if you don't need the proxy, or confirm your proxy service is running properly. Then try building again withflutter runor./gradlew assembleDebug.
3. Switch to domestic Maven mirrors (optional, for network issues)
If you're having trouble accessing Google or JCenter repositories directly even without a proxy, replacing them with domestic mirrors (like Alibaba's) can fix the problem. Update your android/build.gradle like this:
buildscript { ext.kotlin_version = '1.4.10' repositories { maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/nexus/content/groups/public' } } dependencies { classpath 'com.android.tools.build:gradle:4.0.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.3' } } allprojects { repositories { maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/nexus/content/groups/public' } } }
This will let Gradle fetch dependencies from faster, more accessible mirrors instead of the official ones.
Your build error log:
FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring root project 'android'. > Could not resolve all artifacts for configuration ':classpath'. > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10. Required by: project : > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10. > Could not get resource 'https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.4.10/kotlin-gradle-plugin-1.4.10.pom'. > Could not GET 'https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.4.10/kotlin-gradle-plugin-1.4.10.pom'. > Connect to 127.0.0.1:1088 [/127.0.0.1] failed: Connection refused (Connection refused) > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10. > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.4.10/kotlin-gradle-plugin-1.4.10.pom'. > Could not GET 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.4.10/kotlin-gradle-plugin-1.4.10.pom'. > Connect to 127.0.0.1:1088 [/127.0.0.1] failed: Connection refused (Connection refused) > Could not resolve com.google.gms:google-services:4.3.3. Required by: project : > Could not resolve com.google.gms:google-services:4.3.3. > Could not get resource 'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.3/google-services-4.3.3.pom'. > Could not GET 'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.3/google-services-4.3.3.pom'. > Connect to 127.0.0.1:1088 [/127.0.0.1] failed: Connection refused (Connection refused) > Could not resolve com.google.gms:google-services:4.3.3. > Could not get resource 'https://jcenter.bintray.com/com/google/gms/google-services/4.3.3/google-services-4.3.3.pom'. > Could not GET 'https://jcenter.bintray.com/com/google/gms/google-services/4.3.3/google-services-4.3.3.pom'. > Connect to 127.0.0.1:1088 [/127.0.0.1] failed: Connection refused (Connection refused) * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 6s Exception: Gradle task assembleDebug failed with exit code 1
Your android/build.gradle configuration:
buildscript { ext.kotlin_version = '1.4.10' repositories { google() // Google's Maven repository jcenter() } dependencies { classpath 'com.android.tools.build:gradle:4.0.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.3' } } allprojects { repositories { google() // Google's Maven repository jcenter() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') } task clean(type: Delete) { delete rootProject.buildDir }
内容的提问来源于stack exchange,提问作者Zenko




