Import Android volley to Android Studio

209,407

Solution 1

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'

Solution 2

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.

Solution 3

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")

Solution 4

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

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

Solution 5

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'
}
Share:
209,407
nsvir
Author by

nsvir

Updated on July 14, 2021

Comments

  • nsvir
    nsvir almost 3 years

    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?

  • Craig Russell
    Craig Russell over 8 years
    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.
  • ahall
    ahall over 8 years
    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)
  • Cruncher
    Cruncher over 8 years
    This seems to import the module into app and not root, which buggers everything up. Any idea as to why that would be?
  • The_Martian
    The_Martian over 8 years
    Step 2 should be File>New>Import Module.
  • Warpzit
    Warpzit over 8 years
    @The_Martian thanks, I've updated it to reflect the Android studio updates.
  • BurninLeo
    BurninLeo about 8 years
    For beginners with gradle, here're some more details: blog.chrisblunt.com/android-getting-started-with-volley
  • Sundeep Badhotiya
    Sundeep Badhotiya almost 8 years
    @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
  • DBX12
    DBX12 over 7 years
    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.
  • StarWind0
    StarWind0 over 7 years
    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'
  • pb772
    pb772 almost 7 years
    Should I use com.android.volley:volley:1.0.0 or com.mcxiaoke.volley:library-aar:1.0.0?
  • Nikhil Gupta
    Nikhil Gupta over 6 years
    I was facing this issue and a restart worked for me. However, there has to be a better way!
  • StarWind0
    StarWind0 over 6 years
    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.
  • Clive Makamara
    Clive Makamara over 6 years
    I've tried this but it still won't sync, is there something I'm missing?
  • StarWind0
    StarWind0 about 6 years
    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:<current version here>.0.0'
  • Meisam
    Meisam over 5 years
    last version is 1.1.0 and in android studio 3 you should use : implementation 'com.android.volley:volley:1.1.0'
  • Luke
    Luke over 5 years
    Unbelievably, restarting android studio solved our afternoon of trying to fix this :(