Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to build a project in Android Studio. The project uses Gradle.

At the time, maven.org is experiencing some problems and I get following errors:

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!

Is there a way I could drop these dependencies and make Android Studio self-sufficient? I would like to be able to build my Android projects even without internet connection and even if maven.org never recover.

EDIT:

If I understand it right, there is a way to setup local Maven repository and then use

repositories {
  mavenLocal()
}

instead of

repositories {
        mavenCentral()
    }

in build.gradle files.

Unfortunately, I am not sure if it's the way and what are downside of this approach.

UPDATE (December, 2013):

Android Studio now supports Gradle Offline mode (since version 0.4.0). More information can be found in release notes for the Studio.

like image 630
Bobrovsky Avatar asked Jul 31 '13 11:07

Bobrovsky


2 Answers

If you'd like to use maven local repo instead of remote one you need to add jar files to local repository.

Local maven repository is located at

~/.m2/repository

To compile android projects you need Android Builder library. You can download jar from http://mvnrepository.com/artifact/com.android.tools.build/builder/0.5.4 or compile source code by your own.

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

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.

Instead of command line adding libraries can be done by e.g. Archiva app.
http://archiva.apache.org/index.cgi

like image 149
Mike Avatar answered Nov 07 '22 02:11

Mike


For now you can swap

mavenCentral()

to

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

in your build.gradle

but for completely offline access you can create your local maven repository on your computer - probably

You can look at: How to use Sonatype Nexus with Gradle to proxy repsitories?

like image 42
Jacek Marchwicki Avatar answered Nov 07 '22 02:11

Jacek Marchwicki