First and foremost, I am aware of the existence of this question - How do I add a library project to Android Studio? - and unfortunately, it has not helped me.
My goal is rather simple. I want to write an Android app using the Android Studio IDE (0.2.11), and the Guava libraries in my code.
I do not know Gradle, I've only started using Android Studio and my Visual Studio/C# background has dumbed me down, for which I apologize (in that Mickey Mouse world, you typically just add a library reference and off you go).
I will document my steps with screenshots. I mostly followed advice given in this answer.
I created a libraries
folder under my project folder.
![enter image description here](https://i.stack.imgur.com/aHKxM.png)
I cloned Guava repository into it.
![enter image description here](https://i.stack.imgur.com/fDAaK.png)
Files successfully appeared.
![enter image description here](https://i.stack.imgur.com/tTQbH.png)
I went to Project Structure
and selected Import Module
.
![enter image description here](https://i.stack.imgur.com/bFlSD.png)
![enter image description here](https://i.stack.imgur.com/iLSFO.png)
I selected Create module from existing sources
and agreed to all the default choices.
I updated my settings.gradle
file to include ':libraries:guava', ':Test'
:
![enter image description here](https://i.stack.imgur.com/M2pGw.png)
And my build.gradle
file with compile project(":libraries:guava")
:
![enter image description here](https://i.stack.imgur.com/IN7sM.png)
But all I'm getting whenever I'm trying to rebuild the project is:
Error: Gradle: A problem occurred configuring project ':Test'.
> Failed to notify project evaluation listener.
> Configuration with name 'default' not found.
I did try putting a build.gradle
as below in the guava
folder:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
(as the aforementioned answer says).
I have googled up and down to find the "correct" build.gradle
for Guava.
https://code.google.com/p/guava-libraries/wiki/UseGuavaInYourBuild - didn't help me, either.
I did try countless things which I will not describe here as they were rather haphazard - I tried adding a module dependency, I tried turning Use auto-import
on in Gradle settings
, etc.
I know it's not a way of solving issues and I promise I will diligently read Gradle's User Guide from 1 through 5.4.2 to 7.3, but I can't believe this is really prerequisite to achieve something as unremarkable as merely adding a library to a project? Why is there no default build.gradle
file from which one could start to fiddle with all sorts of things if necessary?
And the real question - how do I create an app (in Android Studio) that builds, actually runs on an Android device and on the top of that allows me to use Guava so I could sort a map by values without writing 50 lines of code? :)
Sorry about the chatty tone of my question, I know the drill around here, it's just my way of venting my frustration off.
Judging by how many votes were casted for questions and answers that tackled similar issues, I'm sure I'm not the only one who would benefit from some more instructions. I would start a bounty on it straight away, but the rules forbid me.
See Question&Answers more detail:
os