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

前端 未结 8 801
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 17:55

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 proje

相关标签:
8条回答
  • 2020-11-30 18:33

    add

    compile 'com.mcxiaoke.volley:library:1.0.19'
            compile project('volley')
    

    in the dependencies, under build.gradle file of your app

    DO NOT DISTURB THE build.gradle FILE OF YOUR LIBRARY. IT'S YOUR APP'S GRADLE FILE ONLY YOU NEED TO ALTER

    0 讨论(0)
  • 2020-11-30 18:34

    For incorporate volley in android studio,

    1. paste the following command in terminal (
      git clone https://android.googlesource.com/platform/frameworks/volley ) and run it.

      Refer android developer tutorial for this.

      It will create a folder name volley in the src directory.
    2. Then go to android studio and right click on the project.
    3. choose New -> Module from the list.
    4. Then click on import existing Project from the below list.
    5. you will see a text input area namely source directory, browse the folder you downloaded (volley) and then click on finish.
    6. you will see a folder volley in your project view.
    7. the switch to android view and open the build:gradle(Module:app) file and append the following line in the dependency area:

      compile 'com.mcxiaoke.volley:library-aar:1.0.0'

    8. Now synchronise your project and also build your project.

    0 讨论(0)
  • 2020-11-30 18:41

    As of today, there is an official Android-hosted copy of Volley available on JCenter:

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

    This was compiled from the AOSP volley source code.

    0 讨论(0)
  • 2020-11-30 18:45

    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

    0 讨论(0)
  • 2020-11-30 18:51

    I have set up Volley as a separate Project. That way its not tied to any project and exist independently.

    I also have a Nexus server (Internal repo) setup so I can access volley as
    compile 'com.mycompany.volley:volley:1.0.4' in any project I need.

    Any time I update Volley project, I just need to change the version number in other projects.

    I feel very comfortable with this approach.

    0 讨论(0)
  • 2020-11-30 18:55

    Nowadays

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

    A lot of different ways to do it back in the day (original answer)

    • Add volley.jar as library

      1. Download it from: http://api.androidhive.info/volley/volley.jar
      2. Place it in your [MyProjectPath]/app/libs/ folder

    • Use the source files from git (a rather manual/general way described here)

      1. Download / install the git client (if you don't have it on your system yet): http://git-scm.com/downloads (or 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 (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.

    • Use gradle via the "unofficial" maven mirror

      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'.

    0 讨论(0)
提交回复
热议问题