cordova build android 出现cordova build android Could not resolve all files for configuration ‘:classp

使用 cordova run android 运行时,出现错误

* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:3.0.0.
     Required by:
         project :
      > Could not resolve com.android.tools.build:gradle:3.0.0.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom'.
            > Could not HEAD 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom'.
               > dl.google.com

根据报错提示,主要原因是主要是仓库不能下载问题(需要翻墙),于是在...\platforms\android\build.gradle中 的所有 repositories改为

 repositories {
       maven { url "http://maven.aliyun.com/nexus/content/groups/public/"}
 }

修改后执行“cordova run android”依然出现以下问题,奇怪了,网上很多解决方案都是这么解决的啊,呜呜...........

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 com.android.tools.build:gradle:4.0.0.
     Required by:
         project :
      > Could not resolve com.android.tools.build:gradle:4.0.0.
         > Could not get resource 'https://maven.aliyun.com/repository/google/com/android/tools/build/gradle/4.0.0/gradle-4.0.0.pom'.
            > Could not GET 'https://maven.aliyun.com/repository/google/com/android/tools/build/gradle/4.0.0/gradle-4.0.0.pom'. Received status code 400 from server: Bad Request
      > Could not resolve com.android.tools.build:gradle:4.0.0.
         > Could not get resource 'https://maven.aliyun.com/repository/jcenter/com/android/tools/build/gradle/4.0.0/gradle-4.0.0.pom'.
            > Could not GET 'https://maven.aliyun.com/repository/jcenter/com/android/tools/build/gradle/4.0.0/gradle-4.0.0.pom'. Received status code 400 from server: Bad Request
   > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50.
     Required by:
         project :
      > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50.
         > Could not get resource 'https://maven.aliyun.com/repository/google/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.50/kotlin-gradle-plugin-1.3.50.pom'.
            > Could not GET 'https://maven.aliyun.com/repository/google/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.50/kotlin-gradle-plugin-1.3.50.pom'. Received status code 400 from server: Bad Request
      > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50.
         > Could not get resource 'https://maven.aliyun.com/repository/jcenter/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.50/kotlin-gradle-plugin-1.3.50.pom'.
            > Could not GET 'https://maven.aliyun.com/repository/jcenter/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.50/kotlin-gradle-plugin-1.3.50.pom'. Received status code 400 from server: Bad Request

* 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 2s
Command failed with exit code 1: D:\workspace\Cordova\test\hello2\platforms\android\gradlew cdvBuildDebug -b D:\workspace\Cordova\test\hello2\platforms\android\build.gradle

继续寻找解决办法,根据错误提示,直接把“https://maven.aliyun.com/repository/jcenter/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.50/kotlin-gradle-plugin-1.3.50.pom”放到浏览器中是可以访问下载的,这久奇怪了,继续百度,找啊找,找到一篇网站说代理问题,需要修改"...platforms\android\gradle.properties"中的代理,打开项目中该文件,发现我并没有发现设置过代理,”操蛋“..........,接着查找问题。

org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m
android.useAndroidX=false
android.enableJetifier=false
systemProp.https.nonProxyHosts=localhost
#systemProp.https.proxyPort=1080
systemProp.http.proxyHost=127.0.0.1
systemProp.http.nonProxyHosts=localhost
#systemProp.https.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080

仓库也换了,项目内代理也没设置,这个怎么办,于是整理了问题的思路,脑洞大开,会不是gradle的全局设置了代理了,于是乎找到我电脑上安装的gradle:C:\Users\86183.gradle,该目录有一个gradle.properties文件,打开如下:

## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Fri May 08 17:49:28 CST 2020
systemProp.https.proxyPort=80
systemProp.http.proxyHost=mirrors.neusoft.edu.cn
systemProp.https.proxyHost=mirrors.neusoft.edu.cn
systemProp.http.proxyPort=80
android.injected.testOnly=false

果不其然,发现新大陆了,在该文件中设置了代理,于是乎,急忙把代理注释了,如下:

## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Fri May 08 17:49:28 CST 2020
#systemProp.https.proxyPort=80
#systemProp.http.proxyHost=mirrors.neusoft.edu.cn
#systemProp.https.proxyHost=mirrors.neusoft.edu.cn
#systemProp.http.proxyPort=80
#android.injected.testOnly=false

继续执行“cordova build android”,见证奇迹的时刻到了。

D:\workspace\Cordova\test\hello2>cordova build android
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=undefined (DEPRECATED)
Using Android SDK: D:\Program Files\Android\Sdk
Subproject Path: CordovaLib

> Task :app:mergeDebugResources
[Fatal Error] aapt2-4.0.0-6051327.pom:3:3: 文档中根元素前面的标记必须格式正确。
[Fatal Error] aapt2-4.0.0-6051327.pom:3:3: 文档中根元素前面的标记必须格式正确。

> Task :CordovaLib:compileDebugLibraryResources
[Fatal Error] aapt2-4.0.0-6051327.pom:3:3: 文档中根元素前面的标记必须格式正确。
[Fatal Error] aapt2-4.0.0-6051327.pom:3:3: 文档中根元素前面的标记必须格式正确。

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 1m 45s
40 actionable tasks: 40 executed
Built the following apk(s):
        D:\workspace\Cordova\test\hello2\platforms\android\app\build\outputs\apk\debug\app-debug.apk

编译通过了,至此问题解决了.............一下子心情大好!!!!!

总结

问题主要出在仓库地址和代理设置上。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值