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

前端 未结 8 827
被撕碎了的回忆
被撕碎了的回忆 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: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'.

提交回复
热议问题