Android Studio, Gradle and Maven

3,843 views
Skip to first unread message

Reece Dunn

unread,
Jul 14, 2013, 3:00:47 PM7/14/13
to adt...@googlegroups.com
Hi,

I am trying to point Android Studio and Gradle at the same local Maven directory to avoid downloading duplicate files when building in Android Studio and via Gradle on the command line.

Android Studio uses MAVEN_REPOSITORY which points to ~/.m2/repository. This can easily be changed. Gradle uses ~/.gradle. More specifically, it looks like the the files are stored in ~/.gradle/caches/artifacts-24/filestore.

Q: Is there a way to configure the location Gradle uses for Maven? NOTE: I am using Gradle 1.6 and the /usr/bin/gradle script is the same as the one provided by gradlew (except it runs org.gradle.laincher.GradleMain).

Q: Is it possible to force Android Studio to let Gradle handle the Maven repository dependencies (so the behaviour is the same between the two)?

With Android Studio, the Maven repository looks like:

    com/google/android/support-v4/r7/support-v4-r7.jar
    com/google/android/support-v4/r7/support-v4-r7.jar.sha1
    com/google/android/support-v4/r7/support-v4-r7.pom
    com/google/android/support-v4/r7/support-v4-r7.pom.sha1

whereas with Gradle, it looks like:

    com.google.android/support-v4/r7/jar/24d0f6da34c3a2bfcf736ab42d51c91ac821ee22/support-v4-r7.jar
    com.google.android/support-v4/r7/pom/aef29a63d7075a26930b0c67f1333729be7c4a6e/support-v4-r7.pom

Q: Why are these layouts different?

Additionally, I have noted that Gradle 1.6 uses the maven 3.0.4 plugin, whereas Android Studio 0.2.0 uses maven 3.0.3 (it also has maven 2.2.1 installed).

NOTE: It looks like Android Studio uses Maven 2 by default. I am not sure, as the only reverence to 2 vs 3 is in "Maven > Importing > Use Maven3 to import project". There is no option about Gradle using Maven 2.

Q: How do I make the builds consistent between Android Studio and the Gradle command line?

Jonathan Steele

unread,
Jul 14, 2013, 3:36:52 PM7/14/13
to adt...@googlegroups.com
If you do compile 'com.android.support:support-v14:13.0.+', it will use local maven repo

Reece Dunn

unread,
Jul 14, 2013, 3:52:30 PM7/14/13
to adt...@googlegroups.com


On Sunday, 14 July 2013 20:36:52 UTC+1, Jonathan Steele wrote:
If you do compile 'com.android.support:support-v14:13.0.+', it will use local maven repo

What do you mean by "local maven repo"? For Gradle, this is ~/.gradle/caches/artifacts-24/filestore and for Android Studio it is ~/.m2/repository.

Also, ActionBarSherlock specifies:

  compile 'com.google.android:support-v4:r7'

NOTE: I do not have the "Android Support Repository" installed, if that is what you are referring to.

Jonathan Steele

unread,
Jul 14, 2013, 3:58:55 PM7/14/13
to adt...@googlegroups.com
Yeah. I was not aware you use ABS.

if you do mavenLocal(), it should look for ~/.m2/repository

Reece Dunn

unread,
Jul 14, 2013, 4:27:28 PM7/14/13
to adt...@googlegroups.com


On Sunday, 14 July 2013 20:58:55 UTC+1, Jonathan Steele wrote:
Yeah. I was not aware you use ABS.

if you do mavenLocal(), it should look for ~/.m2/repository

If in ActionBarSherlock/build.gradle (from the dev branch), I use;

-----
  repositories {
    mavenLocal()
  }
-----

I get the error:

-----
.../ActionBarSherlock$ gradle assemble
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'ActionBarSherlock'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not find any version that matches com.android.tools.build:gradle:0.4.+.
     Required by:
         :ActionBarSherlock:unspecified
-----

If I use:

-----
  repositories {
    mavenLocal()
    mavenCentral()
  }
-----

gradle puts the Maven files in ~/.gradle/caches/artifacts-24/filestore/.
 

Reece Dunn

unread,
Jul 14, 2013, 4:33:45 PM7/14/13
to adt...@googlegroups.com

NOTE: Using just |mavenLocal()| works in Android Studio (provided that the files were previously fetched via |mavenCentral()|). It fails as noted above when building with gradle on the command line (using the Gradle 1.6 binaries from http://www.gradle.org/downloads).
 

Jonathan Steele

unread,
Jul 14, 2013, 6:03:42 PM7/14/13
to adt...@googlegroups.com
I see what you did. you put mavenLocal inside buildscript's repo. When it is trying to look for the android plugin in another local maven repo, gradle can't find it.

buildscript {
    repositories.mavenCentral()
    dependencies.classpath 'com.android.tools.build:gradle:0.5.+'
}

repositories {
    mavenLocal()
}

This should fix your problem because buildscript uses mavenCental for gradle plugin and use mavenlocal for libraries.

Xavier Ducrohet

unread,
Jul 16, 2013, 1:26:38 PM7/16/13
to adt...@googlegroups.com
 ~/.gradle/caches/artifacts-24/filestore is not a maven repository. It's a cache of artifacts coming from repositories.

In your build.gradle you should always reference actual repositories. So as Jonathan said, just use 

repositories {
   mavenLocal()
}




--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Reece Dunn

unread,
Jul 16, 2013, 1:41:56 PM7/16/13
to adt...@googlegroups.com


On Tuesday, 16 July 2013 18:26:38 UTC+1, Xavier Ducrohet wrote:
 ~/.gradle/caches/artifacts-24/filestore is not a maven repository. It's a cache of artifacts coming from repositories.

In your build.gradle you should always reference actual repositories. So as Jonathan said, just use 

repositories {
   mavenLocal()
}

Thanks Xavier & Jonathan -- I now understand how this all works.

- Reece
 
Reply all
Reply to author
Forward
0 new messages