1.下载Volley
1 git clone https://android.googlesource.com/platform/frameworks/volley
2.进入Volley目录
1 cd volley/
3.运行
1 gradle build
参考网上帖子,这命令可直接运行,但因为我没配置ANDROID_HOME环境变量,导致报错
1 FAILURE: Build failed with an exception. 2 3 * What went wrong: 4 A problem occurred configuring root project 'volley'. 5 > SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable. 6 7 * Try: 8 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 9 10 BUILD FAILED 11 12 Total time: 4.523 secs
因此,写入一个local.properties文件到volley目录下
local.properties很简单,就一行
1 sdk.dir=/Users/users/Library/Android/sdk
重新运行
1 gradle build
这时候,gradle会下载非常多的依赖包(查看build.gradle看到volley中使用的gradle版本是1.3.1,但我自己系统本身有2.2.1版本的,所以直接修改了此版本号,但在运行过程中,出现各种问题,因此后面又改1.3.1版本)
运行到lint指令时,会报错
1 :lint 2 Ran lint on variant release: 2 issues found 3 Ran lint on variant debug: 2 issues found 4 Wrote HTML report to file:/Users/users/github/volley/build/outputs/lint-results.html 5 Wrote XML report to /Users/users/github/volley/build/outputs/lint-results.xml 6 :lint FAILED
官方给出解决办法是在build.gradle中添加lint配置,如下
1 Fix the issues identified by lint, or add the following to your build script to proceed with errors: 2 ... 3 android { 4 lintOptions { 5 abortOnError false 6 } 7 } 8 ...
但我看了
/Users/users/github/volley/build/outputs/lint-results.xml
其实只是因为AndroidManifest文件中少了一个权限
1 <uses-permission android:name="android.permission.USE_CREDENTIALS" />
添加以上权限到volley/src/main/AndroidManifest.xml文件中,再次运行 gradle build命令,等待非常长一段时间,终于生成对应的jar文件,位于目录:volley/build/intermediates/bundles/release/classes.jar
说明:目前volley已经不支持ant构建,之前的构建方式
1 android update project -p . 2 3 ant jar
这种方式已经不能使用,需注意(其实第一行命令就会报错缺少AndroidManifest文件,生成不了local.properties)
参考资料:
Volley官方教程:https://developer.android.com/training/volley/index.html
Volley构建及使用博客:http://androidsrc.net/android-volley-library-tutorial/