Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to incorporate Volley (or other library) into Android Studio project

I've seen different advice on the best way to do this This question covers creating a jar. Elsewhere, I've seen advice to simply copy the volley source into your own project. This section on libraries at android.com would seem the most authoritative. However, after compiling volley, I don't have an aal library, whereas that section says I should have.

So my question is this: I have an existing Android Studio project with a standard layout, and a git repository; what should I do to add volley? Where should I download it to? How should I add it to Android Studio? Which Gradle files, if any, do I need to modify.

Hopefully, for those of you have done this a few times, this should be bread-and-butter stuff, but I haven't been able to find a straightforward description.

--

Updating, per Scott Barta's suggestion.

The gradle.build file in the volley repository has this line.

apply plugin: 'android-library' 

According to the documentation: "Library projects do not generate an APK, they generate a .aar package (which stands for Android archive)." However, when I build the volley project, no .aar is created.

My feeling is that as Volley is a library project, created by the Android team, it is most probably intended to be generated and used as .aar package. Any advice on whether it would be preferable to generate a .aar, and how to do that, would be appreciated.

like image 768
user3185563 Avatar asked Jan 11 '14 17:01

user3185563


People also ask

Is volley better than Retrofit?

Retrofit has full support for POST requests and multi part file uploads, with a sweet API to boot. Volley supports POST requests but you'll have to convert your Java objects to JSONObjects yourself (e.g., with Gson). Also supports multi part requests but you need to add these additional classes or equivalent.

How do I use volley library on Android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken text view to show response.

What is the purpose of using volley library in Android?

It manages the processing and caching of network requests and it saves developers valuable time from writing the same network call/cache code again and again. Volley is not suitable for large download or streaming operations since Volley holds all responses in memory during parsing.


2 Answers

As pointed out by others as well, Volley is officially available on Github:

Add this line to your gradle dependencies for volley:

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


To install volley from source read below:

I like to keep the official volley repository in my app. That way I get it from the official source and can get updates without depending on anyone else and mitigating concerns expressed by other people.

Added volley as a submodule alongside app.

git submodule add -b master https://github.com/google/volley.git volley 

In my settings.gradle, added the following line to add volley as a module.

include ':volley' 

In my app/build.gradle, I added a compile dependency for the volley project

compile project(':volley') 

That's all! Volley can now be used in my project.

Everytime I want to sync the volley module with Google's repo, i run this.

git submodule foreach git pull 
like image 97
shauvik Avatar answered Oct 13 '22 04:10

shauvik


LATEST UPDATE:

Use the official version from jCenter instead.

dependencies {     compile 'com.android.volley:volley:1.0.0' } 

The dependencies below points to deprecated volley that is no longer maintained.

ORIGINAL ANSWER

You can use this in dependency section of your build.gradle file to use volley

  dependencies {       compile 'com.mcxiaoke.volley:library-aar:1.0.0'   } 

UPDATED:

Its not official but a mirror copy of official Volley. It is regularly synced and updated with official Volley Repository so you can go ahead to use it without any worry.

https://github.com/mcxiaoke/android-volley

like image 20
Piyush Agarwal Avatar answered Oct 13 '22 04:10

Piyush Agarwal