可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I've just pulled down an Android project from git, and Android Studio is giving me the following error whenever I attempt to open it;
Error:Could not find com.android.tools.build:gradle:2.2.0-alpha6. Searched in the following locations: https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.0-alpha6/gradle-2.2.0-alpha6.pom https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.0-alpha6/gradle-2.2.0-alpha6.jar https://maven.fabric.io/public/com/android/tools/build/gradle/2.2.0-alpha6/gradle-2.2.0-alpha6.pom https://maven.fabric.io/public/com/android/tools/build/gradle/2.2.0-alpha6/gradle-2.2.0-alpha6.jar Required by: newApp_Android:app:unspecified
I've installed Gradle locally, and set up environment paths via System.
Under Project Structure/Project, the following setup is in use;
Gradle Version : 2.10 Android Plugin Version : 2.2.0-alpha6 Android Plugin Repository : jcenter Default Library Repository : jcenter
Could anyone point me in the right direction on this?
回答1:
This is because the build process is unable to find the dependency in Maven repository. Add jcenter() along with mavenCentral() in your project level build.gradle file.
buildscript { repositories { mavenCentral() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.0' } }
回答2:
So I had a similar error while I was trying to build ionic2 project for android. This happened after android studio updated gradle during its updates.
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
I read the above answers which pointed to update a 'build.gradle' file but turns out there were multiple files with that name in the project. What worked for me (and hopefully helpful to whoever is working on angular2/ionic2 project and having this issue) is updating the build.gradle file at
[rootOfPorject]/platforms/android/CordovaLib/build.gradle
This file was missing the jcenter() entry and now the repository part looks like this and works like a charm.
repositories { jcenter() mavenCentral() }
Hope this saves time for someone else.
EDIT: As @rcerecedar mentioned, you might also need to add jcenter()
in the following file as well.
[rootOfPorject]/platforms/android/build.gradle
In this file you should check its present in buildscript -> repositories
and also optionally in allprojects -> repositories
回答3:
1.Goto "C:\Program Files\Android\Android Studio\gradle\m2repository\com\android\tools\build\gradle"
2.See the Latest folder name , i.e "2.2.3" , Copy It.
3.Go to build.gradle(Module:yourapp) file ,
Place here:
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:2.2.3' }
回答4:
If you have firewall configured in your PC,try the following in gradle.properties.
systemProp.https.proxyHost= systemProp.https.proxyPort=8080 systemProp.https.proxyUser= systemProp.https.proxyPassword= systemProp.https.nonProxyHosts=www.google.com|localhost
回答5:
What worked for me was i did exactly what "geekydhaval" said, thanks again for that but I went back to the dependencies { classpath 'com.android.tools.build:gradle:2.3.0' } and change from 2.3.2 to 2.3.0 and the build completed successfully.
回答6:
Replace the gradle:2.2.0-alpha6
to gradle:2.2.0-alpha3
.
If this doesn't work replace it to gradle:2.2.0-alpha2
.