How do I add Guava to my Android Studio project?
If you just need to use a stable, released version of the Guava libraries, importing it is extremely easy.
Just go to the build.gradle
file of the module where you want to use the library (i.e GuavaTestProject/GuavaTest/build.gradle
) and, right after
repositories { mavenCentral()}
add a Maven dependency:
dependencies { compile group: 'com.google.guava', name: 'guava', version: '15.0'}
Rebuild your project if needed and that's all (tested right now with a fresh project created with Android Studio 0.2.13).
If you really need to include the source code of the Guava library and compile it yourself as a module of your Gradle build that's an entirely different problem because Guava is build with Maven and so you need to move the Guava build system from Maven to Gradle, which I think is overwhelmingly complex for your goals.
If you just need to browse the source or view it while debugging, what I would do is:
Download Guava source code on a separate folder:
git clone https://code.google.com/p/guava-libraries/git checkout v15.0
When Android Studio doesn't find the sources, click on "Attach sources" and point to this alternative location.
I think if you don't need to actually modify and compile Guava source code this is the easiest solution.
dependencies { compile 'com.google.guava:guava:19.0'}
Source: https://github.com/google/guava
EDIT:As of v22, there's specific guava version for Android.
dependencies { compile 'com.google.guava:guava:22.0-android'}
* Thanks Sam :)
Thats a lot of info in your question.I am using Guava
too. But I don't remember going through any of this trouble..
Guava
is available on the mavencentral
. So adding guava to your project should be fairly simple. AFAIK, you do not need to checkout, build and add a project dependency etc..
See gradle file for my app below.
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.+' }}apply plugin: 'android'repositories { mavenCentral()}// Dependenciesdependencies { compile fileTree(dir: 'libs', include: '*.jar') // jar files under the libs folder. compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar' // actionbarsherlock, compile 'com.android.support:support-v4:18.0.0' // android support lib compile 'com.google.code.gson:gson:2.2.4' // google GSON compile 'com.google.guava:guava:14.0.1' // guava 14.0.1}