简体   繁体   English

无法解决com.android.tools.build:gradle:0.5.+

[英]Could not resolve com.android.tools.build:gradle:0.5.+

I am trying to build a project in Android Studio. 我正在尝试在Android Studio中构建一个项目。 The project uses Gradle. 该项目使用Gradle。

At the time, maven.org is experiencing some problems and I get following errors: 当时,maven.org遇到了一些问题,我得到以下错误:

Gradle: A problem occurred configuring project ':MyProject'.
> Could not resolve all dependencies for configuration ':MyProject:classpath'.
> Could not resolve com.android.tools.build:gradle:0.5.+.
Required by:
Android:MyProject:unspecified
> Could not HEAD 'http://repo1.maven.org/maven2/com/android/tools/build/gradle/0.5.4/gradle-0.5.4.pom'. Received status code 503 from server: Service Temporarily Unavailable

It made me think I don't want to depend on maven.org and internet connection for my builds! 它让我觉得我不想依靠maven.org和互联网连接来构建我的版本!

Is there a way I could drop these dependencies and make Android Studio self-sufficient? 有没有办法可以放弃这些依赖项并让Android Studio自给自足? I would like to be able to build my Android projects even without internet connection and even if maven.org never recover. 即使没有互联网连接,即使maven.org永远无法恢复,我也希望能够构建我的Android项目。

EDIT: 编辑:

If I understand it right, there is a way to setup local Maven repository and then use 如果我理解正确,有一种方法可以设置本地Maven存储库然后使用

repositories {
  mavenLocal()
}

instead of 代替

repositories {
        mavenCentral()
    }

in build.gradle files. build.gradle文件中。

Unfortunately, I am not sure if it's the way and what are downside of this approach. 不幸的是,我不确定这种方法的方式和缺点是什么。

UPDATE (December, 2013): 更新(2013年12月):

Android Studio now supports Gradle Offline mode (since version 0.4.0 ). Android Studio现在支持Gradle Offline模式(自版本0.4.0起 )。 More information can be found in release notes for the Studio. 可以在Studio的发行说明中找到更多信息。

If you'd like to use maven local repo instead of remote one you need to add jar files to local repository. 如果您想使用maven local repo而不是远程repo,则需要将jar文件添加到本地存储库。

Local maven repository is located at 本地maven存储库位于

~/.m2/repository

To compile android projects you need Android Builder library. 要编译android项目,您需要Android Builder库。 You can download jar from http://mvnrepository.com/artifact/com.android.tools.build/builder/0.5.4 or compile source code by your own. 您可以从http://mvnrepository.com/artifact/com.android.tools.build/builder/0.5.4下载jar或自行编译源代码。

To install this library type in your command line: 要在命令行中安装此库类型:

mvn install:install-file -DgroupId=com.android.tools.build \
-DartifactId=builder \
-Dversion=0.5.4 \
-Dfile=builder-0.5.4.jar \
-Dpackaging=jar \
-DgeneratePom=true

Then in build.gradle file you can use 然后在build.gradle文件中即可使用

mavenLocal()

instead of 代替

mavenCentral()

Obviously it may turns out that to you need some extra libs in local repo to run Android project, but process of adding different libs is exactly same as above. 显然,可能会发现在本地仓库中需要一些额外的库来运行Android项目,但添加不同库的过程与上面完全相同。

Instead of command line adding libraries can be done by eg Archiva app. 而不是命令行添加库可以通过例如Archiva app完成。
http://archiva.apache.org/index.cgi http://archiva.apache.org/index.cgi

For now you can swap 现在你可以交换

mavenCentral()

to

maven { url "http://us.maven.org/maven2/" }

in your build.gradle 在你的build.gradle中

but for completely offline access you can create your local maven repository on your computer - probably 但是对于完全脱机访问,您可以在计算机上创建本地maven存储库 - 可能

You can look at: How to use Sonatype Nexus with Gradle to proxy repsitories? 你可以看一下: 如何使用带有Gradle的Sonatype Nexus来代理销售代理?

please check your internet connectivity 请检查您的互联网连接

after reading the second part of your question: - the stuff gets cached - so you are able to build even without internet connectivity 在阅读了问题的第二部分后: - 这些内容被缓存 - 因此即使没有互联网连接,您也可以构建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM