91

I wanna use the google's volley library

I am using Android Studio and I know how to add .jar libraries.

But I could not create a .jar library with the volley files:

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

Here what I did: (using windows seven)

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

And I get the output:

A java exception has occured.

what is wrong? how can i add a not .jar library?

Ali Khaki
  • 1,184
  • 1
  • 13
  • 24
nsvir
  • 8,781
  • 10
  • 32
  • 47
  • If you want to use volley as a dependency module rather than jar file, you can follow [link](http://stackoverflow.com/a/23402162/1093344) – cmoaciopm May 01 '14 at 04:55
  • Possible duplicate of [Best way to incorporate Volley (or other library) into Android Studio project](http://stackoverflow.com/questions/21065477/best-way-to-incorporate-volley-or-other-library-into-android-studio-project) – Sam Stern Feb 14 '16 at 07:09
  • Importing volley tutorial : https://gitsubmoduleasandroidtudiomodule.blogspot.in/ – Arpit Ratan Jul 05 '16 at 18:14

18 Answers18

186

Volley is now officially available on JCenter:

Add this line to your gradle dependencies for your Android project's app module:

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

Abdul Rehman
  • 13
  • 2
  • 4
shauvik
  • 3,912
  • 2
  • 23
  • 18
  • 2
    @Shavik Gradle is not sync while adding this to build.gradle file, i am getting error like : Failed to resolve: com.android.volley:volley:1.0.0 – Sundeep Badhotiya Aug 11 '16 at 07:20
  • 4
    I had a similar problem like @SundeepBadhotiya It was solved by putting mentioned compile statement into the build.gradle of the Module, not the gradle file of the Project. – DBX12 Sep 12 '16 at 12:10
  • Should I use `com.android.volley:volley:1.0.0` or `com.mcxiaoke.volley:library-aar:1.0.0`? – pb772 Aug 15 '17 at 00:30
  • 1
    I've tried this but it still won't sync, is there something I'm missing? – Clive Makamara Sep 20 '17 at 09:17
  • 1
    last version is 1.1.0 and in android studio 3 you should use : implementation 'com.android.volley:volley:1.1.0' – Meisam Aug 21 '18 at 08:19
53

So Volley has been updated to Android studio build style which makes it harder create a jar. But the recommended way for eclipse was using it as a library project and this goes for android studio as well, but when working in android studio we call this a module. So here is a guide to how do it the way Google wants us to do it. Guide is based on this nice tutorial.

  1. First get latest volley with git (git clone https://android.googlesource.com/platform/frameworks/volley).

  2. In your current project (android studio) click [File] --> [New] -->[Import Module].

  3. Now select the directory where you downloaded Volley to.

  4. Now Android studio might guide you to do the rest but continue guide to verify that everything works correct

  5. Open settings.gradle (find in root) and add (or verify this is included):

    include ':app', ':volley'

  6. Now go to your build.gradle in your project and add the dependency:

    compile project(":volley")

Thats all there is to it, much simpler and easier than compiling a jar and safer than relying on third parties jars or maven uploads.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Warpzit
  • 27,966
  • 19
  • 103
  • 155
  • 1
    This is what solved my problem. However I complicated it by moving the submodule into a directory I created called "3rd_party". I had to change the statements above to `include ':app', ':3rd_party:volley'`, and `compile project(":3rd_party:volley")`. (Using colons to delineate folders tripped me up at first, first thinking it might just be denoting a relative path) – ahall Sep 20 '15 at 03:06
19

Updating Warpzit's answer for Android Studio 1.3.2 (differences in bold)
(update: appears to be the same for Android 2.0)

  1. First get latest volley with git.
  2. In your current project (android studio) click [file] --> [New]--> [New Module].
  3. Now select [Import Gradle Project], Click Next
  4. Now select the directory where you downloaded Volley to.
  5. Now Android studio might guide you to do the rest but continue guide to verify that everything works correct
  6. Open settings.gradle (find in root) and add (or verify this is included):

    include ':app', ':volley'

  7. Now go to your build.gradle in your project and add the dependency:

    compile project(":volley")

Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
  • This seems to import the module into app and not root, which buggers everything up. Any idea as to why that would be? – Cruncher Oct 21 '15 at 17:24
  • DEPRECATED. This answer is no longer valid. While it would technically "work" you really really shouldn't do it this way in 2018+ Use compile 'com.android.volley:volley:.0.0' – StarWind0 Apr 02 '18 at 18:26
18

Way too complicated guys. Just include it in your gradle dependencies:

dependencies {
    ...
    compile 'com.mcxiaoke.volley:library:1.0.17'
}
wild_nothing
  • 2,845
  • 1
  • 35
  • 47
  • 17
    It is worth pointing out that this isn't an official repository. As such, there is always the possibility that malicious code could be included in this. Probably not going to happen, right? But best to be aware it could. – Craig Russell Sep 08 '15 at 10:21
  • For beginners with gradle, here're some more details: https://blog.chrisblunt.com/android-getting-started-with-volley/ – BurninLeo Feb 27 '16 at 13:45
  • 5
    DEPRECATED Please note, this project is deprecated and no longer being maintained, please use official version from jCenter. compile 'com.android.volley:volley:1.0.0' – StarWind0 Jan 15 '17 at 09:37
10

Most of these answers are out of date.

Google now has an easy way to import it.. We will continue to see a lot of outdated information as they did not create this solution for a good 2-3 years.

https://bintray.com/android/android-utils/com.android.volley.volley/view

All you need to do is add to your Build.Gradle the following:

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

IE

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "24.0.0"
    defaultConfig {
        applicationId "com.example.foobar.ebay"
        minSdkVersion 23
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.volley:volley:1.0.0'
    testCompile 'junit:junit:4.12'
}
Junior Mayhé
  • 16,144
  • 26
  • 115
  • 161
StarWind0
  • 1,554
  • 2
  • 17
  • 46
3

Add this line to the dependencies in build.gradle:

compile 'com.mcxiaoke.volley:library:1.0.+'
Victor Odiah
  • 1,061
  • 11
  • 14
3

After putting compile 'com.android.volley:volley:1.0.0' into your build.gradle (Module) file under dependencies, it will not work immediately, you will have to restart Android Studio first!

Smith
  • 5,765
  • 17
  • 102
  • 161
doncic
  • 31
  • 1
  • I was facing this issue and a restart worked for me. However, there has to be a better way! – Nikhil Gupta Aug 30 '17 at 18:15
  • All you need to do is refresh your dependencies. Restarting probably started this for you. There is a banner at the top of the screen that appears asking you to refresh. Hard to miss. Just press that next time. – StarWind0 Sep 14 '17 at 16:06
  • Unbelievably, restarting android studio solved our afternoon of trying to fix this :( – Luke Oct 26 '18 at 15:59
2

Add this dependency in your gradle.build(Module:app)file

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

And then sync your gradle file.

Bhumi Unadkat
  • 31
  • 1
  • 2
1

In the "build.gradle" for your app, (the app, not the project), add this:

dependencies {
    ...
    implementation 'com.android.volley:volley:1.1.0'
}
Tim Cooper
  • 10,023
  • 5
  • 61
  • 77
1

Add this in your "build.gradle" of you app.

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

Sanjay Goswami
  • 191
  • 2
  • 7
0

Or you can simply do

ant jar

in your cloned volley git project. You should now see volley.jar in the volley projects bin folder. Copy this to you Android Studio's app\libs folder. Then add following under dependencies section of Module level build.gradle file -

compile files('libs/volley.jar')

And you should be good import and use the library classes in your project,

angryITguy
  • 9,332
  • 8
  • 54
  • 82
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
0

To add volley as submodule and getting regular updates from the GIT repo the following steps can be followed. Main advantage is, Volley can be customised and source code could be pull from GIT repo whenever update is required.

It is also helping for debugging purpose.

Follow the below steps :

Step I :

Add volley as submodule in Android application project GIT Repo. git submodule add -b master https://android.googlesource.com/platform/frameworks/volley Libraries/Volley

Step II :

In settings.gradle, add the following to add volley as a studio project module. include ':Volley' project(':Volley').projectDir=new File('../Libraries/Volley')

Step III :

In app/build.gradle, add following line to compile Volley compile project(':Volley')

That would be all! Volley has been successfully added in the project.

Every time you want to get the latest code from Google official Volley's repo, just run the below command

git submodule foreach git pull

For more detailed information : https://gitsubmoduleasandroidtudiomodule.blogspot.in/

GIT Repo sample code : https://github.com/arpitratan/AndroidGitSubmoduleAsModule

Arpit Ratan
  • 2,976
  • 1
  • 12
  • 20
0

The "compile project(':volley')" line was giving me this error:

Error:Execution failed for task ':volley:processDebugResources'. > com.android.ide.common.process.ProcessException: Failed to execute aapt

It was caused because the compileSdk and buildTools versions of module volley were currently on"22" and "22.0.1" and I my project was working with newer ones ("24" and "24.0.1").

SOLUTION:

Open your build.gradle (Module:volley) file and change the version of "compileSdk" and "buildTools", for example I changed this:

android {
    compileSdkVersion 22
    buildToolsVersion = '22.0.1'
}

for this:

android {
    compileSdkVersion 24
    buildToolsVersion = '24.0.1'
}

You should no longer have this error, I hope it helps:)

Alan Barrera
  • 11
  • 1
  • 1
0

it also available on repository mavenCentral() ...

dependencies {
    // https://mvnrepository.com/artifact/com.android.volley/volley
    api "com.android.volley:volley:1.1.0'
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
0

two things

one: compile is out of date rather it is better to use implementation,

and two: volley 1.0.0 is out of date and syncing project will no work

alternatively in build.gradle add implementation 'com.android.volley:volley:1.1.1' or implementation 'com.android.volley:volley:1.1.+' for 1.1.0 and newer versions.

Poul Bak
  • 10,450
  • 5
  • 32
  • 57
0

add this line to your manifest file inside android:usesCleartextTraffic="true"

sumanth
  • 318
  • 1
  • 6
  • 25
-1

add volly to your studio gradle app by compile 'com.android.volley:volley:1.0.0'

Manish
  • 234
  • 2
  • 13
-1

step 1:- Download volley.jar file.

step 2:- Go to your project and set the display menu from Android to Project then go to

app -> libs-> paste your volley.jar file here

step 3:- Right click on the volley.jar file and click on "add as library". and its all done.

Sanoop Surendran
  • 3,484
  • 4
  • 28
  • 49