将 Android volley 导入 Android Studio
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20059576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Import Android volley to Android Studio
提问by nsvir
I wanna use the google's volley library
我想使用谷歌的排球库
I am using Android Studio and I know how to add .jar libraries.
我正在使用 Android Studio,我知道如何添加 .jar 库。
But I could not create a .jar library with the volley files:
但我无法使用 volley 文件创建 .jar 库:
Here what I did: (using windows seven)
这是我所做的:(使用 Windows 7)
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.
发生了 Java 异常。
what is wrong? how can i add a not .jar library?
怎么了?如何添加非 .jar 库?
回答by shauvik
Volley is now officially available on JCenter:
Volley 现已在 JCenter 上正式发布:
Add this line to your gradle dependencies for your Android project's app module:
将此行添加到您的 Android 项目的应用程序模块的 gradle 依赖项中:
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.android.volley:volley:1.1.1'
回答by Warpzit
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.
因此,Volley 已更新为 Android Studio 构建样式,这使得创建 jar 变得更加困难。但是 eclipse 的推荐方法是将其用作库项目,这也适用于 android studio,但是在 android studio 中工作时,我们称其为模块。所以这里有一个指南,告诉我们如何按照谷歌希望我们的方式去做。指南基于这个不错的教程。
- First get latest volley with git (git clone https://android.googlesource.com/platform/frameworks/volley).
- In your current project (android studio) click
[File]
-->[New]
-->[Import Module]
. - Now select the directory where you downloaded Volley to.
- Now Android studio might guide you to do the rest but continue guide to verify that everything works correct
Open settings.gradle (find in root) and add (or verify this is included):
include ':app', ':volley'
Now go to your build.gradle in your project and add the dependency:
compile project(":volley")
- 首先使用 git 获取最新的 volley(git clone https://android.googlesource.com/platform/frameworks/volley)。
- 在您当前的项目(android studio)中点击
[File]
-->[New]
-->[Import Module]
。 - 现在选择您将 Volley 下载到的目录。
- 现在 Android Studio 可能会指导您完成其余的工作,但继续指导以验证一切正常
打开 settings.gradle(在 root 中找到)并添加(或验证是否包含):
include ':app', ':volley'
现在转到项目中的 build.gradle 并添加依赖项:
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.
这就是它的全部内容,比编译 jar 更简单、更容易,并且比依赖第三方 jar 或 maven 上传更安全。
回答by Al Lelopath
Updating Warpzit's answer for Android Studio 1.3.2 (differences in bold)
(update: appears to be the same for Android 2.0)
更新 Warpzit 对 Android Studio 1.3.2 的回答(粗体差异)
(更新:Android 2.0 似乎相同)
- First get latest volley with git.
- In your current project (android studio) click [file] --> [New]--> [New Module].
- Now select [Import GradleProject], Click Next
- Now select the directory where you downloaded Volley to.
- Now Android studio might guide you to do the rest but continue guide to verify that everything works correct
Open settings.gradle (find in root) and add (or verify this is included):
include ':app', ':volley'
Now go to your build.gradle in your project and add the dependency:
compile project(":volley")
- 首先使用 git 获取最新的截击。
- 在您当前的项目 (android studio) 中,单击 [ file] --> [New]--> [New Module]。
- 现在选择【导入Gradle项目】,点击下一步
- 现在选择您将 Volley 下载到的目录。
- 现在 Android Studio 可能会指导您完成其余的工作,但继续指导以验证一切正常
打开 settings.gradle(在 root 中找到)并添加(或验证是否包含):
包括 ':app', ':volley'
现在转到项目中的 build.gradle 并添加依赖项:
编译项目(":volley")
回答by wild_nothing
Way too complicated guys. Just include it in your gradle dependencies:
太复杂了伙计们。只需将它包含在您的 gradle 依赖项中:
dependencies {
...
compile 'com.mcxiaoke.volley:library:1.0.17'
}
回答by StarWind0
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.
谷歌现在有一个简单的方法来导入它。我们将继续看到很多过时的信息,因为他们已经有 2-3 年没有创建这个解决方案了。
https://bintray.com/android/android-utils/com.android.volley.volley/view
https://bintray.com/android/android-utils/com.android.volley.volley/view
All you need to do is add to your Build.Gradle the following:
您需要做的就是将以下内容添加到您的 Build.Gradle 中:
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.volley:volley:1.0.0'
IE
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'
}
回答by doncic
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!
把compile 'com.android.volley:volley:1.0.0'
你的build.gradle(Module)文件放到依赖项下后,不会立即生效,你得先重启Android Studio!
回答by Victor Odiah
Add this line to the dependencies in build.gradle:
将此行添加到 build.gradle 中的依赖项:
compile 'com.mcxiaoke.volley:library:1.0.+'
回答by Bhumi Unadkat
Add this dependency in your gradle.build(Module:app)file
在您的 gradle.build(Module:app) 文件中添加此依赖项
compile 'com.android.volley:volley:1.0.0'
And then sync your gradle file.
然后同步你的gradle文件。
回答by Tim Cooper
In the "build.gradle" for your app, (the app, not the project), add this:
在您的应用程序(应用程序,而不是项目)的“build.gradle”中,添加以下内容:
dependencies {
...
implementation 'com.android.volley:volley:1.1.0'
}
回答by Sanjay Goswami
Add this in your "build.gradle" of you app.
将此添加到您的应用程序的“build.gradle”中。
implementation 'com.android.volley:volley:1.1.1'
实现 'com.android.volley:volley:1.1.1'