Android Studio + Volley [duplicate]
Asked Answered
D

4

45

I'm new to Android Studio and I want to use Volley library for my app but i can't add the source as a library in Android Studio.

I've searched the web but couldn't find anything. Everywhere is said to import as a library but I don't know how.

I got the volley source from git repository:

https://android.googlesource.com/platform/frameworks/volley

But I don't know how to add it to my project as a library.

Dilapidated answered 29/8, 2013 at 14:9 Comment(4)
To use volley as a dependency module, you can follow linkZolazoldi
Here is a link to an image-based tutorial on how to incorporate Volley as a module linkParallelism
Why don't they just add it to maven so we can use it as a dependency?Patinated
I was wondering if they keep it separate because they plan on integrating it into the SDK like they've done with the Apache stuff in the past? (Of course that has been superseded by java.net.HttpURLConnection)Haire
S
90

UPDATE: Volley is now official and is available through the JCenter. Here's how to import it:

implementation 'com.android.volley:volley:1.1.1'

DEPRICATED WAY:

Late to the party, but was able to import it by adding this to the build.gradle file:

dependencies {
    compile 'com.mcxiaoke.volley:library:1.0.19'
}

Here is the link to unofficial Maven repo

NOTE: Volley v1.0.19 is current as of 02/05/2016. Please go to the Maven Repo (use link above), look up the latest version (line where artifactId = library) and update the version in your gradle configuration accordingly.

Sunda answered 21/7, 2014 at 18:21 Comment(2)
Note that this is not from google, but simply a weekly mirror of it from someone else (no problem with that and still very helpful, but worth noting).Kyla
Comment above does not apply to the update of this answer. It is now officially maintained by Google.Sunda
R
23

If you don't want to import it as a module but simply use it as a dependency you can create a jar using ant. In your volley directory just type ant jar and you will find a volley.jar in YOUR_VOLLEY_DIRECTORY/bin (you need to install apache ant if you don't have it)

You can copy the jar in the libs directory in your android app project (or create a libs directory if you don't have one) and add the dependency to build.gradle like this

compile files('libs/volley.jar')
Railway answered 29/8, 2013 at 19:39 Comment(1)
I simply can't understand why they don't put it on maven...Presbyterial
A
3

I know this is a little later than the other 2 answers, but I couldn't get the JAR import method to work, or exporting Volley to Gradle as the latest version kept on producing errors that the Gradle version was too old...

What I did was to create a new package in my project of com.android.volley, and then copy the source code from the Volley package, making sure that you have both volley and volley/toolbox - once I did this the app ran without an issue

I'm not very good at GIT, but there must be a way to export just the package into the root of your Gradle Java source

Alyssa answered 30/10, 2013 at 15:30 Comment(0)
D
1

Edit: As pointed out in the comments, this doesn't work anymore.

File -> Import Module...

Select directory where you downloaded Volley and follow all of the directions (you probably won't have to change anything, just click "Next" a bunch.)

Then, start typing your volley stuff:

private static RequestQueue queue;

As you're typing RequestQueue, it might autosuggest it, or it might turn red after you type it (I can't remember for sure). If it autosuggests it, just select it, and you're done. If it's red and underlined, press Alt-Enter, and there should be an option for something like "Add from module 'volley'" Select that, and you're done.

(Sorry if this isn't all exact. It's from memory.)

Dilatation answered 29/8, 2013 at 14:54 Comment(2)
You said: "File -> Import Module...". However, that is not an option in Android Studio 0.4.2. There is only File -> Import Project.Aquilegia
@Aquilegia Yes, I believe it was at the time of this post, but it's gone now. You should use Gradle as described in the other answer instead. Thanks!Dilatation

© 2022 - 2024 — McMap. All rights reserved.