Import Android volley to Android Studio
AndroidAndroid StudioAndroid LibraryAndroid VolleyAndroid Problem Overview
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?
Android Solutions
Solution 1 - Android
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 - Android
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.
-
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")
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 - Android
Updating Warpzit's answer for Android Studio 1.3.2 (differences in bold)
(update: appears to be the same for Android 2.0)
-
First get latest volley with git.
-
In your current project (android studio) click [file] --> [New]--> [New Module].
-
Now select [Import Gradle Project], 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")
Solution 4 - Android
Way too complicated guys. Just include it in your gradle dependencies:
dependencies {
...
compile 'com.mcxiaoke.volley:library:1.0.17'
}
Solution 5 - Android
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'
}
Solution 6 - Android
Add this line to the dependencies in build.gradle:
compile 'com.mcxiaoke.volley:library:1.0.+'
Solution 7 - Android
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!
Solution 8 - Android
Add this dependency in your gradle.build(Module:app)file
compile 'com.android.volley:volley:1.0.0'
And then sync your gradle file.
Solution 9 - Android
In the "build.gradle" for your app, (the app, not the project), add this:
dependencies {
...
implementation 'com.android.volley:volley:1.1.0'
}
Solution 10 - Android
Add this in your "build.gradle" of you app.
implementation 'com.android.volley:volley:1.1.1'
Solution 11 - Android
Or you can simply do
ant jar
in your cloned volley git project. You should now see volley.jar
in the volley projects bin
folder. Copy this to you Android Studio's app\libs
folder. Then add following under dependencies
section of Module level build.gradle
file -
compile files('libs/volley.jar')
And you should be good import and use the library classes in your project,
Solution 12 - Android
To add volley as submodule and getting regular updates from the GIT repo the following steps can be followed. Main advantage is, Volley can be customised and source code could be pull from GIT repo whenever update is required.
It is also helping for debugging purpose.
Follow the below steps :
Step I :
Add volley as submodule in Android application project GIT Repo. git submodule add -b master https://android.googlesource.com/platform/frameworks/volley Libraries/Volley
Step II :
In settings.gradle, add the following to add volley as a studio project module. include ':Volley' project(':Volley').projectDir=new File('../Libraries/Volley')
Step III :
In app/build.gradle, add following line to compile Volley compile project(':Volley')
That would be all! Volley has been successfully added in the project.
> Every time you want to get the latest code from Google official > Volley's repo, just run the below command
git submodule foreach git pull
For more detailed information : https://gitsubmoduleasandroidtudiomodule.blogspot.in/
GIT Repo sample code : https://github.com/arpitratan/AndroidGitSubmoduleAsModule
Solution 13 - Android
The "compile project(':volley')" line was giving me this error:
> Error:Execution failed for task ':volley:processDebugResources'. > > com.android.ide.common.process.ProcessException: Failed to execute > aapt
It was caused because the compileSdk and buildTools versions of module volley were currently on"22" and "22.0.1" and I my project was working with newer ones ("24" and "24.0.1").
SOLUTION:
Open your build.gradle (Module:volley) file and change the version of "compileSdk" and "buildTools", for example I changed this:
android {
compileSdkVersion 22
buildToolsVersion = '22.0.1'
}
for this:
android {
compileSdkVersion 24
buildToolsVersion = '24.0.1'
}
You should no longer have this error, I hope it helps:)
Solution 14 - Android
it also available on repository mavenCentral()
...
dependencies {
// https://mvnrepository.com/artifact/com.android.volley/volley
api "com.android.volley:volley:1.1.0'
}
Solution 15 - Android
two things
one: compile is out of date rather it is better to use implementation,
and two: volley 1.0.0 is out of date and syncing project will no work
alternatively in build.gradle add implementation 'com.android.volley:volley:1.1.1' or implementation 'com.android.volley:volley:1.1.+' for 1.1.0 and newer versions.
Solution 16 - Android
add this line to your manifest file inside
android:usesCleartextTraffic="true"
Solution 17 - Android
https://github.com/Pawan245/Hanumanjetlibrary">Hanumanjetlibrary.</a>
Hanumanjetlibrary.
Prerequisites
Add this in your root build.gradle file (not your module build.gradle file):
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Dependency
Add this to your module's build.gradle file (make sure the version matches the JitPack badge above):
dependencies {
...
implementation 'com.github.Pawan245:Hanumanjetlibrary:6.1.0'
}
ApicallAny (Volley)
Place this ApicallAny anywhere in your App Make Http Network Call
#MainActivity.java
#withoutParams
String url="http://rt.com/api/my.php";
ApicallAny.ApicallVolleywithoutParams(MainActivity.this,url, new ApicallAny.VolleyCallback() {
@Override
public void onSuccess(String result) {
// do stuff here
}
@Override
public void onError(String result) {
// do stuff here
}
});
#withParams
Map params = new HashMap<>();
params.put("param1","val");
params.put("param2","valx");
String url="http://rt.com/api/my.php";;
ApicallAny.ApicallVolleywithParams(MainActivity.this, url,params, new ApicallAny.VolleyCallback() {
@Override
public void onSuccess(String result) {
// do stuff here
}
@Override
public void onError(String result) {
// do stuff here
}
});
Solution 18 - Android
add volly to your studio gradle app by compile 'com.android.volley:volley:1.0.0'
Solution 19 - Android
step 1:- Download volley.jar file.
step 2:- Go to your project and set the display menu from Android to Project then go to
app -> libs-> paste your volley.jar
file here
step 3:- Right click on the volley.jar file and click on "add as library". and its all done.