Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Volley Android Networking Library

$ git clone https://android.googlesource.com/platform/frameworks/volley
$ cd volley
$ android update project -p .
$ ant jar

Then, copy bin/volley.jar into your libs/ folder and off you go!

source


In the Volley lesson, Google instructs as to either add Volley to our project as an Android Library project or as a .jar file.

Here's how to create the Volley .jar file using Android Studio or Eclipse:

NOTE:

In both cases I suggest renaming the .jar file to the date of Volley's latest commit, i.e. volley_20150319.jar, to keep versioning simple.


Android Studio:

  1. Clone the Volley repository via Git.
  2. Import the project into Android Studio. (I usually select the project's gradle file when importing in Android Studio)
  3. Build the project. (I had to change the gradle build settings to reflect the latest build tools and gradle version, but it's usually up to date).
  4. In your file explorer, navigate to [your local path to volley]/build/intermediate/bundles/
  5. In both the debug and release folders you'll find a JAR file called classes.jar.
  6. Copy either JAR file into your libs/ folder.
  7. Gradle sync, and you're done.

Eclipse:

  1. Clone the Volley repository via Git.
  2. Import the project into eclipse.
  3. Right-click the project and select Export...
  4. Select Java / JAR file.
  5. We're only interested in the src folder and nothing else. The easiest way to make sure only it is selected is to deselect the project and then select the src folder inside.
  6. Check the Export generated class files and resources option.
  7. OPTIONAL: If you want the Javadoc to be visible also select the Export Java source files resources.
  8. Create the JAR file and put it in your libs/ folder.

1) Is this library can also be used as networking library in normal Java projects also OR is it strictly for Android Only

It is for Android only, as it depends on Android-specific classes. You can tell this by looking at the source code, for stuff like RequestQueue.

2) I see multiple branches here and no documentation on which branch is to start with. Which branch should I use to start with?

The instructions from the Google I|O presentation were to just clone the git repo, which would pull from the master branch by default.

3) How to integrate this library in your own project? What approach is better: Make Volley as a standalone library project and spin a jar and put it in your project or Copy the all source code inside your project?

The instructions from the Google I|O presentation were to add the source code to your project. Personally, I find this to be a bizarre approach.


you can download the volley.jar

Source : AndroidHive

copy theVolley.jar to libs

Then

Right Click volley.jar -> Add As Library

enter image description here


The Volley library is now published by the Android Open Source Project:

dependencies {
    implementation 'com.android.volley:volley:1.1.0'
}

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

compile 'com.android.volley:volley:1.0.0'

DEPRICATED WAY:

If you're using Gradle, you can import Volley from here.

dependencies {
    compile 'com.mcxiaoke.volley:library:1.0.+'
}

Note

This is an unofficial mirror (with some minor bugfix, see Changelog for details.) for android volley library, the source code will synchronize periodically with the official volley repository.


Plenty of ways

Since there are many answers about a single approach, but none that is comparing the different ways to get volley up and running, I also put my two cents in. Feel free to edit/enhance this answer as well.

Add it as library - (quick solution)

  1. Download it from: androidhive
  2. Place it in your [MyProjectPath]/app/libs/ folder
  3. In Android Studio right-click on it and select Add As Library...

Source files from git - (a rather official solution)

  1. Download / install the git client (if you don't have it on your system yet) (othervise via git clone https://github.com/git/git ... sry bad one, but couldn't resist ^^)
  2. Execute git clone https://android.googlesource.com/platform/frameworks/volley
  3. Copy the com folder from within [path_where_you_typed_git_clone]/volley/src to your projects app/src/main/java folder (or integrate it instead, if you already have a com folder there!! ;-))

    The files show up immediately in Android Studio. For Eclipse you will have to right-click on the src folder and press refresh (or F5) first.

    Doing it via git is what is officially suggested in the android tutorials (look here).

Gradle via an "unofficial" mirror - (dynamic solution)

  1. In your project's src/build.gradle file add following volley dependency:

        dependencies {
            compile fileTree(dir: 'libs', include: ['*.jar'])
            // ...
    
            compile 'com.mcxiaoke.volley:library:1.+'
        }
    
  2. Click on Try Again which should right away appear on the top of the file, or just Build it if not

    The main "advantage" here is, that this will keep the version up to date for you, whereas in the other two cases you would have to manually update volley.

    On the "downside" it is not officially from google, but a third party weekly mirror.

    But both of these points, are really relative to what you would need/want. Also if you don't want updates, just put the desired version there instead e.g. compile 'com.mcxiaoke.volley:library:1.0.7'.